Some warning fixes
[syinit] / 03-c-mode-sy.el
1 ;; 03-c-mode-sy.el --- Set up C mode   -*- Emacs-Lisp -*-
2
3 ;; Copyright (C) 2007 - 2012 Steve Youngs
4
5 ;;     Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;;    Created: <2007-12-02>
8 ;; Time-stamp: <Sunday Jun 10, 2012 10:53:58 steve>
9 ;;   Download: <http://bastard.steveyoungs.com/~steve/SXEmacs/inits/>
10 ;;   HTMLised: <http://bastard.steveyoungs.com/~steve/SXEmacs/htmlinits/03-c-mode-sy.html>
11 ;;   Git Repo: git clone http://git.sxemacs.org/syinit
12 ;;   Keywords: init, compile
13
14 ;; This file is part of SYinit
15
16 ;; Redistribution and use in source and binary forms, with or without
17 ;; modification, are permitted provided that the following conditions
18 ;; are met:
19 ;;
20 ;; 1. Redistributions of source code must retain the above copyright
21 ;;    notice, this list of conditions and the following disclaimer.
22 ;;
23 ;; 2. Redistributions in binary form must reproduce the above copyright
24 ;;    notice, this list of conditions and the following disclaimer in the
25 ;;    documentation and/or other materials provided with the distribution.
26 ;;
27 ;; 3. Neither the name of the author nor the names of any contributors
28 ;;    may be used to endorse or promote products derived from this
29 ;;    software without specific prior written permission.
30 ;;
31 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
32 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 ;; DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
40 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
41 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
43 ;;; Commentary:
44 ;;   This sets up my C programming styles.  Note, too, that with this
45 ;;   setup I am able to have different styles for different projects.
46 ;;   It is a little kludgy, but it works.
47
48 ;;; Credits:
49 ;;
50 ;;   The HTML version of this file was created with Hrvoje Niksic's
51 ;;   htmlize.el which is part of the XEmacs "text-modes" package.
52 ;;
53
54 ;;; Todo:
55 ;;
56 ;;     
57
58 ;;; Code:
59 ;:*=======================
60 ;:* Defaults
61 (setq c-comment-leader "  ")
62 (setq c-default-style
63       '((c-mode . "linux")
64         (c++-mode . "linux")
65         (java-mode . "java")
66         (python-mode . "python")
67         (other . "gnu")))
68
69 ;:*=======================
70 ;:* Special style for Linux source files
71 (defun linux-c-mode ()
72   "C mode with adjusted defaults for use with the Linux kernel.
73
74 Key-bindings:
75 \\{c-mode-map}"
76   (c-mode)
77   (c-set-style "linux")
78   (setq mode-name "Linux/C"))
79
80 (unless (member '("^.*/linux.*/.*\\.[ch]$" . linux-c-mode) auto-mode-alist)
81   (add-to-list 'auto-mode-alist '("^.*/linux.*/.*\\.[ch]$" . linux-c-mode)))
82
83 ;:*=======================
84 ;:* C style for XEmacs core source files
85 (defun xemacs-c-mode ()
86   "C mode with adjusted defaults for use with XEmacs core sources.
87
88 Key-bindings:
89 \\{c-mode-map}"
90   (c-mode)
91   (c-set-style "gnu")
92   (setq mode-name "XE/C"))
93
94 (unless (member '("^.*/xemacs.*/.*\\.[ch]$" . xemacs-c-mode) auto-mode-alist)
95   (add-to-list 'auto-mode-alist '("^.*/xemacs.*/.*\\.[ch]$" . xemacs-c-mode)))
96
97 ;:*=======================
98 ;:* C style for SXEmacs core source files
99 (defvar c-enable-xemacs-performance-kludge-p)
100 (defun sxemacs-c-mode ()
101   "C mode with adjusted defaults for use with SXEmacs core sources.
102
103 Key-bindings:
104 \\{c-mode-map}"
105   (c-mode)
106   (c-set-style "linux")
107   (setq mode-name "SXE/C")
108   (make-variable-buffer-local 'c-enable-xemacs-performance-kludge-p)
109   (setq c-enable-xemacs-performance-kludge-p t))
110
111 (unless (member '("^.*/sxemacs.*/.*\\.[ch]$" . sxemacs-c-mode) auto-mode-alist)
112   (add-to-list 'auto-mode-alist '("^.*/sxemacs.*/.*\\.[ch]$" . sxemacs-c-mode)))
113
114 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
115 (message "C mode initialised.")