Fix up comment convention on the arch-tag lines.
[bpt/emacs.git] / lisp / progmodes / cc-styles.el
1 ;;; cc-styles.el --- support for styles in CC Mode
2
3 ;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
5 ;; Free Software Foundation, Inc.
6
7 ;; Authors: 2004- Alan Mackenzie
8 ;; 1998- Martin Stjernholm
9 ;; 1992-1999 Barry A. Warsaw
10 ;; 1987 Dave Detlefs and Stewart Clamen
11 ;; 1985 Richard M. Stallman
12 ;; Maintainer: bug-cc-mode@gnu.org
13 ;; Created: 22-Apr-1997 (split from cc-mode.el)
14 ;; Version: See cc-mode.el
15 ;; Keywords: c languages oop
16
17 ;; This file is part of GNU Emacs.
18
19 ;; GNU Emacs is free software; you can redistribute it and/or modify
20 ;; it under the terms of the GNU General Public License as published by
21 ;; the Free Software Foundation; either version 3, or (at your option)
22 ;; any later version.
23
24 ;; GNU Emacs is distributed in the hope that it will be useful,
25 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;; GNU General Public License for more details.
28
29 ;; You should have received a copy of the GNU General Public License
30 ;; along with this program; see the file COPYING. If not, write to
31 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
32 ;; Boston, MA 02110-1301, USA.
33
34 ;;; Commentary:
35
36 ;;; Code:
37
38 (eval-when-compile
39 (let ((load-path
40 (if (and (boundp 'byte-compile-dest-file)
41 (stringp byte-compile-dest-file))
42 (cons (file-name-directory byte-compile-dest-file) load-path)
43 load-path)))
44 (load "cc-bytecomp" nil t)))
45
46 (cc-require 'cc-defs)
47 (cc-require 'cc-vars)
48 (cc-require 'cc-align)
49 ;; cc-align is only indirectly required: Styles added with
50 ;; `c-add-style' often contains references to functions defined there.
51
52 ;; Silence the compiler.
53 (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs
54 (cc-bytecomp-obsolete-fun make-local-hook) ; Marked obsolete in Emacs 21.1.
55
56 \f
57 (defvar c-style-alist
58 '(("gnu"
59 (c-basic-offset . 2)
60 (c-comment-only-line-offset . (0 . 0))
61 (c-hanging-braces-alist . ((substatement-open before after)
62 (arglist-cont-nonempty)))
63 (c-offsets-alist . ((statement-block-intro . +)
64 (knr-argdecl-intro . 5)
65 (substatement-open . +)
66 (substatement-label . 0)
67 (label . 0)
68 (statement-case-open . +)
69 (statement-cont . +)
70 (arglist-intro . c-lineup-arglist-intro-after-paren)
71 (arglist-close . c-lineup-arglist)
72 (inline-open . 0)
73 (brace-list-open . +)
74 (topmost-intro-cont
75 . (first c-lineup-topmost-intro-cont
76 c-lineup-gnu-DEFUN-intro-cont))))
77 (c-special-indent-hook . c-gnu-impose-minimum)
78 (c-block-comment-prefix . ""))
79
80 ("k&r"
81 (c-basic-offset . 5)
82 (c-comment-only-line-offset . 0)
83 (c-offsets-alist . ((statement-block-intro . +)
84 (knr-argdecl-intro . 0)
85 (substatement-open . 0)
86 (substatement-label . 0)
87 (label . 0)
88 (statement-cont . +))))
89
90 ("bsd"
91 (c-basic-offset . 8)
92 (c-comment-only-line-offset . 0)
93 (c-offsets-alist . ((statement-block-intro . +)
94 (knr-argdecl-intro . +)
95 (substatement-open . 0)
96 (substatement-label . 0)
97 (label . 0)
98 (statement-cont . +)
99 (inline-open . 0)
100 (inexpr-class . 0))))
101
102 ("stroustrup"
103 (c-basic-offset . 4)
104 (c-comment-only-line-offset . 0)
105 (c-offsets-alist . ((statement-block-intro . +)
106 (substatement-open . 0)
107 (substatement-label . 0)
108 (label . 0)
109 (statement-cont . +))))
110
111 ("whitesmith"
112 (c-basic-offset . 4)
113 (c-comment-only-line-offset . 0)
114 ;; It's obvious that the CC Mode way of choosing anchor positions
115 ;; doesn't fit this style at all. :P
116 (c-offsets-alist . ((defun-open . +)
117 (defun-close . c-lineup-whitesmith-in-block)
118 (defun-block-intro . (add c-lineup-whitesmith-in-block
119 c-indent-multi-line-block))
120 (class-open . +)
121 (class-close . +)
122 (inline-open . +)
123 (inline-close . c-lineup-whitesmith-in-block)
124 (knr-argdecl-intro . +)
125 (block-open . 0) ; Get indentation from `statement' instead.
126 (block-close . c-lineup-whitesmith-in-block)
127 (brace-list-open . +)
128 (brace-list-close . c-lineup-whitesmith-in-block)
129 (brace-list-intro . (add c-lineup-whitesmith-in-block
130 c-indent-multi-line-block))
131 (brace-list-entry . (add c-lineup-after-whitesmith-blocks
132 c-indent-multi-line-block))
133 (brace-entry-open . (add c-lineup-after-whitesmith-blocks
134 c-indent-multi-line-block))
135 (statement . (add c-lineup-after-whitesmith-blocks
136 c-indent-multi-line-block))
137 (statement-block-intro . (add c-lineup-whitesmith-in-block
138 c-indent-multi-line-block))
139 (substatement-open . +)
140 (substatement-label . +)
141 (label . 0)
142 (arglist-intro . (add c-lineup-whitesmith-in-block
143 c-indent-multi-line-block))
144 (arglist-cont . (add c-lineup-after-whitesmith-blocks
145 c-indent-multi-line-block))
146 (arglist-cont-nonempty . (add c-lineup-whitesmith-in-block
147 c-indent-multi-line-block))
148 (arglist-close . c-lineup-whitesmith-in-block)
149 (inclass . c-lineup-whitesmith-in-block)
150 (extern-lang-open . +)
151 (namespace-open . +)
152 (module-open . +)
153 (composition-open . +)
154 (extern-lang-close . +)
155 (namespace-close . +)
156 (module-close . +)
157 (composition-close . +)
158 (inextern-lang . c-lineup-whitesmith-in-block)
159 (innamespace . c-lineup-whitesmith-in-block)
160 (inmodule . c-lineup-whitesmith-in-block)
161 (incomposition . c-lineup-whitesmith-in-block)
162 (inexpr-class . 0))))
163
164 ("ellemtel"
165 (c-basic-offset . 3)
166 (c-comment-only-line-offset . 0)
167 (c-hanging-braces-alist . ((substatement-open before after)))
168 (c-offsets-alist . ((topmost-intro . 0)
169 (substatement . +)
170 (substatement-open . 0)
171 (case-label . +)
172 (access-label . -)
173 (inclass . ++)
174 (inline-open . 0)
175 (arglist-cont-nonempty))))
176
177 ("linux"
178 (c-basic-offset . 8)
179 (c-comment-only-line-offset . 0)
180 (c-hanging-braces-alist . ((brace-list-open)
181 (brace-entry-open)
182 (substatement-open after)
183 (block-close . c-snug-do-while)
184 (arglist-cont-nonempty)))
185 (c-cleanup-list . (brace-else-brace))
186 (c-offsets-alist . ((statement-block-intro . +)
187 (knr-argdecl-intro . 0)
188 (substatement-open . 0)
189 (substatement-label . 0)
190 (label . 0)
191 (statement-cont . +))))
192
193 ("python"
194 (indent-tabs-mode . t)
195 (fill-column . 78)
196 (c-basic-offset . 8)
197 (c-offsets-alist . ((substatement-open . 0)
198 (inextern-lang . 0)
199 (arglist-intro . +)
200 (knr-argdecl-intro . +)))
201 (c-hanging-braces-alist . ((brace-list-open)
202 (brace-list-intro)
203 (brace-list-close)
204 (brace-entry-open)
205 (substatement-open after)
206 (block-close . c-snug-do-while)
207 (arglist-cont-nonempty)))
208 (c-block-comment-prefix . ""))
209
210 ("java"
211 (c-basic-offset . 4)
212 (c-comment-only-line-offset . (0 . 0))
213 ;; the following preserves Javadoc starter lines
214 (c-offsets-alist . ((inline-open . 0)
215 (topmost-intro-cont . +)
216 (statement-block-intro . +)
217 (knr-argdecl-intro . 5)
218 (substatement-open . +)
219 (substatement-label . +)
220 (label . +)
221 (statement-case-open . +)
222 (statement-cont . +)
223 (arglist-intro . c-lineup-arglist-intro-after-paren)
224 (arglist-close . c-lineup-arglist)
225 (access-label . 0)
226 (inher-cont . c-lineup-java-inher)
227 (func-decl-cont . c-lineup-java-throws))))
228
229 ;; awk style exists primarily for auto-newline settings. Otherwise it's
230 ;; pretty much like k&r.
231 ("awk"
232 (c-basic-offset . 4)
233 (c-comment-only-line-offset . 0)
234 (c-hanging-braces-alist . ((defun-open after)
235 (defun-close . c-snug-1line-defun-close)
236 (substatement-open after)
237 (block-close . c-snug-do-while)
238 (arglist-cont-nonempty)))
239 (c-hanging-semi&comma-criteria . nil)
240 (c-cleanup-list . nil) ; You might want one-liner-defun here.
241 (c-offsets-alist . ((statement-block-intro . +)
242 (substatement-open . 0)
243 (statement-cont . +))))
244
245 )
246 "Styles of indentation.
247 Elements of this alist are of the form:
248
249 (STYLE-STRING [BASE-STYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
250
251 where STYLE-STRING is a short descriptive string used to select a
252 style, VARIABLE is any Emacs variable, and VALUE is the intended value
253 for that variable when using the selected style.
254
255 Optional BASE-STYLE if present, is a string and must follow
256 STYLE-STRING. BASE-STYLE names a style that this style inherits from.
257 By default, all styles inherit from the \"user\" style, which is
258 computed at run time. Style loops generate errors.
259
260 Two variables are treated specially. When VARIABLE is
261 `c-offsets-alist', the VALUE is a list containing elements of the
262 form:
263
264 (SYNTACTIC-SYMBOL . OFFSET)
265
266 as described in `c-offsets-alist'. These are passed directly to
267 `c-set-offset' so there is no need to set every syntactic symbol in
268 your style, only those that are different from the default.
269
270 When VARIABLE is `c-special-indent-hook', its VALUE is added to
271 `c-special-indent-hook' using `add-hook'. If VALUE is a list, each
272 element of the list is added with `add-hook'.
273
274 Do not change this variable directly. Use the function `c-add-style'
275 to add new styles or modify existing styles (it is not a good idea to
276 modify existing styles -- you should create a new style that inherits
277 the existing style).")
278
279 \f
280 ;; Functions that manipulate styles
281 (defun c-set-style-1 (conscell dont-override)
282 ;; Set the style for one variable
283 (let ((attr (car conscell))
284 (val (cdr conscell)))
285 (cond
286 ;; first special variable
287 ((eq attr 'c-offsets-alist)
288 (let ((offsets (cond ((eq dont-override t)
289 c-offsets-alist)
290 (dont-override
291 (default-value 'c-offsets-alist)))))
292 (mapcar (lambda (langentry)
293 (let ((langelem (car langentry))
294 (offset (cdr langentry)))
295 (unless (assq langelem offsets)
296 (c-set-offset langelem offset))))
297 val)))
298 ;; second special variable
299 ((eq attr 'c-special-indent-hook)
300 ;; Maybe we should ignore dont-override here and always add new
301 ;; hooks?
302 (unless (cond ((eq dont-override t)
303 c-special-indent-hook)
304 (dont-override
305 (default-value 'c-special-indent-hook)))
306 (if (listp val)
307 (mapcar (lambda (func)
308 (add-hook 'c-special-indent-hook func t t))
309 val)
310 (add-hook 'c-special-indent-hook val t t))))
311 ;; all other variables
312 (t (when (or (not dont-override)
313 (not (memq attr c-style-variables))
314 (eq (if (eq dont-override t)
315 (symbol-value attr)
316 (default-value attr))
317 'set-from-style))
318 (set attr val)
319 ;; Must update a number of other variables if
320 ;; c-comment-prefix-regexp is set.
321 (if (eq attr 'c-comment-prefix-regexp)
322 (c-setup-paragraph-variables)))))))
323
324 (defun c-get-style-variables (style basestyles)
325 ;; Return all variables in a style by resolving inheritances.
326 (if (not style)
327 (copy-alist c-fallback-style)
328 (let ((vars (cdr (or (assoc (downcase style) c-style-alist)
329 (assoc (upcase style) c-style-alist)
330 (assoc style c-style-alist)
331 (progn
332 (c-benign-error "Undefined style: %s" style)
333 nil)))))
334 (let ((base (and (stringp (car-safe vars))
335 (prog1
336 (downcase (car vars))
337 (setq vars (cdr vars))))))
338 (if (memq base basestyles)
339 (c-benign-error "Style loop detected: %s in %s" base basestyles)
340 (nconc (c-get-style-variables base (cons base basestyles))
341 (copy-alist vars)))))))
342
343 (defvar c-set-style-history nil)
344
345 ;;;###autoload
346 (defun c-set-style (stylename &optional dont-override)
347 "Set the current buffer to use the style STYLENAME.
348 STYLENAME, a string, must be an existing CC Mode style - These are contained
349 in the variable `c-style-alist'.
350
351 The variable `c-indentation-style' will get set to STYLENAME.
352
353 \"Setting the style\" is done by setting CC Mode's \"style variables\" to the
354 values indicated by the pertinent entry in `c-style-alist'. Other variables
355 might get set too.
356
357 If DONT-OVERRIDE is neither nil nor t, style variables whose default values
358 have been set (more precisely, whose default values are not the symbol
359 `set-from-style') will not be changed. This avoids overriding global settings
360 done in ~/.emacs. It is useful to call c-set-style from a mode hook in this
361 way.
362
363 If DONT-OVERRIDE is t, style variables that already have values (i.e., whose
364 values are not the symbol `set-from-style') will not be overridden. CC Mode
365 calls c-set-style internally in this way whilst initializing a buffer; if
366 cc-set-style is called like this from anywhere else, it will usually behave as
367 a null operation."
368 (interactive
369 (list (let ((completion-ignore-case t)
370 (prompt (format "Which %s indentation style? "
371 mode-name)))
372 (completing-read prompt c-style-alist nil t nil
373 'c-set-style-history
374 c-indentation-style))))
375 (or c-buffer-is-cc-mode
376 (error "Buffer %s is not a CC Mode buffer (c-set-style)" (buffer-name)))
377 (or (stringp stylename)
378 (error "Argument to c-set-style was not a string"))
379 (c-initialize-builtin-style)
380 (let ((vars (c-get-style-variables stylename nil)))
381 (unless dont-override
382 ;; Since we always add to c-special-indent-hook we must reset it
383 ;; first, or else the hooks from the preceding style will
384 ;; remain. This is not necessary for c-offsets-alist, since
385 ;; c-get-style-variables contains every valid offset type in the
386 ;; fallback entry.
387 (setq c-special-indent-hook
388 (default-value 'c-special-indent-hook)))
389 (mapc (lambda (elem)
390 (c-set-style-1 elem dont-override))
391 ;; Need to go through the variables backwards when we
392 ;; don't override any settings.
393 (if (eq dont-override t) (nreverse vars) vars)))
394 (setq c-indentation-style stylename)
395 (c-keep-region-active))
396
397 ;;;###autoload
398 (defun c-add-style (style description &optional set-p)
399 "Adds a style to `c-style-alist', or updates an existing one.
400 STYLE is a string identifying the style to add or update. DESCRIPTION
401 is an association list describing the style and must be of the form:
402
403 ([BASESTYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
404
405 See the variable `c-style-alist' for the semantics of BASESTYLE,
406 VARIABLE and VALUE. This function also sets the current style to
407 STYLE using `c-set-style' if the optional SET-P flag is non-nil."
408 (interactive
409 (let ((stylename (completing-read "Style to add: " c-style-alist
410 nil nil nil 'c-set-style-history))
411 (descr (eval-minibuffer "Style description: ")))
412 (list stylename descr
413 (y-or-n-p "Set the style too? "))))
414 (setq style (downcase style))
415 (let ((s (assoc style c-style-alist)))
416 (if s
417 (setcdr s (copy-alist description)) ; replace
418 (setq c-style-alist (cons (cons style description) c-style-alist))))
419 (and set-p (c-set-style style)))
420
421 \f
422 (defvar c-read-offset-history nil)
423
424 (defun c-read-offset (langelem)
425 ;; read new offset value for LANGELEM from minibuffer. return a
426 ;; valid value only
427 (let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist)
428 (assq langelem (get 'c-offsets-alist
429 'c-stylevar-fallback)))))
430 (symname (symbol-name langelem))
431 (defstr (format "(default %s): " oldoff))
432 (errmsg (concat "Offset must be int, func, var, vector, list, "
433 "or [+,-,++,--,*,/] "
434 defstr))
435 (prompt (concat symname " offset " defstr))
436 (keymap (make-sparse-keymap))
437 (minibuffer-completion-table obarray)
438 (minibuffer-completion-predicate 'fboundp)
439 offset input)
440 ;; In principle completing-read is used here, but SPC is unbound
441 ;; to make it less annoying to enter lists.
442 (set-keymap-parent keymap minibuffer-local-completion-map)
443 (define-key keymap " " 'self-insert-command)
444 (while (not offset)
445 (setq input (read-from-minibuffer prompt nil keymap t
446 'c-read-offset-history
447 (format "%s" oldoff)))
448 (if (c-valid-offset input)
449 (setq offset input)
450 ;; error, but don't signal one, keep trying
451 ;; to read an input value
452 (ding)
453 (setq prompt errmsg)))
454 offset))
455
456 ;;;###autoload
457 (defun c-set-offset (symbol offset &optional ignored)
458 "Change the value of a syntactic element symbol in `c-offsets-alist'.
459 SYMBOL is the syntactic element symbol to change and OFFSET is the new
460 offset for that syntactic element. The optional argument is not used
461 and exists only for compatibility reasons."
462 (interactive
463 (let* ((langelem
464 (intern (completing-read
465 (concat "Syntactic symbol to change"
466 (if current-prefix-arg " or add" "")
467 ": ")
468 (mapcar
469 #'(lambda (langelem)
470 (cons (format "%s" (car langelem)) nil))
471 (get 'c-offsets-alist 'c-stylevar-fallback))
472 nil (not current-prefix-arg)
473 ;; initial contents tries to be the last element
474 ;; on the syntactic analysis list for the current
475 ;; line
476 (and c-buffer-is-cc-mode
477 (c-save-buffer-state
478 ((syntax (c-guess-basic-syntax))
479 (len (length syntax))
480 (ic (format "%s" (car (nth (1- len) syntax)))))
481 (cons ic 0)))
482 )))
483 (offset (c-read-offset langelem)))
484 (list langelem offset current-prefix-arg)))
485 ;; sanity check offset
486 (if (c-valid-offset offset)
487 (let ((entry (assq symbol c-offsets-alist)))
488 (if entry
489 (setcdr entry offset)
490 (if (assq symbol (get 'c-offsets-alist 'c-stylevar-fallback))
491 (setq c-offsets-alist (cons (cons symbol offset)
492 c-offsets-alist))
493 (c-benign-error "%s is not a valid syntactic symbol" symbol))))
494 (c-benign-error "Invalid indentation setting for symbol %s: %S"
495 symbol offset))
496 (c-keep-region-active))
497
498 \f
499 (defun c-setup-paragraph-variables ()
500 "Fix things up for paragraph recognition and filling inside comments and
501 strings by incorporating the values of `c-comment-prefix-regexp',
502 `sentence-end', `paragraph-start' and `paragraph-separate' in the relevant
503 variables."
504
505 (interactive)
506 (or c-buffer-is-cc-mode
507 (error "Buffer %s is not a CC Mode buffer (c-setup-paragraph-variables)"
508 (buffer-name)))
509 ;; Set up the values for use in comments.
510 (setq c-current-comment-prefix
511 (if (listp c-comment-prefix-regexp)
512 (cdr-safe (or (assoc major-mode c-comment-prefix-regexp)
513 (assoc 'other c-comment-prefix-regexp)))
514 c-comment-prefix-regexp))
515
516 (let ((comment-line-prefix
517 (concat "[ \t]*\\(" c-current-comment-prefix "\\)[ \t]*")))
518
519 (setq paragraph-start (concat comment-line-prefix
520 c-paragraph-start
521 "\\|"
522 page-delimiter)
523 paragraph-separate (concat comment-line-prefix
524 c-paragraph-separate
525 "\\|"
526 page-delimiter)
527 paragraph-ignore-fill-prefix t
528 adaptive-fill-mode t
529 adaptive-fill-regexp
530 (concat comment-line-prefix
531 (if (default-value 'adaptive-fill-regexp)
532 (concat "\\("
533 (default-value 'adaptive-fill-regexp)
534 "\\)")
535 "")))
536
537 (when (boundp 'adaptive-fill-first-line-regexp)
538 ;; XEmacs adaptive fill mode doesn't have this.
539 (make-local-variable 'adaptive-fill-first-line-regexp)
540 (setq adaptive-fill-first-line-regexp
541 (concat "\\`" comment-line-prefix
542 ;; Maybe we should incorporate the old value here,
543 ;; but then we have to do all sorts of kludges to
544 ;; deal with the \` and \' it probably contains.
545 "\\'"))))
546
547 ;; Set up the values for use in strings. These are the default
548 ;; paragraph-start/separate values, enhanced to accept escaped EOLs as
549 ;; whitespace. Used in c-beginning/end-of-sentence-in-string in cc-cmds.
550 (setq c-string-par-start
551 ;;(concat "\\(" (default-value 'paragraph-start) "\\)\\|[ \t]*\\\\$"))
552 "\f\\|[ \t]*\\\\?$")
553 (setq c-string-par-separate
554 ;;(concat "\\(" (default-value 'paragraph-separate) "\\)\\|[ \t]*\\\\$"))
555 "[ \t\f]*\\\\?$")
556 (setq c-sentence-end-with-esc-eol
557 (concat "\\(\\(" (c-default-value-sentence-end) "\\)"
558 ;; N.B.: "$" would be invalid when not enclosed like "\\($\\)".
559 "\\|" "[.?!][]\"')}]* ?\\\\\\($\\)[ \t\n]*"
560 "\\)")))
561
562 \f
563 ;; Helper for setting up Filladapt mode. It's not used by CC Mode itself.
564
565 (cc-bytecomp-defvar filladapt-token-table)
566 (cc-bytecomp-defvar filladapt-token-match-table)
567 (cc-bytecomp-defvar filladapt-token-conversion-table)
568
569 (defun c-setup-filladapt ()
570 "Convenience function to configure Kyle E. Jones' Filladapt mode for
571 CC Mode by making sure the proper entries are present on
572 `filladapt-token-table', `filladapt-token-match-table', and
573 `filladapt-token-conversion-table'. This is intended to be used on
574 `c-mode-common-hook' or similar."
575 ;; This function is intended to be used explicitly by the end user
576 ;; only.
577
578 ;; The default configuration already handles C++ comments, but we
579 ;; need to add handling of C block comments. A new filladapt token
580 ;; `c-comment' is added for that.
581 (let (p)
582 (setq p filladapt-token-table)
583 (while (and p (not (eq (car-safe (cdr-safe (car-safe p))) 'c-comment)))
584 (setq p (cdr-safe p)))
585 (if p
586 (setcar (car p) c-current-comment-prefix)
587 (setq filladapt-token-table
588 (append (list (car filladapt-token-table)
589 (list c-current-comment-prefix 'c-comment))
590 (cdr filladapt-token-table)))))
591 (unless (assq 'c-comment filladapt-token-match-table)
592 (setq filladapt-token-match-table
593 (append '((c-comment c-comment))
594 filladapt-token-match-table)))
595 (unless (assq 'c-comment filladapt-token-conversion-table)
596 (setq filladapt-token-conversion-table
597 (append '((c-comment . exact))
598 filladapt-token-conversion-table))))
599
600 \f
601 (defun c-initialize-builtin-style ()
602 ;; Dynamically append the default value of most variables. This is
603 ;; crucial because future c-set-style calls will always reset the
604 ;; variables first to the `cc-mode' style before instituting the new
605 ;; style. Only do this once!
606 (unless (get 'c-initialize-builtin-style 'is-run)
607 (put 'c-initialize-builtin-style 'is-run t)
608 ;;(c-initialize-cc-mode)
609 (unless (assoc "user" c-style-alist)
610 (let ((vars c-style-variables) var val uservars)
611 (while vars
612 (setq var (car vars)
613 val (symbol-value var)
614 vars (cdr vars))
615 (cond ((eq var 'c-offsets-alist)
616 (or (null val)
617 (setq uservars (cons (cons 'c-offsets-alist val)
618 uservars))))
619 ((not (eq val 'set-from-style))
620 (setq uservars (cons (cons var val)
621 uservars)))))
622 (c-add-style "user" uservars)))
623 (unless (assoc "cc-mode" c-style-alist)
624 (c-add-style "cc-mode" '("user")))
625 (if c-style-variables-are-local-p
626 (c-make-styles-buffer-local))))
627
628 (defun c-make-styles-buffer-local (&optional this-buf-only-p)
629 "Make all CC Mode style variables buffer local.
630 If `this-buf-only-p' is non-nil, the style variables will be made
631 buffer local only in the current buffer. Otherwise they'll be made
632 permanently buffer local in any buffer that changes their values.
633
634 The buffer localness of the style variables are normally controlled
635 with the variable `c-style-variables-are-local-p', so there's seldom
636 any reason to call this function directly."
637
638 ;; style variables
639 (let ((func (if this-buf-only-p
640 'make-local-variable
641 'make-variable-buffer-local))
642 (varsyms (cons 'c-indentation-style (copy-alist c-style-variables))))
643 (delq 'c-special-indent-hook varsyms)
644 (mapc func varsyms)
645 ;; Hooks must be handled specially
646 (if this-buf-only-p
647 (make-local-hook 'c-special-indent-hook)
648 (with-no-warnings (make-variable-buffer-local 'c-special-indent-hook))
649 (setq c-style-variables-are-local-p t))
650 ))
651
652
653 \f
654 (cc-provide 'cc-styles)
655
656 ;; arch-tag: c764f61a-96ba-484a-a68f-101c0e9d5d2c
657 ;;; cc-styles.el ends here