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