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