Mercurial > emacs
annotate lisp/progmodes/cc-styles.el @ 38234:aa4a82ab70c4
*** empty log message ***
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Fri, 29 Jun 2001 17:40:38 +0000 |
parents | 728d49350f43 |
children | 7a94f1c588c4 |
rev | line source |
---|---|
18720 | 1 ;;; cc-styles.el --- support for styles in CC Mode |
2 | |
36920 | 3 ;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc. |
18720 | 4 |
30400
58d2360c8677
(c-style-alist): The basic offset for the BSD
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
5 ;; Authors: 2000- Martin Stjernholm |
58d2360c8677
(c-style-alist): The basic offset for the BSD
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm |
24282 | 7 ;; 1992-1997 Barry A. Warsaw |
18720 | 8 ;; 1987 Dave Detlefs and Stewart Clamen |
9 ;; 1985 Richard M. Stallman | |
24282 | 10 ;; Maintainer: bug-cc-mode@gnu.org |
18720 | 11 ;; Created: 22-Apr-1997 (split from cc-mode.el) |
20147 | 12 ;; Version: See cc-mode.el |
18720 | 13 ;; Keywords: c languages oop |
14 | |
15 ;; This file is part of GNU Emacs. | |
16 | |
17 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
18 ;; it under the terms of the GNU General Public License as published by | |
19 ;; the Free Software Foundation; either version 2, or (at your option) | |
20 ;; any later version. | |
21 | |
22 ;; GNU Emacs is distributed in the hope that it will be useful, | |
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 ;; GNU General Public License for more details. | |
26 | |
27 ;; You should have received a copy of the GNU General Public License | |
36920 | 28 ;; along with this program; see the file COPYING. If not, write to |
29 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
18720 | 30 ;; Boston, MA 02111-1307, USA. |
31 | |
26817 | 32 (eval-when-compile |
33 (let ((load-path | |
36920 | 34 (if (and (boundp 'byte-compile-dest-file) |
35 (stringp byte-compile-dest-file)) | |
36 (cons (file-name-directory byte-compile-dest-file) load-path) | |
26817 | 37 load-path))) |
36920 | 38 (require 'cc-bytecomp))) |
18720 | 39 |
36920 | 40 (cc-require 'cc-defs) |
41 (cc-require 'cc-vars) | |
24282 | 42 |
18720 | 43 |
24282 | 44 ;; Warning: don't eval-defun this constant or you'll break style inheritance. |
18720 | 45 (defconst c-style-alist |
46 '(("gnu" | |
47 (c-basic-offset . 2) | |
48 (c-comment-only-line-offset . (0 . 0)) | |
49 (c-offsets-alist . ((statement-block-intro . +) | |
50 (knr-argdecl-intro . 5) | |
51 (substatement-open . +) | |
52 (label . 0) | |
53 (statement-case-open . +) | |
54 (statement-cont . +) | |
55 (arglist-intro . c-lineup-arglist-intro-after-paren) | |
56 (arglist-close . c-lineup-arglist) | |
24282 | 57 (inline-open . 0) |
30400
58d2360c8677
(c-style-alist): The basic offset for the BSD
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
58 (brace-list-open . +) |
18720 | 59 )) |
60 (c-special-indent-hook . c-gnu-impose-minimum) | |
26817 | 61 (c-block-comment-prefix . "") |
18720 | 62 ) |
63 ("k&r" | |
64 (c-basic-offset . 5) | |
65 (c-comment-only-line-offset . 0) | |
66 (c-offsets-alist . ((statement-block-intro . +) | |
67 (knr-argdecl-intro . 0) | |
68 (substatement-open . 0) | |
69 (label . 0) | |
70 (statement-cont . +) | |
71 )) | |
72 ) | |
73 ("bsd" | |
30400
58d2360c8677
(c-style-alist): The basic offset for the BSD
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
74 (c-basic-offset . 8) |
18720 | 75 (c-comment-only-line-offset . 0) |
76 (c-offsets-alist . ((statement-block-intro . +) | |
77 (knr-argdecl-intro . +) | |
78 (substatement-open . 0) | |
79 (label . 0) | |
80 (statement-cont . +) | |
26817 | 81 (inline-open . 0) |
82 (inexpr-class . 0) | |
18720 | 83 )) |
84 ) | |
85 ("stroustrup" | |
86 (c-basic-offset . 4) | |
87 (c-comment-only-line-offset . 0) | |
88 (c-offsets-alist . ((statement-block-intro . +) | |
89 (substatement-open . 0) | |
90 (label . 0) | |
91 (statement-cont . +) | |
92 )) | |
93 ) | |
94 ("whitesmith" | |
95 (c-basic-offset . 4) | |
96 (c-comment-only-line-offset . 0) | |
26817 | 97 (c-offsets-alist . ((knr-argdecl-intro . +) |
18720 | 98 (label . 0) |
99 (statement-cont . +) | |
26817 | 100 (substatement-open . +) |
101 (block-open . +) | |
102 (statement-block-intro . c-lineup-whitesmith-in-block) | |
103 (block-close . c-lineup-whitesmith-in-block) | |
104 (inline-open . +) | |
105 (defun-open . +) | |
106 (defun-block-intro . c-lineup-whitesmith-in-block) | |
107 (defun-close . c-lineup-whitesmith-in-block) | |
108 (brace-list-open . +) | |
109 (brace-list-intro . c-lineup-whitesmith-in-block) | |
110 (brace-entry-open . c-indent-multi-line-block) | |
111 (brace-list-close . c-lineup-whitesmith-in-block) | |
112 (class-open . +) | |
113 (inclass . c-lineup-whitesmith-in-block) | |
114 (class-close . +) | |
115 (inexpr-class . 0) | |
116 (extern-lang-open . +) | |
117 (inextern-lang . c-lineup-whitesmith-in-block) | |
118 (extern-lang-close . +) | |
119 (namespace-open . +) | |
120 (innamespace . c-lineup-whitesmith-in-block) | |
121 (namespace-close . +) | |
18720 | 122 )) |
123 ) | |
124 ("ellemtel" | |
125 (c-basic-offset . 3) | |
126 (c-comment-only-line-offset . 0) | |
127 (c-hanging-braces-alist . ((substatement-open before after))) | |
128 (c-offsets-alist . ((topmost-intro . 0) | |
129 (topmost-intro-cont . 0) | |
130 (substatement . +) | |
131 (substatement-open . 0) | |
132 (case-label . +) | |
133 (access-label . -) | |
134 (inclass . ++) | |
135 (inline-open . 0) | |
136 )) | |
137 ) | |
138 ("linux" | |
139 (c-basic-offset . 8) | |
140 (c-comment-only-line-offset . 0) | |
141 (c-hanging-braces-alist . ((brace-list-open) | |
24282 | 142 (brace-entry-open) |
18720 | 143 (substatement-open after) |
144 (block-close . c-snug-do-while))) | |
145 (c-cleanup-list . (brace-else-brace)) | |
146 (c-offsets-alist . ((statement-block-intro . +) | |
147 (knr-argdecl-intro . 0) | |
148 (substatement-open . 0) | |
149 (label . 0) | |
150 (statement-cont . +) | |
151 )) | |
152 ) | |
153 ("python" | |
154 (indent-tabs-mode . t) | |
26817 | 155 (fill-column . 78) |
18720 | 156 (c-basic-offset . 8) |
157 (c-offsets-alist . ((substatement-open . 0) | |
19807
86412da1174b
(c-style-alist) <python>:, knr-argdecl-intro == +
Richard M. Stallman <rms@gnu.org>
parents:
19376
diff
changeset
|
158 (inextern-lang . 0) |
86412da1174b
(c-style-alist) <python>:, knr-argdecl-intro == +
Richard M. Stallman <rms@gnu.org>
parents:
19376
diff
changeset
|
159 (arglist-intro . +) |
86412da1174b
(c-style-alist) <python>:, knr-argdecl-intro == +
Richard M. Stallman <rms@gnu.org>
parents:
19376
diff
changeset
|
160 (knr-argdecl-intro . +) |
18720 | 161 )) |
162 (c-hanging-braces-alist . ((brace-list-open) | |
163 (brace-list-intro) | |
164 (brace-list-close) | |
24282 | 165 (brace-entry-open) |
18720 | 166 (substatement-open after) |
167 (block-close . c-snug-do-while) | |
168 )) | |
26817 | 169 (c-block-comment-prefix . "") |
18720 | 170 ) |
171 ("java" | |
20918
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
172 (c-basic-offset . 4) |
18720 | 173 (c-comment-only-line-offset . (0 . 0)) |
19254
81353d4e05b7
(c-styles-alist): In "java" style, set
Richard M. Stallman <rms@gnu.org>
parents:
19212
diff
changeset
|
174 ;; the following preserves Javadoc starter lines |
20918
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
175 (c-offsets-alist . ((inline-open . 0) |
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
176 (topmost-intro-cont . +) |
18720 | 177 (statement-block-intro . +) |
178 (knr-argdecl-intro . 5) | |
179 (substatement-open . +) | |
26817 | 180 (label . +) |
18720 | 181 (statement-case-open . +) |
182 (statement-cont . +) | |
183 (arglist-intro . c-lineup-arglist-intro-after-paren) | |
184 (arglist-close . c-lineup-arglist) | |
185 (access-label . 0) | |
186 (inher-cont . c-lineup-java-inher) | |
187 (func-decl-cont . c-lineup-java-throws) | |
188 )) | |
189 ) | |
190 ) | |
191 "Styles of indentation. | |
192 Elements of this alist are of the form: | |
193 | |
194 (STYLE-STRING [BASE-STYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...]) | |
195 | |
196 where STYLE-STRING is a short descriptive string used to select a | |
197 style, VARIABLE is any Emacs variable, and VALUE is the intended value | |
198 for that variable when using the selected style. | |
199 | |
200 Optional BASE-STYLE if present, is a string and must follow | |
201 STYLE-STRING. BASE-STYLE names a style that this style inherits from. | |
26817 | 202 By default, all styles inherit from the \"user\" style, which is |
18720 | 203 computed at run time. Style loops generate errors. |
204 | |
205 Two variables are treated specially. When VARIABLE is | |
206 `c-offsets-alist', the VALUE is a list containing elements of the | |
207 form: | |
208 | |
209 (SYNTACTIC-SYMBOL . OFFSET) | |
210 | |
211 as described in `c-offsets-alist'. These are passed directly to | |
212 `c-set-offset' so there is no need to set every syntactic symbol in | |
213 your style, only those that are different from the default. | |
214 | |
215 When VARIABLE is `c-special-indent-hook', its VALUE is added to | |
216 `c-special-indent-hook' using `add-hook'. If VALUE is a list, each | |
217 element of the list is added with `add-hook'. | |
218 | |
219 Do not change this variable directly. Use the function `c-add-style' | |
220 to add new styles or modify existing styles (it is not a good idea to | |
221 modify existing styles -- you should create a new style that inherits | |
222 the existing style.") | |
223 | |
26817 | 224 |
18720 | 225 |
226 ;; Functions that manipulate styles | |
26817 | 227 (defun c-set-style-1 (conscell dont-override) |
18720 | 228 ;; Set the style for one variable |
229 (let ((attr (car conscell)) | |
230 (val (cdr conscell))) | |
231 (cond | |
232 ;; first special variable | |
233 ((eq attr 'c-offsets-alist) | |
234 (mapcar | |
235 (function | |
236 (lambda (langentry) | |
237 (let ((langelem (car langentry)) | |
238 (offset (cdr langentry))) | |
26817 | 239 (unless (and dont-override |
240 (assq langelem c-offsets-alist)) | |
241 (c-set-offset langelem offset)) | |
18720 | 242 ))) |
26817 | 243 (if dont-override (reverse val) val))) |
18720 | 244 ;; second special variable |
245 ((eq attr 'c-special-indent-hook) | |
26817 | 246 (let ((add-func (if dont-override |
247 (lambda (func) | |
248 (unless (memq func c-special-indent-hook) | |
249 (add-hook 'c-special-indent-hook func t))) | |
250 (lambda (func) | |
251 (add-hook 'c-special-indent-hook func))))) | |
252 (if (listp val) | |
253 (mapcar add-func (if dont-override (reverse val) val)) | |
254 (funcall add-func val)))) | |
18720 | 255 ;; all other variables |
26817 | 256 (t (if (or (not dont-override) |
257 (not (memq attr c-style-variables)) | |
258 (eq (symbol-value attr) 'set-from-style)) | |
259 (set attr val)))) | |
18720 | 260 )) |
261 | |
26817 | 262 (defun c-get-style-variables (style basestyles) |
263 ;; Return all variables in a style by resolving inheritances. | |
18720 | 264 (let ((vars (cdr (or (assoc (downcase style) c-style-alist) |
265 (assoc (upcase style) c-style-alist) | |
266 (assoc style c-style-alist) | |
267 (error "Undefined style: %s" style))))) | |
26817 | 268 (if (string-equal style "user") |
269 (copy-alist vars) | |
270 (let ((base (if (stringp (car vars)) | |
271 (prog1 | |
272 (downcase (car vars)) | |
273 (setq vars (cdr vars))) | |
274 "user"))) | |
275 (if (memq base basestyles) | |
276 (error "Style loop detected: %s in %s" base basestyles)) | |
277 (nconc (c-get-style-variables base (cons base basestyles)) | |
278 (copy-alist vars)))))) | |
279 | |
18720 | 280 (defvar c-set-style-history nil) |
281 | |
282 ;;;###autoload | |
26817 | 283 (defun c-set-style (stylename &optional dont-override) |
18720 | 284 "Set CC Mode variables to use one of several different indentation styles. |
285 STYLENAME is a string representing the desired style from the list of | |
286 styles described in the variable `c-style-alist'. See that variable | |
287 for details of setting up styles. | |
288 | |
289 The variable `c-indentation-style' always contains the buffer's current | |
26817 | 290 style name. |
291 | |
292 If the optional argument DONT-OVERRIDE is non-nil, no style variables | |
293 that already have values will be overridden. I.e. in the case of | |
294 `c-offsets-alist', syntactic symbols will only be added, and in the | |
295 case of all other style variables, only those set to `set-from-style' | |
296 will be reassigned. | |
297 | |
298 Obviously, specifying DONT-OVERRIDE is useful mainly when the initial | |
299 style is chosen for a CC Mode buffer by a major mode. Since this is | |
300 done internally by CC Mode, there's hardly ever a reason to use it." | |
18720 | 301 (interactive (list (let ((completion-ignore-case t) |
302 (prompt (format "Which %s indentation style? " | |
303 mode-name))) | |
304 (completing-read prompt c-style-alist nil t | |
38167
728d49350f43
(c-set-style): Don't specify initial contents for completing-read.
Richard M. Stallman <rms@gnu.org>
parents:
36920
diff
changeset
|
305 nil |
728d49350f43
(c-set-style): Don't specify initial contents for completing-read.
Richard M. Stallman <rms@gnu.org>
parents:
36920
diff
changeset
|
306 'c-set-style-history |
728d49350f43
(c-set-style): Don't specify initial contents for completing-read.
Richard M. Stallman <rms@gnu.org>
parents:
36920
diff
changeset
|
307 c-indentation-style)))) |
19254
81353d4e05b7
(c-styles-alist): In "java" style, set
Richard M. Stallman <rms@gnu.org>
parents:
19212
diff
changeset
|
308 (c-initialize-builtin-style) |
26817 | 309 (let ((vars (c-get-style-variables stylename nil))) |
310 (mapcar (lambda (elem) | |
311 (c-set-style-1 elem dont-override)) | |
312 ;; Need to go through the variables backwards when we | |
313 ;; don't override. | |
314 (if dont-override (nreverse vars) vars))) | |
18720 | 315 (setq c-indentation-style stylename) |
316 (c-keep-region-active)) | |
317 | |
318 ;;;###autoload | |
319 (defun c-add-style (style descrip &optional set-p) | |
320 "Adds a style to `c-style-alist', or updates an existing one. | |
321 STYLE is a string identifying the style to add or update. DESCRIP is | |
322 an association list describing the style and must be of the form: | |
323 | |
324 ([BASESTYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...]) | |
325 | |
326 See the variable `c-style-alist' for the semantics of BASESTYLE, | |
327 VARIABLE and VALUE. This function also sets the current style to | |
328 STYLE using `c-set-style' if the optional SET-P flag is non-nil." | |
329 (interactive | |
330 (let ((stylename (completing-read "Style to add: " c-style-alist | |
331 nil nil nil 'c-set-style-history)) | |
332 (description (eval-minibuffer "Style description: "))) | |
333 (list stylename description | |
334 (y-or-n-p "Set the style too? ")))) | |
335 (setq style (downcase style)) | |
336 (let ((s (assoc style c-style-alist))) | |
337 (if s | |
338 (setcdr s (copy-alist descrip)) ; replace | |
339 (setq c-style-alist (cons (cons style descrip) c-style-alist)))) | |
340 (and set-p (c-set-style style))) | |
341 | |
342 | |
343 | |
344 (defvar c-read-offset-history nil) | |
345 | |
346 (defun c-read-offset (langelem) | |
347 ;; read new offset value for LANGELEM from minibuffer. return a | |
348 ;; legal value only | |
26817 | 349 (let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist) |
350 (assq langelem (get 'c-offsets-alist | |
351 'c-stylevar-fallback))))) | |
24282 | 352 (symname (symbol-name langelem)) |
353 (defstr (format "(default %s): " oldoff)) | |
36920 | 354 (errmsg (concat "Offset must be int, func, var, vector, list, " |
24282 | 355 "or [+,-,++,--,*,/] " |
356 defstr)) | |
357 (prompt (concat symname " offset " defstr)) | |
18720 | 358 offset input interned raw) |
359 (while (not offset) | |
360 (setq input (completing-read prompt obarray 'fboundp nil nil | |
361 'c-read-offset-history) | |
362 offset (cond ((string-equal "" input) oldoff) ; default | |
363 ((string-equal "+" input) '+) | |
364 ((string-equal "-" input) '-) | |
365 ((string-equal "++" input) '++) | |
366 ((string-equal "--" input) '--) | |
367 ((string-equal "*" input) '*) | |
368 ((string-equal "/" input) '/) | |
369 ((string-match "^-?[0-9]+$" input) | |
370 (string-to-int input)) | |
371 ;; a symbol with a function binding | |
372 ((fboundp (setq interned (intern input))) | |
373 interned) | |
374 ;; a symbol with variable binding | |
375 ((boundp interned) interned) | |
36920 | 376 ;; a lambda function or a vector |
377 ((progn | |
378 (c-safe (setq raw (read input))) | |
379 (or (functionp raw) | |
380 (vectorp raw))) | |
381 raw) | |
18720 | 382 ;; error, but don't signal one, keep trying |
383 ;; to read an input value | |
384 (t (ding) | |
385 (setq prompt errmsg) | |
386 nil)))) | |
387 offset)) | |
388 | |
19212
024594beef65
(c-set-offset): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
18845
diff
changeset
|
389 ;;;###autoload |
26817 | 390 (defun c-set-offset (symbol offset &optional ignored) |
18720 | 391 "Change the value of a syntactic element symbol in `c-offsets-alist'. |
392 SYMBOL is the syntactic element symbol to change and OFFSET is the new | |
26817 | 393 offset for that syntactic element. The optional argument is not used |
394 and exists only for compatibility reasons." | |
18720 | 395 (interactive |
396 (let* ((langelem | |
397 (intern (completing-read | |
398 (concat "Syntactic symbol to change" | |
399 (if current-prefix-arg " or add" "") | |
400 ": ") | |
401 (mapcar | |
402 #'(lambda (langelem) | |
403 (cons (format "%s" (car langelem)) nil)) | |
26817 | 404 (get 'c-offsets-alist 'c-stylevar-fallback)) |
18720 | 405 nil (not current-prefix-arg) |
406 ;; initial contents tries to be the last element | |
407 ;; on the syntactic analysis list for the current | |
408 ;; line | |
409 (let* ((syntax (c-guess-basic-syntax)) | |
410 (len (length syntax)) | |
411 (ic (format "%s" (car (nth (1- len) syntax))))) | |
412 (cons ic 0)) | |
413 ))) | |
414 (offset (c-read-offset langelem))) | |
415 (list langelem offset current-prefix-arg))) | |
416 ;; sanity check offset | |
26817 | 417 (unless (c-valid-offset offset) |
36920 | 418 (error (concat "Offset must be int, func, var, vector, list, " |
419 "or in [+,-,++,--,*,/]: %s") | |
26817 | 420 offset)) |
18720 | 421 (let ((entry (assq symbol c-offsets-alist))) |
422 (if entry | |
423 (setcdr entry offset) | |
26817 | 424 (if (assq symbol (get 'c-offsets-alist 'c-stylevar-fallback)) |
18720 | 425 (setq c-offsets-alist (cons (cons symbol offset) c-offsets-alist)) |
26817 | 426 (error "%s is not a valid syntactic symbol" symbol)))) |
18720 | 427 (c-keep-region-active)) |
428 | |
26817 | 429 |
24282 | 430 |
18720 | 431 (defun c-initialize-builtin-style () |
432 ;; Dynamically append the default value of most variables. This is | |
433 ;; crucial because future c-set-style calls will always reset the | |
434 ;; variables first to the `cc-mode' style before instituting the new | |
435 ;; style. Only do this once! | |
24282 | 436 (unless (get 'c-initialize-builtin-style 'is-run) |
437 (put 'c-initialize-builtin-style 'is-run t) | |
36920 | 438 ;;(c-initialize-cc-mode) |
24282 | 439 (or (assoc "cc-mode" c-style-alist) |
440 (assoc "user" c-style-alist) | |
441 (progn | |
26817 | 442 (c-add-style |
443 "user" | |
444 (mapcar | |
445 (lambda (var) | |
446 (let ((val (symbol-value var))) | |
447 (cons var | |
448 (cond ((eq var 'c-offsets-alist) | |
449 (mapcar | |
450 (lambda (langentry) | |
451 (setq langentry (or (assq (car langentry) val) | |
452 langentry)) | |
453 (cons (car langentry) | |
454 (cdr langentry))) | |
455 (get var 'c-stylevar-fallback))) | |
456 ((eq var 'c-special-indent-hook) | |
457 val) | |
458 (t | |
459 (if (eq val 'set-from-style) | |
460 (get var 'c-stylevar-fallback) | |
461 val)))))) | |
462 c-style-variables)) | |
463 (c-add-style "cc-mode" '("user")))) | |
24282 | 464 (if c-style-variables-are-local-p |
465 (c-make-styles-buffer-local)))) | |
19254
81353d4e05b7
(c-styles-alist): In "java" style, set
Richard M. Stallman <rms@gnu.org>
parents:
19212
diff
changeset
|
466 |
20918
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
467 (defun c-make-styles-buffer-local (&optional this-buf-only-p) |
18720 | 468 "Make all CC Mode style variables buffer local. |
26817 | 469 If you edit primarily one style of C (or C++, Objective-C, Java, etc) |
470 code, you probably want style variables to be global. This is the | |
471 default. | |
18720 | 472 |
26817 | 473 If you edit many different styles of C (or C++, Objective-C, Java, |
474 etc) at the same time, you probably want the CC Mode style variables | |
475 to be buffer local. If you do, it's advicable to set any CC Mode | |
476 style variables in a hook function (e.g. off of `c-mode-common-hook'), | |
477 instead of at the top level of your ~/.emacs file. | |
18720 | 478 |
479 This function makes all the CC Mode style variables buffer local. | |
480 Call it after CC Mode is loaded into your Emacs environment. | |
481 Conversely, set the variable `c-style-variables-are-local-p' to t in | |
482 your .emacs file, before CC Mode is loaded, and this function will be | |
20918
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
483 automatically called when CC Mode is loaded. |
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
484 |
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
485 Optional argument, when non-nil, means use `make-local-variable' |
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
486 instead of `make-variable-buffer-local'." |
18720 | 487 ;; style variables |
20918
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
488 (let ((func (if this-buf-only-p |
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
489 'make-local-variable |
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
490 'make-variable-buffer-local)) |
26817 | 491 (varsyms (cons 'c-indentation-style (copy-alist c-style-variables)))) |
492 (delq 'c-special-indent-hook varsyms) | |
20918
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
493 (mapcar func varsyms) |
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
494 ;; Hooks must be handled specially |
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
495 (if this-buf-only-p |
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
496 (make-local-hook 'c-special-indent-hook) |
26817 | 497 (make-variable-buffer-local 'c-special-indent-hook) |
498 (setq c-style-variables-are-local-p t)) | |
20918
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
499 )) |
8e64bd5b1b5f
(c-make-styles-buffer-local): Take an optional argument which switches
Richard M. Stallman <rms@gnu.org>
parents:
20147
diff
changeset
|
500 |
18720 | 501 |
502 | |
36920 | 503 (cc-provide 'cc-styles) |
18720 | 504 ;;; cc-styles.el ends here |