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