annotate lisp/modes/c-style.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children b82b59fe008d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; c-style.el --- sets c-style control variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1992-1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; c-style|Daniel LaLiberte|liberte@cs.uiuc.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; |sets c-style control variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; |Thu Feb 27 13:42:57 CST 1992|Version: 2.1|~/as-is/c-src-doc.el.Z
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; There are several ways to call set-c-style described below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; None of these methods reindent your program - they only affect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; new indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; - Just call set-c-style in your c-mode-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; Without style argument, default-c-style will be used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; With style argument, this will set the style for every
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; c-mode buffer the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; - Call set-c-style from the Local Variables list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; e.g. "eval:(set-c-style 'C++)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; - Call set-c-style interactively. It prompts for the style name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; with completion using default-c-style.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; For convenience, put one of the following in your .emacs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; (autoload 'set-c-style "c-style" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; or (load "c-style")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; =====================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defvar default-c-style 'GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "*The default value of c-style. Set this in your .emacs.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; The following predefined styles are all I know about.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; If you learn of another style that has a "big" following, please
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; send me the parameters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defvar c-style-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 '((GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (c-indent-level 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (c-continued-statement-offset 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (c-brace-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (c-argdecl-indent 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (c-label-offset -2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (c-indent-level 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (c-continued-statement-offset 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (c-brace-offset -8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (c-argdecl-indent 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (c-label-offset -8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (K&R
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (c-indent-level 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (c-continued-statement-offset 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (c-brace-offset -5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (c-argdecl-indent 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (c-label-offset -5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (BS ; was C++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (c-indent-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (c-continued-statement-offset 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (c-brace-offset -4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (c-argdecl-indent 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (c-label-offset -4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; From Lynn Slater
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (LRS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (c-indent-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (c-continued-statement-offset 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (c-brace-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (c-argdecl-indent 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (c-label-offset -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (c-auto-newline nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (Plauger
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (c-indent-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (c-continued-statement-offset 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (c-continued-brace-offset -8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (c-brace-offset 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (c-brace-imaginary-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (c-argdecl-indent 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (c-label-offset -8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (c-auto-newline t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (c-tab-always-indent t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;; From Jozsef A Toth <jtoth+@pitt.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; Is this really the Whitesmith style?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (Alman
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (c-argdecl-indent 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (c-brace-imaginary-offset 2) ;;; ????
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (c-brace-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (c-continued-statement-offset 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (c-indent-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (c-label-offset -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (c-auto-newline t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (comment-column 40)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (tab-width 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (fill-column '79))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (Gould
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (c-indent-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (c-continued-statement-offset 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (c-brace-offset -4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (c-argdecl-indent 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (c-label-offset -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (c-brace-imaginary-offset 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; From Joan Eslinger <wombat@kilimanjaro.key.amdahl.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (WRS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (c-indent-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (c-continued-statement-offset 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (c-brace-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (c-argdecl-indent 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (c-label-offset -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (c-brace-imaginary-offset 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (c-continued-brace-offset -4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (defvar c-style nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 "The buffer local c-mode indentation style.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; Add style name to mode line. Assumes minor-mode-alist is not buffer local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; Thanks to Joan Eslinger.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (defvar c-style-name nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 "The style name for a c-mode indentation style.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 This is to be set by set-c-style, and used by the mode line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (or (assq 'c-style-name minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (purecopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (append minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; use undocumented feature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 '((c-style-name c-style-name))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defun set-c-style (&optional style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "Set up the c-mode style variables from STYLE if it is given, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 default-c-style otherwise. It makes the c indentation style variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 buffer local."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (let ((c-styles (mapcar 'car c-style-alist))) ; for completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (setq style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (let ((style-string ; Get style name with completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (format "Set c-mode indentation style to (default %s): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 default-c-style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (vconcat c-styles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (function (lambda (arg) (memq arg c-styles)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (if (string-equal "" style-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 default-c-style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (intern style-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; If style is nil, use default-c-style.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (setq style (or style default-c-style))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (make-local-variable 'c-style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (if (memq style c-styles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq c-style style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (error "Undefined c style: %s" style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (message "c-style: %s" c-style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; Set the c-style-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (make-local-variable 'c-style-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (setq c-style-name (format " %s" c-style))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; Finally, set the indentation style variables making each one local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (mapcar (function (lambda (c-style-pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (make-local-variable (car c-style-pair))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (set (car c-style-pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (car (cdr c-style-pair)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (cdr (assq c-style c-style-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 c-style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ))