Loads and loads and loads of updates.
[syinit] / 03-c-mode-sy.el
1 ;; 03-c-mode-sy.el --- Set up C mode   -*- Emacs-Lisp -*-
2
3 ;; Copyright (C) 2007 - 2020 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: <Wednesday Feb 12, 2020 12:00:39 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)
81                 auto-mode-alist)
82   (add-to-list 'auto-mode-alist
83                '("^.*/linux.*/.*\\.[ch]$" . linux-c-mode)))
84
85 ;:*=======================
86 ;:* C style for XEmacs core source files
87 (defun xemacs-c-mode ()
88   "C mode with adjusted defaults for use with XEmacs core sources.
89
90 Key-bindings:
91 \\{c-mode-map}"
92   (c-mode)
93   (c-set-style "gnu")
94   (setq mode-name "XE/C"))
95
96 (unless (member '("^.*/xemacs.*/.*\\.[ch]$" . xemacs-c-mode)
97                 auto-mode-alist)
98   (add-to-list 'auto-mode-alist
99                '("^.*/xemacs.*/.*\\.[ch]$" . xemacs-c-mode)))
100
101 ;:*=======================
102 ;:* C style for SXEmacs core source files
103 (defvar c-enable-xemacs-performance-kludge-p)
104 (defun sxemacs-c-mode ()
105   "C mode with adjusted defaults for use with SXEmacs core sources.
106
107 Key-bindings:
108 \\{c-mode-map}"
109   (c-mode)
110   (c-set-style "linux")
111   (setq mode-name "SXE/C")
112   (make-variable-buffer-local 'c-enable-xemacs-performance-kludge-p)
113   (setq c-enable-xemacs-performance-kludge-p t))
114
115 (unless (member '("^.*/sxemacs.*/.*\\.[ch]$" . sxemacs-c-mode)
116                 auto-mode-alist)
117   (add-to-list 'auto-mode-alist
118                '("^.*/sxemacs.*/.*\\.[ch]$" . sxemacs-c-mode)))
119
120 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
121 (message "C mode initialised.")