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