]> code.delx.au - gnu-emacs/blob - lisp/progmodes/cc-vars.el
Add 2009 to copyright years.
[gnu-emacs] / lisp / progmodes / cc-vars.el
1 ;;; cc-vars.el --- user customization variables for CC Mode
2
3 ;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 ;; Free Software Foundation, Inc.
6
7 ;; Authors: 2002- Alan Mackenzie
8 ;; 1998- Martin Stjernholm
9 ;; 1992-1999 Barry A. Warsaw
10 ;; 1987 Dave Detlefs and Stewart Clamen
11 ;; 1985 Richard M. Stallman
12 ;; Maintainer: bug-cc-mode@gnu.org
13 ;; Created: 22-Apr-1997 (split from cc-mode.el)
14 ;; Version: See cc-mode.el
15 ;; Keywords: c languages oop
16
17 ;; This file is part of GNU Emacs.
18
19 ;; GNU Emacs is free software: you can redistribute it and/or modify
20 ;; it under the terms of the GNU General Public License as published by
21 ;; the Free Software Foundation, either version 3 of the License, or
22 ;; (at your option) any later version.
23
24 ;; GNU Emacs is distributed in the hope that it will be useful,
25 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;; GNU General Public License for more details.
28
29 ;; You should have received a copy of the GNU General Public License
30 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31
32 ;;; Commentary:
33
34 ;;; Code:
35
36 (eval-when-compile
37 (let ((load-path
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)
41 load-path)))
42 (load "cc-bytecomp" nil t)))
43
44 (cc-require 'cc-defs)
45
46 ;; Silence the compiler.
47 (cc-bytecomp-defun get-char-table) ; XEmacs
48
49 (cc-eval-when-compile
50 (require 'custom)
51 (require 'widget))
52
53 (cc-eval-when-compile
54 ;; Need the function form of `backquote', which isn't standardized
55 ;; between Emacsen. It's called `bq-process' in XEmacs, and
56 ;; `backquote-process' in Emacs. `backquote-process' returns a
57 ;; slightly more convoluted form, so let `bq-process' be the norm.
58 (if (fboundp 'backquote-process)
59 (cc-bytecomp-defmacro bq-process (form)
60 `(cdr (backquote-process ,form)))))
61
62 \f
63 ;;; Helpers
64
65 ;; This widget exists in newer versions of the Custom library
66 (or (get 'other 'widget-type)
67 (define-widget 'other 'sexp
68 "Matches everything, but doesn't let the user edit the value.
69 Useful as last item in a `choice' widget."
70 :tag "Other"
71 :format "%t%n"
72 :value 'other))
73
74 ;; The next defun will supersede c-const-symbol.
75 (eval-and-compile
76 (defun c-constant-symbol (sym len)
77 "Create an uneditable symbol for customization buffers.
78 SYM is the name of the symbol, LEN the length of the field (in
79 characters) the symbol will be displayed in. LEN must be big
80 enough.
81
82 This returns a (const ....) structure, suitable for embedding
83 within a customization type."
84 (or (symbolp sym) (error "c-constant-symbol: %s is not a symbol" sym))
85 (let* ((name (symbol-name sym))
86 (l (length name))
87 (disp (concat name ":" (make-string (- len l 1) ?\ ))))
88 `(const
89 :size ,len
90 :format ,disp
91 :value ,sym))))
92
93 (define-widget 'c-const-symbol 'item
94 "An uneditable lisp symbol. This is obsolete -
95 use c-constant-symbol instead."
96 :value nil
97 :tag "Symbol"
98 :format "%t: %v\n%d"
99 :match (lambda (widget value) (symbolp value))
100 :value-to-internal
101 (lambda (widget value)
102 (let ((s (if (symbolp value)
103 (symbol-name value)
104 value))
105 (l (widget-get widget :size)))
106 (if l
107 (setq s (concat s (make-string (- l (length s)) ?\ ))))
108 s))
109 :value-to-external
110 (lambda (widget value)
111 (if (stringp value)
112 (intern (progn
113 (string-match "\\`[^ ]*" value)
114 (match-string 0 value)))
115 value)))
116
117 (define-widget 'c-integer-or-nil 'sexp
118 "An integer or the value nil."
119 :value nil
120 :tag "Optional integer"
121 :match (lambda (widget value) (or (integerp value) (null value))))
122
123 (define-widget 'c-symbol-list 'sexp
124 "A single symbol or a list of symbols."
125 :tag "Symbols separated by spaces"
126 :validate 'widget-field-validate
127 :match
128 (lambda (widget value)
129 (or (symbolp value)
130 (catch 'ok
131 (while (listp value)
132 (unless (symbolp (car value))
133 (throw 'ok nil))
134 (setq value (cdr value)))
135 (null value))))
136 :value-to-internal
137 (lambda (widget value)
138 (cond ((null value)
139 "")
140 ((symbolp value)
141 (symbol-name value))
142 ((consp value)
143 (mapconcat (lambda (symbol)
144 (symbol-name symbol))
145 value
146 " "))
147 (t
148 value)))
149 :value-to-external
150 (lambda (widget value)
151 (if (stringp value)
152 (let (list end)
153 (while (string-match "\\S +" value end)
154 (setq list (cons (intern (match-string 0 value)) list)
155 end (match-end 0)))
156 (if (and list (not (cdr list)))
157 (car list)
158 (nreverse list)))
159 value)))
160
161 (defvar c-style-variables
162 '(c-basic-offset c-comment-only-line-offset c-indent-comment-alist
163 c-indent-comments-syntactically-p c-block-comment-prefix
164 c-comment-prefix-regexp c-doc-comment-style c-cleanup-list
165 c-hanging-braces-alist c-hanging-colons-alist
166 c-hanging-semi&comma-criteria c-backslash-column c-backslash-max-column
167 c-special-indent-hook c-label-minimum-indentation c-offsets-alist)
168 "List of the style variables.")
169
170 (defvar c-fallback-style nil)
171
172 (defsubst c-set-stylevar-fallback (name val)
173 (put name 'c-stylevar-fallback val)
174 (setq c-fallback-style (cons (cons name val) c-fallback-style)))
175
176 (defmacro defcustom-c-stylevar (name val doc &rest args)
177 "Define a style variable NAME with VAL and DOC.
178 More precisely, convert the given `:type FOO', mined out of ARGS,
179 to an aggregate `:type (radio STYLE (PREAMBLE FOO))', append some
180 some boilerplate documentation to DOC, arrange for the fallback
181 value of NAME to be VAL, and call `custom-declare-variable' to
182 do the rest of the work.
183
184 STYLE stands for the choice where the value is taken from some
185 style setting. PREAMBLE is optionally prepended to FOO; that is,
186 if FOO contains :tag or :value, the respective two-element list
187 component is ignored."
188 (declare (debug (symbolp form stringp &rest)))
189 (let* ((expanded-doc (concat doc "
190
191 This is a style variable. Apart from the valid values described
192 above, it can be set to the symbol `set-from-style'. In that case,
193 it takes its value from the style system (see `c-default-style' and
194 `c-style-alist') when a CC Mode buffer is initialized. Otherwise,
195 the value set here overrides the style system (there is a variable
196 `c-old-style-variable-behavior' that changes this, though)."))
197 (typ (eval (plist-get args :type)))
198 (type (if (consp typ) typ (list typ)))
199 (head (car type))
200 (tail (cdr type))
201 (newt (append (unless (plist-get tail :tag)
202 '(:tag "Override style settings"))
203 (unless (plist-get tail :value)
204 `(:value ,(eval val)))
205 tail))
206 (aggregate `'(radio
207 (const :tag "Use style settings" set-from-style)
208 ,(cons head newt))))
209 `(progn
210 (c-set-stylevar-fallback ',name ,val)
211 (custom-declare-variable
212 ',name ''set-from-style
213 ,expanded-doc
214 ,@(plist-put args :type aggregate)))))
215
216 (defun c-valid-offset (offset)
217 "Return non-nil if OFFSET is a valid offset for a syntactic symbol.
218 See `c-offsets-alist'."
219 (or (eq offset '+)
220 (eq offset '-)
221 (eq offset '++)
222 (eq offset '--)
223 (eq offset '*)
224 (eq offset '/)
225 (integerp offset)
226 (functionp offset)
227 (and (symbolp offset) (boundp offset))
228 (and (vectorp offset)
229 (= (length offset) 1)
230 (integerp (elt offset 0)))
231 (and (consp offset)
232 (not (eq (car offset) 'quote)) ; Detect misquoted lists.
233 (progn
234 (when (memq (car offset) '(first min max add))
235 (setq offset (cdr offset)))
236 (while (and (consp offset)
237 (c-valid-offset (car offset)))
238 (setq offset (cdr offset)))
239 (null offset)))))
240
241
242 \f
243 ;;; User variables
244
245 (defcustom c-strict-syntax-p nil
246 "*If non-nil, all syntactic symbols must be found in `c-offsets-alist'.
247 If the syntactic symbol for a particular line does not match a symbol
248 in the offsets alist, or if no non-nil offset value can be determined
249 for a symbol, an error is generated, otherwise no error is reported
250 and the syntactic symbol is ignored.
251
252 This variable is considered obsolete; it doesn't work well with lineup
253 functions that return nil to support the feature of using lists on
254 syntactic symbols in `c-offsets-alist'. Please keep it set to nil."
255 :type 'boolean
256 :group 'c)
257
258 (defcustom c-echo-syntactic-information-p nil
259 "*If non-nil, syntactic info is echoed when the line is indented."
260 :type 'boolean
261 :group 'c)
262
263 (defcustom c-report-syntactic-errors nil
264 "*If non-nil, certain syntactic errors are reported with a ding
265 and a message, for example when an \"else\" is indented for which
266 there's no corresponding \"if\".
267
268 Note however that CC Mode doesn't make any special effort to check for
269 syntactic errors; that's the job of the compiler. The reason it can
270 report cases like the one above is that it can't find the correct
271 anchoring position to indent the line in that case."
272 :type 'boolean
273 :group 'c)
274
275 (defcustom-c-stylevar c-basic-offset 4
276 "*Amount of basic offset used by + and - symbols in `c-offsets-alist'.
277 Also used as the indentation step when `c-syntactic-indentation' is
278 nil."
279 :type 'integer
280 :group 'c)
281 ;;;###autoload(put 'c-basic-offset 'safe-local-variable 'integerp)
282
283 (defcustom c-tab-always-indent t
284 "*Controls the operation of the TAB key.
285 If t, hitting TAB always just indents the current line. If nil, hitting
286 TAB indents the current line if point is at the left margin or in the
287 line's indentation, otherwise it calls `c-insert-tab-function' to
288 insert a `real' tab character. If some other value (neither nil nor t),
289 then inserts a tab only within literals (comments and strings), but
290 always reindents the line.
291
292 Note: the variable `c-comment-only-line-offset' also controls the
293 indentation of lines containing only comments."
294 :type '(radio
295 (const :tag "TAB key always indents, never inserts TAB" t)
296 (const :tag "TAB key indents in left margin, otherwise inserts TAB" nil)
297 (other :tag "TAB key inserts TAB in literals, otherwise indents" other))
298 :group 'c)
299
300 (defcustom c-insert-tab-function 'insert-tab
301 "*Function used when inserting a tab for \\[c-indent-command].
302 Only used when `c-tab-always-indent' indicates a `real' tab character
303 should be inserted. Value must be a function taking no arguments.
304 The default, `insert-tab', inserts either a tab or the equivalent
305 number of spaces depending on the value of `indent-tabs-mode'."
306 :type 'function
307 :group 'c)
308
309 (defcustom c-syntactic-indentation t
310 "*Whether the indentation should be controlled by the syntactic context.
311
312 If t, the indentation functions indent according to the syntactic
313 context, using the style settings specified by `c-offsets-alist'.
314
315 If nil, every line is just indented to the same level as the previous
316 one, and the \\[c-indent-command] command adjusts the indentation in
317 steps specified by `c-basic-offset'. The indentation style has no
318 effect in this mode, nor any of the indentation associated variables,
319 e.g. `c-special-indent-hook'."
320 :type 'boolean
321 :group 'c)
322 (make-variable-buffer-local 'c-syntactic-indentation)
323 (put 'c-syntactic-indentation 'safe-local-variable 'booleanp)
324
325 (defcustom c-syntactic-indentation-in-macros t
326 "*Enable syntactic analysis inside macros.
327 If this is nil, all lines inside macro definitions are analyzed as
328 `cpp-macro-cont'. Otherwise they are analyzed syntactically, just
329 like normal code, and `cpp-define-intro' is used to create the
330 additional indentation of the bodies of \"#define\" macros.
331
332 Having this enabled simplifies editing of large multiline macros, but
333 it might complicate editing if CC Mode doesn't recognize the context
334 of the macro content. The default context inside the macro is the
335 same as the top level, so if it contains \"bare\" statements they
336 might be indented wrongly, although there are special cases that
337 handle this in most cases. If this problem occurs, it's usually
338 countered easily by surrounding the statements by a block \(or even
339 better with the \"do { ... } while \(0)\" trick)."
340 :type 'boolean
341 :group 'c)
342 (put 'c-syntactic-indentation-in-macros 'safe-local-variable 'booleanp)
343
344 (defcustom-c-stylevar c-comment-only-line-offset 0
345 "*Extra offset for line which contains only the start of a comment.
346 Can contain an integer or a cons cell of the form:
347
348 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
349
350 Where NON-ANCHORED-OFFSET is the amount of offset given to
351 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
352 the amount of offset to give column-zero anchored comment-only lines.
353 Just an integer as value is equivalent to (<val> . -1000).
354
355 Note that this variable only has effect when the `c-lineup-comment'
356 lineup function is used on the `comment-intro' syntactic symbol (the
357 default)."
358 :type '(choice (integer :tag "Non-anchored offset" 0)
359 (cons :tag "Non-anchored & anchored offset"
360 :value (0 . 0)
361 (integer :tag "Non-anchored offset")
362 (integer :tag "Anchored offset")))
363 :group 'c)
364
365 (defcustom-c-stylevar c-indent-comment-alist
366 '((anchored-comment . (column . 0))
367 (end-block . (space . 1))
368 (cpp-end-block . (space . 2)))
369 "*Specifies how \\[indent-for-comment] calculates the comment start column.
370 This is an association list that contains entries of the form:
371
372 (LINE-TYPE . INDENT-SPEC)
373
374 LINE-TYPE specifies a type of line as described below, and INDENT-SPEC
375 says what \\[indent-for-comment] should do when used on that type of line.
376
377 The recognized values for LINE-TYPE are:
378
379 empty-line -- The line is empty.
380 anchored-comment -- The line contains a comment that starts in column 0.
381 end-block -- The line contains a solitary block closing brace.
382 cpp-end-block -- The line contains a preprocessor directive that
383 closes a block, i.e. either \"#endif\" or \"#else\".
384 other -- The line does not match any other entry
385 currently on the list.
386
387 An INDENT-SPEC is a cons cell of the form:
388
389 (ACTION . VALUE)
390
391 ACTION says how \\[indent-for-comment] should align the comment, and
392 VALUE is interpreted depending on ACTION. ACTION can be any of the
393 following:
394
395 space -- Put VALUE spaces between the end of the line and the start
396 of the comment.
397 column -- Start the comment at the column VALUE. If the line is
398 longer than that, the comment is preceded by a single
399 space. If VALUE is nil, `comment-column' is used.
400 align -- Align the comment with one on the previous line, if there
401 is any. If the line is too long, the comment is preceded
402 by a single space. If there isn't a comment start on the
403 previous line, the behavior is specified by VALUE, which
404 in turn is interpreted as an INDENT-SPEC.
405
406 If a LINE-TYPE is missing, then \\[indent-for-comment] indents the comment
407 according to `comment-column'.
408
409 Note that a non-nil value on `c-indent-comments-syntactically-p'
410 overrides this variable, so empty lines are indentented syntactically
411 in that case, i.e. as if \\[c-indent-command] was used instead."
412 :type
413 (let ((space '(cons :tag "space"
414 :format "%v"
415 :value (space . 1)
416 (const :format "space " space)
417 (integer :format "%v")))
418 (column '(cons :tag "column"
419 :format "%v"
420 (const :format "column " column)
421 (c-integer-or-nil :format "%v"))))
422 `(set ,@(mapcar
423 (lambda (elt)
424 `(cons :format "%v"
425 ,(c-constant-symbol elt 20)
426 (choice
427 :format "%[Choice%] %v"
428 :value (column . nil)
429 ,space
430 ,column
431 (cons :tag "align"
432 :format "%v"
433 (const :format "align " align)
434 (choice
435 :format "%[Choice%] %v"
436 :value (column . nil)
437 ,space
438 ,column)))))
439 '(empty-line anchored-comment end-block cpp-end-block other))))
440 :group 'c)
441
442 (defcustom-c-stylevar c-indent-comments-syntactically-p nil
443 "*Specifies how \\[indent-for-comment] should handle comment-only lines.
444 When this variable is non-nil, comment-only lines are indented
445 according to syntactic analysis via `c-offsets-alist'. Otherwise, the
446 comment is indented as if it was preceded by code. Note that this
447 variable does not affect how the normal line indentation treats
448 comment-only lines."
449 :type 'boolean
450 :group 'c)
451
452 (make-obsolete-variable 'c-comment-continuation-stars
453 'c-block-comment-prefix)
454
455 ;; Although c-comment-continuation-stars is obsolete, we look at it in
456 ;; some places in CC Mode anyway, so make the compiler ignore it
457 ;; during our compilation.
458 ;; [This is unclean; better to use `symbol-value'. --ttn]
459 ;;(cc-bytecomp-obsolete-var c-comment-continuation-stars)
460 ;;(cc-bytecomp-defvar c-comment-continuation-stars)
461
462 (defcustom-c-stylevar c-block-comment-prefix
463 (if (boundp 'c-comment-continuation-stars)
464 (symbol-value 'c-comment-continuation-stars)
465 "* ")
466 "*Specifies the line prefix of continued C-style block comments.
467 You should set this variable to the literal string that gets inserted
468 at the front of continued block style comment lines. This should
469 either be the empty string, or some characters without preceding
470 spaces. To adjust the alignment under the comment starter, put an
471 appropriate value on the `c' syntactic symbol (see the
472 `c-offsets-alist' variable).
473
474 It's only used when a one-line block comment is broken into two or
475 more lines for the first time; otherwise the appropriate prefix is
476 adapted from the comment. This variable is not used for C++ line
477 style comments."
478 :type 'string
479 :group 'c)
480
481 (defcustom-c-stylevar c-comment-prefix-regexp
482 '((pike-mode . "//+!?\\|\\**")
483 (awk-mode . "#+")
484 (other . "//+\\|\\**"))
485 "*Regexp to match the line prefix inside comments.
486 This regexp is used to recognize the fill prefix inside comments for
487 correct paragraph filling and other things.
488
489 If this variable is a string, it will be used in all CC Mode major
490 modes. It can also be an association list, to associate specific
491 regexps to specific major modes. The symbol for the major mode is
492 looked up in the association list, and its value is used as the line
493 prefix regexp. If it's not found, then the symbol `other' is looked
494 up and its value is used instead.
495
496 The regexp should match the prefix used in both C++ style line
497 comments and C style block comments, but it does not need to match a
498 block comment starter. In other words, it should at least match
499 \"//\" for line comments and the string in `c-block-comment-prefix',
500 which is sometimes inserted by CC Mode inside block comments. It
501 should not match any surrounding whitespace.
502
503 Note that CC Mode uses this variable to set many other variables that
504 handle the paragraph filling. That's done at mode initialization or
505 when you switch to a style which sets this variable. Thus, if you
506 change it in some other way, e.g. interactively in a CC Mode buffer,
507 you will need to do \\[c-setup-paragraph-variables] afterwards so that
508 the other variables are updated with the new value.
509
510 Note also that when CC Mode starts up, all variables are initialized
511 before the mode hooks are run. It's therefore necessary to make a
512 call to `c-setup-paragraph-variables' explicitly if you change this
513 variable in a mode hook."
514 :type '(radio
515 (regexp :tag "Regexp for all modes")
516 (list
517 :tag "Mode-specific regexps"
518 (set
519 :inline t :format "%v"
520 (cons :format "%v"
521 (const :format "C " c-mode) (regexp :format "%v"))
522 (cons :format "%v"
523 (const :format "C++ " c++-mode) (regexp :format "%v"))
524 (cons :format "%v"
525 (const :format "ObjC " objc-mode) (regexp :format "%v"))
526 (cons :format "%v"
527 (const :format "Java " java-mode) (regexp :format "%v"))
528 (cons :format "%v"
529 (const :format "IDL " idl-mode) (regexp :format "%v"))
530 (cons :format "%v"
531 (const :format "Pike " pike-mode) (regexp :format "%v"))
532 (cons :format "%v"
533 (const :format "AWK " awk-mode) (regexp :format "%v")))
534 (cons :format " %v"
535 (const :format "Other " other) (regexp :format "%v"))))
536 :group 'c)
537
538 (defcustom-c-stylevar c-doc-comment-style
539 '((java-mode . javadoc)
540 (pike-mode . autodoc)
541 (c-mode . gtkdoc))
542 "*Specifies documentation comment style(s) to recognize.
543 This is primarily used to fontify doc comments and the markup within
544 them, e.g. Javadoc comments.
545
546 The value can be any of the following symbols for various known doc
547 comment styles:
548
549 javadoc -- Javadoc style for \"/** ... */\" comments (default in Java mode).
550 autodoc -- Pike autodoc style for \"//! ...\" comments (default in Pike mode).
551 gtkdoc -- GtkDoc style for \"/** ... **/\" comments (default in C mode).
552
553 The value may also be a list of doc comment styles, in which case all
554 of them are recognized simultaneously (presumably with markup cues
555 that don't conflict).
556
557 The value may also be an association list to specify different doc
558 comment styles for different languages. The symbol for the major mode
559 is then looked up in the alist, and the value of that element is
560 interpreted as above if found. If it isn't found then the symbol
561 `other' is looked up and its value is used instead.
562
563 Note that CC Mode uses this variable to set other variables that
564 handle fontification etc. That's done at mode initialization or when
565 you switch to a style which sets this variable. Thus, if you change
566 it in some other way, e.g. interactively in a CC Mode buffer, you will
567 need to do \\[java-mode] (or whatever mode you're currently using) to
568 reinitialize.
569
570 Note also that when CC Mode starts up, the other variables are
571 modified before the mode hooks are run. If you change this variable
572 in a mode hook, you have to call `c-setup-doc-comment-style'
573 afterwards to redo that work."
574 ;; Symbols other than those documented above may be used on this
575 ;; variable. If a variable exists that has that name with
576 ;; "-font-lock-keywords" appended, it's value is prepended to the
577 ;; font lock keywords list. If it's a function then it's called and
578 ;; the result is prepended.
579 :type '(radio
580 (c-symbol-list :tag "Doc style(s) in all modes")
581 (list
582 :tag "Mode-specific doc styles"
583 (set
584 :inline t :format "%v"
585 (cons :format "%v"
586 (const :format "C " c-mode)
587 (c-symbol-list :format "%v"))
588 (cons :format "%v"
589 (const :format "C++ " c++-mode)
590 (c-symbol-list :format "%v"))
591 (cons :format "%v"
592 (const :format "ObjC " objc-mode)
593 (c-symbol-list :format "%v"))
594 (cons :format "%v"
595 (const :format "Java " java-mode)
596 (c-symbol-list :format "%v"))
597 (cons :format "%v"
598 (const :format "IDL " idl-mode)
599 (c-symbol-list :format "%v"))
600 (cons :format "%v"
601 (const :format "Pike " pike-mode)
602 (c-symbol-list :format "%v"))
603 (cons :format "%v"
604 (const :format "AWK " awk-mode)
605 (c-symbol-list :format "%v"))
606 (cons :format "%v"
607 (const :format "Other " other)
608 (c-symbol-list :format "%v")))))
609 :group 'c)
610
611 (defcustom c-ignore-auto-fill '(string cpp code)
612 "*List of contexts in which automatic filling never occurs.
613 If Auto Fill mode is active, it will be temporarily disabled if point
614 is in any context on this list. It's e.g. useful to enable Auto Fill
615 in comments only, but not in strings or normal code. The valid
616 contexts are:
617
618 string -- inside a string or character literal
619 c -- inside a C style block comment
620 c++ -- inside a C++ style line comment
621 cpp -- inside a preprocessor directive
622 code -- anywhere else, i.e. in normal code"
623 :type '(set
624 (const :tag "String literals" string)
625 (const :tag "C style block comments" c)
626 (const :tag "C++ style line comments" c++)
627 (const :tag "Preprocessor directives" cpp)
628 (const :tag "Normal code" code))
629 :group 'c)
630
631 (defcustom-c-stylevar c-cleanup-list '(scope-operator)
632 "*List of various C/C++/ObjC constructs to \"clean up\".
633 The following clean ups only take place when the auto-newline feature
634 is turned on, as evidenced by the `/la' appearing next to the mode
635 name:
636
637 brace-else-brace -- Clean up \"} else {\" constructs by placing
638 entire construct on a single line. This clean
639 up only takes place when there is nothing but
640 white space between the braces and the `else'.
641 Clean up occurs when the open brace after the
642 `else' is typed.
643 brace-elseif-brace -- Similar to brace-else-brace, but clean up
644 \"} else if (...) {\" constructs. Clean up
645 occurs after the open parenthesis and the open
646 brace.
647 brace-catch-brace -- Similar to brace-elseif-brace, but clean up
648 \"} catch (...) {\" constructs.
649 empty-defun-braces -- Clean up empty defun braces by placing the
650 braces on the same line. Clean up occurs when
651 the defun closing brace is typed.
652 one-liner-defun -- If the code inside a function body can fit in
653 a single line, then remove any newlines
654 between that line and the defun braces so that
655 the whole body becomes a single line.
656 `c-max-one-liner-length' gives the maximum
657 length allowed for the resulting line. Clean
658 up occurs when the closing brace is typed.
659 defun-close-semi -- Clean up the terminating semi-colon on defuns
660 by placing the semi-colon on the same line as
661 the closing brace. Clean up occurs when the
662 semi-colon is typed.
663 list-close-comma -- Clean up commas following braces in array
664 and aggregate initializers. Clean up occurs
665 when the comma is typed.
666 scope-operator -- Clean up double colons which may designate
667 a C++ scope operator split across multiple
668 lines. Note that certain C++ constructs can
669 generate ambiguous situations. This clean up
670 only takes place when there is nothing but
671 whitespace between colons. Clean up occurs
672 when the second colon is typed.
673
674 The following clean ups always take place when they are on this list,
675 regardless of the auto-newline feature, since they typically don't
676 involve auto-newline inserted newlines:
677
678 space-before-funcall -- Insert exactly one space before the opening
679 parenthesis of a function call. Clean up
680 occurs when the opening parenthesis is typed.
681 compact-empty-funcall -- Clean up any space before the function call
682 opening parenthesis if and only if the
683 argument list is empty. This is typically
684 useful together with `space-before-funcall' to
685 get the style \"foo (bar)\" and \"foo()\".
686 Clean up occurs when the closing parenthesis
687 is typed.
688 comment-close-slash -- When a slash is typed after the comment prefix
689 on a bare line in a c-style comment, the comment
690 is closed by cleaning up preceding space and
691 inserting a star if needed."
692 :type '(set
693 (const :tag "Put \"} else {\" on one line (brace-else-brace)"
694 brace-else-brace)
695 (const :tag "Put \"} else if (...) {\" on one line (brace-elseif-brace)"
696 brace-elseif-brace)
697 (const :tag "Put \"} catch (...) {\" on one line (brace-catch-brace)"
698 brace-catch-brace)
699 (const :tag "Put empty defun braces on one line (empty-defun-braces)"
700 empty-defun-braces)
701 (const :tag "Put short function bodies on one line (one-liner-defun)"
702 one-liner-defun)
703 (const :tag "Put \"};\" ending defuns on one line (defun-close-semi)"
704 defun-close-semi)
705 (const :tag "Put \"},\" in aggregates on one line (list-close-comma)"
706 list-close-comma)
707 (const :tag "Put C++ style \"::\" on one line (scope-operator)"
708 scope-operator)
709 (const :tag "Put a space before funcall parens, e.g. \"foo (bar)\" (space-before-funcall)"
710 space-before-funcall)
711 (const :tag "Remove space before empty funcalls, e.g. \"foo()\" (compact-empty-funcall)"
712 compact-empty-funcall)
713 (const :tag "Make / on a bare line of a C-style comment close it (comment-close-slash)"
714 comment-close-slash))
715 :group 'c)
716
717 (defcustom-c-stylevar c-hanging-braces-alist '((brace-list-open)
718 (brace-entry-open)
719 (statement-cont)
720 (substatement-open after)
721 (block-close . c-snug-do-while)
722 (extern-lang-open after)
723 (namespace-open after)
724 (module-open after)
725 (composition-open after)
726 (inexpr-class-open after)
727 (inexpr-class-close before)
728 (arglist-cont-nonempty))
729 "*Controls the insertion of newlines before and after braces
730 when the auto-newline feature is active. This variable contains an
731 association list with elements of the following form:
732 \(SYNTACTIC-SYMBOL . ACTION).
733
734 When a brace (either opening or closing) is inserted, the syntactic
735 context it defines is looked up in this list, and if found, the
736 associated ACTION is used to determine where newlines are inserted.
737 If the context is not found, the default is to insert a newline both
738 before and after the brace.
739
740 SYNTACTIC-SYMBOL can be statement-cont, brace-list-intro,
741 inexpr-class-open, inexpr-class-close, and any of the *-open and
742 *-close symbols. See `c-offsets-alist' for details, except for
743 inexpr-class-open and inexpr-class-close, which doesn't have any
744 corresponding symbols there. Those two symbols are used for the
745 opening and closing braces, respectively, of anonymous inner classes
746 in Java.
747
748 ACTION can be either a function symbol or a list containing any
749 combination of the symbols `before' or `after'. If the list is empty,
750 no newlines are inserted either before or after the brace.
751
752 When ACTION is a function symbol, the function is called with a two
753 arguments: the syntactic symbol for the brace and the buffer position
754 at which the brace was inserted. The function must return a list as
755 described in the preceding paragraph. Note that during the call to
756 the function, the variable `c-syntactic-context' is set to the entire
757 syntactic context for the brace line."
758 :type
759 `(set ,@(mapcar
760 (lambda (elt)
761 `(cons :format "%v"
762 ,(c-constant-symbol elt 24)
763 (choice :format "%[Choice%] %v"
764 :value (before after)
765 (set :menu-tag "Before/after"
766 :format "Newline %v brace\n"
767 (const :format "%v, " before)
768 (const :format "%v " after))
769 (function :menu-tag "Function"
770 :format "Run function: %v"))))
771 '(defun-open defun-close
772 class-open class-close
773 inline-open inline-close
774 block-open block-close
775 statement-cont substatement-open statement-case-open
776 brace-list-open brace-list-close
777 brace-list-intro brace-entry-open
778 extern-lang-open extern-lang-close
779 namespace-open namespace-close
780 module-open module-close
781 composition-open composition-close
782 inexpr-class-open inexpr-class-close
783 arglist-cont-nonempty)))
784 :group 'c)
785
786 (defcustom c-max-one-liner-length 80
787 "Maximum length of line that clean-up \"one-liner-defun\" will compact to.
788 Zero or nil means no limit."
789 :type 'integer
790 :group 'c)
791
792 (defcustom-c-stylevar c-hanging-colons-alist nil
793 "*Controls the insertion of newlines before and after certain colons.
794 This variable contains an association list with elements of the
795 following form: (SYNTACTIC-SYMBOL . ACTION).
796
797 SYNTACTIC-SYMBOL can be any of: case-label, label, access-label,
798 member-init-intro, or inher-intro.
799
800 See the variable `c-hanging-braces-alist' for the semantics of this
801 variable. Note however that making ACTION a function symbol is
802 currently not supported for this variable."
803 :type
804 `(set ,@(mapcar
805 (lambda (elt)
806 `(cons :format "%v"
807 ,(c-constant-symbol elt 20)
808 (set :format "Newline %v colon\n"
809 (const :format "%v, " before)
810 (const :format "%v" after))))
811 '(case-label label access-label member-init-intro inher-intro)))
812 :group 'c)
813
814 (defcustom-c-stylevar c-hanging-semi&comma-criteria
815 '(c-semi&comma-inside-parenlist)
816 "*List of functions that decide whether to insert a newline or not.
817 The functions in this list are called, in order, whenever the
818 auto-newline minor mode is activated (as evidenced by a `/a' or `/ah'
819 string in the mode line), and a semicolon or comma is typed (see
820 `c-electric-semi&comma'). Each function in this list is called with
821 no arguments, and should return one of the following values:
822
823 nil -- no determination made, continue checking
824 'stop -- do not insert a newline, and stop checking
825 (anything else) -- insert a newline, and stop checking
826
827 If every function in the list is called with no determination made,
828 then no newline is inserted."
829 :type '(repeat function)
830 :group 'c)
831
832 (defcustom-c-stylevar c-backslash-column 48
833 "*Minimum alignment column for line continuation backslashes.
834 This is used by the functions that automatically insert or align the
835 line continuation backslashes in multiline macros. If any line in the
836 macro exceeds this column then the next tab stop from that line is
837 used as alignment column instead. See also `c-backslash-max-column'."
838 :type 'integer
839 :group 'c)
840 ;;;###autoload(put 'c-backslash-column 'safe-local-variable 'integerp)
841
842 (defcustom-c-stylevar c-backslash-max-column 72
843 "*Maximum alignment column for line continuation backslashes.
844 This is used by the functions that automatically insert or align the
845 line continuation backslashes in multiline macros. If any line in the
846 macro exceeds this column then the backslashes for the other lines
847 will be aligned at this column."
848 :type 'integer
849 :group 'c)
850
851 (defcustom c-auto-align-backslashes t
852 "*Align automatically inserted line continuation backslashes.
853 When line continuation backslashes are inserted automatically for line
854 breaks in multiline macros, e.g. by \\[c-context-line-break], they are
855 aligned with the other backslashes in the same macro if this flag is
856 set. Otherwise the inserted backslashes are preceded by a single
857 space."
858 :type 'boolean
859 :group 'c)
860
861 (defcustom c-backspace-function 'backward-delete-char-untabify
862 "*Function called by `c-electric-backspace' when deleting backwards."
863 :type 'function
864 :group 'c)
865
866 (defcustom c-delete-function 'delete-char
867 "*Function called by `c-electric-delete-forward' when deleting forwards."
868 :type 'function
869 :group 'c)
870
871 (defcustom c-require-final-newline
872 ;; C and C++ mandate that all nonempty files should end with a
873 ;; newline. Objective-C refers to C for all things it doesn't
874 ;; specify, so the same holds there. The other languages do not
875 ;; require it (at least not explicitly in a normative text).
876 '((c-mode . t)
877 (c++-mode . t)
878 (objc-mode . t))
879 "*Controls whether a final newline is ensured when the file is saved.
880 The value is an association list that for each language mode specifies
881 the value to give to `require-final-newline' at mode initialization;
882 see that variable for details about the value. If a language isn't
883 present on the association list, CC Mode won't touch
884 `require-final-newline' in buffers for that language."
885 :type `(set (cons :format "%v"
886 (const :format "C " c-mode)
887 (symbol :format "%v" :value ,require-final-newline))
888 (cons :format "%v"
889 (const :format "C++ " c++-mode)
890 (symbol :format "%v" :value ,require-final-newline))
891 (cons :format "%v"
892 (const :format "ObjC " objc-mode)
893 (symbol :format "%v" :value ,require-final-newline))
894 (cons :format "%v"
895 (const :format "Java " java-mode)
896 (symbol :format "%v" :value ,require-final-newline))
897 (cons :format "%v"
898 (const :format "IDL " idl-mode)
899 (symbol :format "%v" :value ,require-final-newline))
900 (cons :format "%v"
901 (const :format "Pike " pike-mode)
902 (symbol :format "%v" :value ,require-final-newline))
903 (cons :format "%v"
904 (const :format "AWK " awk-mode)
905 (symbol :format "%v" :value ,require-final-newline)))
906 :group 'c)
907
908 (defcustom c-electric-pound-behavior nil
909 "*List of behaviors for electric pound insertion.
910 Only currently supported behavior is `alignleft'."
911 :type '(set (const alignleft))
912 :group 'c)
913
914 (defcustom c-special-indent-hook nil
915 "*Hook for user defined special indentation adjustments.
916 This hook gets called after each line is indented by the mode. It is only
917 called if `c-syntactic-indentation' is non-nil."
918 :type 'hook
919 :group 'c)
920
921 (defcustom-c-stylevar c-label-minimum-indentation 1
922 "*Minimum indentation for lines inside code blocks.
923 This variable typically only affects code using the `gnu' style, which
924 mandates a minimum of one space in front of every line inside code
925 blocks. Specifically, the function `c-gnu-impose-minimum' on your
926 `c-special-indent-hook' is what enforces this."
927 :type 'integer
928 :group 'c)
929
930 (defcustom c-progress-interval 5
931 "*Interval used to update progress status during long re-indentation.
932 If a number, percentage complete gets updated after each interval of
933 that many seconds. To inhibit all messages during indentation, set
934 this variable to nil."
935 :type 'integer
936 :group 'c)
937
938 (defcustom c-default-style '((java-mode . "java") (awk-mode . "awk")
939 (other . "gnu"))
940 "*Style which gets installed by default when a file is visited.
941
942 The value of this variable can be any style defined in
943 `c-style-alist', including styles you add. The value can also be an
944 association list of major mode symbols to style names.
945
946 When the value is a string, all CC Mode major modes will install this
947 style by default.
948
949 When the value is an alist, the major mode symbol is looked up in it
950 and the associated style is installed. If the major mode is not
951 listed in the alist, then the symbol `other' is looked up in it, and
952 if found, the style in that entry is used. If `other' is not found in
953 the alist, then \"gnu\" style is used.
954
955 The default style gets installed before your mode hooks run, so you
956 can always override the use of `c-default-style' by making calls to
957 `c-set-style' in the appropriate mode hook."
958 :type '(radio
959 (string :tag "Style in all modes")
960 (set :tag "Mode-specific styles"
961 (cons :format "%v"
962 (const :format "C " c-mode) (string :format "%v"))
963 (cons :format "%v"
964 (const :format "C++ " c++-mode) (string :format "%v"))
965 (cons :format "%v"
966 (const :format "ObjC " objc-mode) (string :format "%v"))
967 (cons :format "%v"
968 (const :format "Java " java-mode) (string :format "%v"))
969 (cons :format "%v"
970 (const :format "IDL " idl-mode) (string :format "%v"))
971 (cons :format "%v"
972 (const :format "Pike " pike-mode) (string :format "%v"))
973 (cons :format "%v"
974 (const :format "AWK " awk-mode) (string :format "%v"))
975 (cons :format "%v"
976 (const :format "Other " other) (string :format "%v"))))
977 :group 'c)
978
979 ;; *) At the start of a statement or declaration means in more detail:
980 ;; At the closest preceding statement/declaration that starts at boi
981 ;; and doesn't have a label or comment at that position. If there's
982 ;; no such statement within the same block, then back up to the
983 ;; surrounding block or statement, add the appropriate
984 ;; statement-block-intro, defun-block-intro or substatement syntax
985 ;; symbol and continue searching.
986 (c-set-stylevar-fallback 'c-offsets-alist
987 '((string . c-lineup-dont-change)
988 ;; Anchor pos: Beg of previous line.
989 (c . c-lineup-C-comments)
990 ;; Anchor pos: Beg of the comment.
991 (defun-open . 0)
992 ;; Anchor pos: When inside a class: Boi at the func decl start.
993 ;; When at top level: Bol at the func decl start. When inside
994 ;; a code block (only possible in Pike): At the func decl
995 ;; start(*).
996 (defun-close . 0)
997 ;; Anchor pos: At the defun block open if it's at boi,
998 ;; otherwise boi at the func decl start.
999 (defun-block-intro . +)
1000 ;; Anchor pos: At the block open(*).
1001 (class-open . 0)
1002 ;; Anchor pos: Boi at the class decl start.
1003 (class-close . 0)
1004 ;; Anchor pos: Boi at the class decl start.
1005 (inline-open . +)
1006 ;; Anchor pos: None for functions (inclass got the relpos
1007 ;; then), boi at the lambda start for lambdas.
1008 (inline-close . 0)
1009 ;; Anchor pos: Inexpr functions: At the lambda block open if
1010 ;; it's at boi, else at the statement(*) at boi of the start of
1011 ;; the lambda construct. Otherwise: At the inline block open
1012 ;; if it's at boi, otherwise boi at the func decl start.
1013 (func-decl-cont . +)
1014 ;; Anchor pos: Boi at the func decl start.
1015 (knr-argdecl-intro . +)
1016 ;; Anchor pos: Boi at the topmost intro line.
1017 (knr-argdecl . 0)
1018 ;; Anchor pos: At the beginning of the first K&R argdecl.
1019 (topmost-intro . 0)
1020 ;; Anchor pos: Bol at the last line of previous construct.
1021 (topmost-intro-cont . c-lineup-topmost-intro-cont)
1022 ;; Anchor pos: Boi at the topmost intro line.
1023 (member-init-intro . +)
1024 ;; Anchor pos: Boi at the func decl arglist open.
1025 (member-init-cont . c-lineup-multi-inher)
1026 ;; Anchor pos: Beg of the first member init.
1027 (inher-intro . +)
1028 ;; Anchor pos: Boi at the class decl start.
1029 (inher-cont . c-lineup-multi-inher)
1030 ;; Anchor pos: Java: At the implements/extends keyword start.
1031 ;; Otherwise: At the inher start colon, or boi at the class
1032 ;; decl start if the first inherit clause hangs and it's not a
1033 ;; func-local inherit clause (when does that occur?).
1034 (block-open . 0)
1035 ;; Anchor pos: Inexpr statement: At the statement(*) at boi of
1036 ;; the start of the inexpr construct. Otherwise: None.
1037 (block-close . 0)
1038 ;; Anchor pos: Inexpr statement: At the inexpr block open if
1039 ;; it's at boi, else at the statement(*) at boi of the start of
1040 ;; the inexpr construct. Block hanging on a case/default
1041 ;; label: At the closest preceding label that starts at boi.
1042 ;; Otherwise: At the block open(*).
1043 (brace-list-open . 0)
1044 ;; Anchor pos: Boi at the brace list decl start, but a starting
1045 ;; "typedef" token is ignored.
1046 (brace-list-close . 0)
1047 ;; Anchor pos: At the brace list decl start(*).
1048 (brace-list-intro . +)
1049 ;; Anchor pos: At the brace list decl start(*).
1050 (brace-list-entry . 0)
1051 ;; Anchor pos: At the first non-ws char after the open paren if
1052 ;; the first token is on the same line, otherwise boi at that
1053 ;; token.
1054 (brace-entry-open . 0)
1055 ;; Anchor pos: Same as brace-list-entry.
1056 (statement . 0)
1057 ;; Anchor pos: After a `;' in the condition clause of a for
1058 ;; statement: At the first token after the starting paren.
1059 ;; Otherwise: At the preceding statement(*).
1060 (statement-cont . +)
1061 ;; Anchor pos: After the first token in the condition clause of
1062 ;; a for statement: At the first token after the starting
1063 ;; paren. Otherwise: At the containing statement(*).
1064 (statement-block-intro . +)
1065 ;; Anchor pos: In inexpr statement block: At the inexpr block
1066 ;; open if it's at boi, else at the statement(*) at boi of the
1067 ;; start of the inexpr construct. In a block hanging on a
1068 ;; case/default label: At the closest preceding label that
1069 ;; starts at boi. Otherwise: At the start of the containing
1070 ;; block(*).
1071 (statement-case-intro . +)
1072 ;; Anchor pos: At the case/default label(*).
1073 (statement-case-open . 0)
1074 ;; Anchor pos: At the case/default label(*).
1075 (substatement . +)
1076 ;; Anchor pos: At the containing statement(*).
1077 (substatement-open . +)
1078 ;; Anchor pos: At the containing statement(*).
1079 (substatement-label . 2)
1080 ;; Anchor pos: At the containing statement(*).
1081 (case-label . 0)
1082 ;; Anchor pos: At the start of the switch block(*).
1083 (access-label . -)
1084 ;; Anchor pos: Same as inclass.
1085 (label . 2)
1086 ;; Anchor pos: At the start of the containing block(*).
1087 (do-while-closure . 0)
1088 ;; Anchor pos: At the corresponding while statement(*).
1089 (else-clause . 0)
1090 ;; Anchor pos: At the corresponding if statement(*).
1091 (catch-clause . 0)
1092 ;; Anchor pos: At the previous try or catch statement clause(*).
1093 (comment-intro . (c-lineup-knr-region-comment c-lineup-comment))
1094 ;; Anchor pos: None.
1095 (arglist-intro . +)
1096 ;; Anchor pos: At the containing statement(*).
1097 ;; 2nd pos: At the open paren.
1098 (arglist-cont . (c-lineup-gcc-asm-reg 0))
1099 ;; Anchor pos: At the first token after the open paren.
1100 (arglist-cont-nonempty . (c-lineup-gcc-asm-reg c-lineup-arglist))
1101 ;; Anchor pos: At the containing statement(*).
1102 ;; 2nd pos: At the open paren.
1103 (arglist-close . +)
1104 ;; Anchor pos: At the containing statement(*).
1105 ;; 2nd pos: At the open paren.
1106 (stream-op . c-lineup-streamop)
1107 ;; Anchor pos: Boi at the first stream op in the statement.
1108 (inclass . +)
1109 ;; Anchor pos: At the class open brace if it's at boi,
1110 ;; otherwise boi at the class decl start.
1111 (cpp-macro . [0])
1112 ;; Anchor pos: None.
1113 (cpp-macro-cont . +)
1114 ;; Anchor pos: At the macro start (always at boi).
1115 (cpp-define-intro . (c-lineup-cpp-define +))
1116 ;; Anchor pos: None.
1117 (friend . 0)
1118 ;; Anchor pos: None.
1119 (objc-method-intro . [0])
1120 ;; Anchor pos: Boi.
1121 (objc-method-args-cont . c-lineup-ObjC-method-args)
1122 ;; Anchor pos: At the method start (always at boi).
1123 (objc-method-call-cont . c-lineup-ObjC-method-call)
1124 ;; Anchor pos: At the open bracket.
1125 (extern-lang-open . 0)
1126 (namespace-open . 0)
1127 (module-open . 0)
1128 (composition-open . 0)
1129 ;; Anchor pos: Boi at the extern/namespace/etc keyword.
1130 (extern-lang-close . 0)
1131 (namespace-close . 0)
1132 (module-close . 0)
1133 (composition-close . 0)
1134 ;; Anchor pos: Boi at the corresponding extern/namespace/etc keyword.
1135 (inextern-lang . +)
1136 (innamespace . +)
1137 (inmodule . +)
1138 (incomposition . +)
1139 ;; Anchor pos: At the extern/namespace/etc block open brace if
1140 ;; it's at boi, otherwise boi at the keyword.
1141 (template-args-cont . (c-lineup-template-args +))
1142 ;; Anchor pos: Boi at the decl start. This might be changed;
1143 ;; the logical position is clearly the opening '<'.
1144 (inlambda . c-lineup-inexpr-block)
1145 ;; Anchor pos: None.
1146 (lambda-intro-cont . +)
1147 ;; Anchor pos: Boi at the lambda start.
1148 (inexpr-statement . +)
1149 ;; Anchor pos: None.
1150 (inexpr-class . +)
1151 ;; Anchor pos: None.
1152 ))
1153 (defcustom c-offsets-alist nil
1154 "Association list of syntactic element symbols and indentation offsets.
1155 As described below, each cons cell in this list has the form:
1156
1157 (SYNTACTIC-SYMBOL . OFFSET)
1158
1159 When a line is indented, CC Mode first determines the syntactic
1160 context of it by generating a list of symbols called syntactic
1161 elements. The global variable `c-syntactic-context' is bound to the
1162 that list. Each element in the list is in turn a list where the first
1163 element is a syntactic symbol which tells what kind of construct the
1164 indentation point is located within. More elements in the syntactic
1165 element lists are optional. If there is one more and it isn't nil,
1166 then it's the anchor position for that construct.
1167
1168 After generating the syntactic context for the line, CC Mode
1169 calculates the absolute indentation: First the base indentation is
1170 found by using the anchor position for the first syntactic element
1171 that provides one. If none does, zero is used as base indentation.
1172 Then CC Mode looks at each syntactic element in the context in turn.
1173 It compares the car of the syntactic element against the
1174 SYNTACTIC-SYMBOL's in `c-offsets-alist'. When it finds a match, it
1175 adds OFFSET to the base indentation. The sum of this calculation is
1176 the absolute offset for line being indented.
1177
1178 If the syntactic element does not match any in the `c-offsets-alist',
1179 the element is ignored.
1180
1181 OFFSET can specify an offset in several different ways:
1182
1183 If OFFSET is nil then it's ignored.
1184
1185 If OFFSET is an integer then it's used as relative offset, i.e. it's
1186 added to the base indentation.
1187
1188 If OFFSET is one of the symbols `+', `-', `++', `--', `*', or `/'
1189 then a positive or negative multiple of `c-basic-offset' is added to
1190 the base indentation; 1, -1, 2, -2, 0.5, and -0.5, respectively.
1191
1192 If OFFSET is a symbol with a value binding then that value, which
1193 must be an integer, is used as relative offset.
1194
1195 If OFFSET is a vector then its first element, which must be an
1196 integer, is used as an absolute indentation column. This overrides
1197 the previous base indentation and the relative offsets applied to
1198 it, and it becomes the new base indentation.
1199
1200 If OFFSET is a function or a lambda expression then it's called with
1201 a single argument containing the cons of the syntactic symbol and
1202 the anchor position (or nil if there is none). The return value
1203 from the function is then reinterpreted as an offset specification.
1204
1205 If OFFSET is a list then its elements are evaluated recursively as
1206 offset specifications. If the first element is any of the symbols
1207 below then it isn't evaluated but instead specifies how the
1208 remaining offsets in the list should be combined. If it's something
1209 else then the list is combined according the method `first'. The
1210 valid combination methods are:
1211
1212 `first' -- Use the first offset (that doesn't evaluate to nil).
1213 `min' -- Use the minimum of all the offsets. All must be either
1214 relative or absolute - they can't be mixed.
1215 `max' -- Use the maximum of all the offsets. All must be either
1216 relative or absolute - they can't be mixed.
1217 `add' -- Add all the evaluated offsets together. Exactly one of
1218 them may be absolute, in which case the result is
1219 absolute. Any relative offsets that preceded the
1220 absolute one in the list will be ignored in that case.
1221
1222 `c-offsets-alist' is a style variable. This means that the offsets on
1223 this variable are normally taken from the style system in CC Mode
1224 \(see `c-default-style' and `c-style-alist'). However, any offsets
1225 put explicitly on this list will override the style system when a CC
1226 Mode buffer is initialized \(there is a variable
1227 `c-old-style-variable-behavior' that changes this, though).
1228
1229 Here is the current list of valid syntactic element symbols:
1230
1231 string -- Inside multi-line string.
1232 c -- Inside a multi-line C style block comment.
1233 defun-open -- Brace that opens a function definition.
1234 defun-close -- Brace that closes a function definition.
1235 defun-block-intro -- The first line in a top-level defun.
1236 class-open -- Brace that opens a class definition.
1237 class-close -- Brace that closes a class definition.
1238 inline-open -- Brace that opens an in-class inline method.
1239 inline-close -- Brace that closes an in-class inline method.
1240 func-decl-cont -- The region between a function definition's
1241 argument list and the function opening brace
1242 (excluding K&R argument declarations). In C, you
1243 cannot put anything but whitespace and comments
1244 between them; in C++ and Java, throws declarations
1245 and other things can appear in this context.
1246 knr-argdecl-intro -- First line of a K&R C argument declaration.
1247 knr-argdecl -- Subsequent lines in a K&R C argument declaration.
1248 topmost-intro -- The first line in a topmost construct definition.
1249 topmost-intro-cont -- Topmost definition continuation lines.
1250 member-init-intro -- First line in a member initialization list.
1251 member-init-cont -- Subsequent member initialization list lines.
1252 inher-intro -- First line of a multiple inheritance list.
1253 inher-cont -- Subsequent multiple inheritance lines.
1254 block-open -- Statement block open brace.
1255 block-close -- Statement block close brace.
1256 brace-list-open -- Open brace of an enum or static array list.
1257 brace-list-close -- Close brace of an enum or static array list.
1258 brace-list-intro -- First line in an enum or static array list.
1259 brace-list-entry -- Subsequent lines in an enum or static array list.
1260 brace-entry-open -- Subsequent lines in an enum or static array
1261 list that start with an open brace.
1262 statement -- A C (or like) statement.
1263 statement-cont -- A continuation of a C (or like) statement.
1264 statement-block-intro -- The first line in a new statement block.
1265 statement-case-intro -- The first line in a case \"block\".
1266 statement-case-open -- The first line in a case block starting with brace.
1267 substatement -- The first line after an if/while/for/do/else.
1268 substatement-open -- The brace that opens a substatement block.
1269 substatement-label -- Labelled line after an if/while/for/do/else.
1270 case-label -- A \"case\" or \"default\" label.
1271 access-label -- C++ private/protected/public access label.
1272 label -- Any ordinary label.
1273 do-while-closure -- The \"while\" that ends a do/while construct.
1274 else-clause -- The \"else\" of an if/else construct.
1275 catch-clause -- The \"catch\" or \"finally\" of a try/catch construct.
1276 comment-intro -- A line containing only a comment introduction.
1277 arglist-intro -- The first line in an argument list.
1278 arglist-cont -- Subsequent argument list lines when no
1279 arguments follow on the same line as the
1280 arglist opening paren.
1281 arglist-cont-nonempty -- Subsequent argument list lines when at
1282 least one argument follows on the same
1283 line as the arglist opening paren.
1284 arglist-close -- The solo close paren of an argument list.
1285 stream-op -- Lines continuing a stream operator construct.
1286 inclass -- The construct is nested inside a class definition.
1287 Used together with e.g. `topmost-intro'.
1288 cpp-macro -- The start of a C preprocessor macro definition.
1289 cpp-macro-cont -- Inside a multi-line C preprocessor macro definition.
1290 friend -- A C++ friend declaration.
1291 objc-method-intro -- The first line of an Objective-C method definition.
1292 objc-method-args-cont -- Lines continuing an Objective-C method definition.
1293 objc-method-call-cont -- Lines continuing an Objective-C method call.
1294 extern-lang-open -- Brace that opens an \"extern\" block.
1295 extern-lang-close -- Brace that closes an \"extern\" block.
1296 inextern-lang -- Analogous to the `inclass' syntactic symbol,
1297 but used inside \"extern\" blocks.
1298 namespace-open, namespace-close, innamespace
1299 -- Similar to the three `extern-lang' symbols, but for
1300 C++ \"namespace\" blocks.
1301 module-open, module-close, inmodule
1302 -- Similar to the three `extern-lang' symbols, but for
1303 CORBA IDL \"module\" blocks.
1304 composition-open, composition-close, incomposition
1305 -- Similar to the three `extern-lang' symbols, but for
1306 CORBA CIDL \"composition\" blocks.
1307 template-args-cont -- C++ template argument list continuations.
1308 inlambda -- In the header or body of a lambda function.
1309 lambda-intro-cont -- Continuation of the header of a lambda function.
1310 inexpr-statement -- The statement is inside an expression.
1311 inexpr-class -- The class is inside an expression. Used e.g. for
1312 Java anonymous classes."
1313 :type
1314 `(set :format "%{%t%}:
1315 Override style setting
1316 | Syntax Offset
1317 %v"
1318 ,@(mapcar
1319 (lambda (elt)
1320 `(cons :format "%v"
1321 :value ,elt
1322 ,(c-constant-symbol (car elt) 25)
1323 (sexp :format "%v"
1324 :validate
1325 (lambda (widget)
1326 (unless (c-valid-offset (widget-value widget))
1327 (widget-put widget :error "Invalid offset")
1328 widget)))))
1329 (get 'c-offsets-alist 'c-stylevar-fallback)))
1330 :group 'c)
1331
1332 ;; The syntactic symbols that can occur inside code blocks. Used by
1333 ;; `c-gnu-impose-minimum'.
1334 (defconst c-inside-block-syms
1335 '(defun-block-intro block-open block-close statement statement-cont
1336 statement-block-intro statement-case-intro statement-case-open
1337 substatement substatement-open substatement-label case-label label
1338 do-while-closure else-clause catch-clause inlambda))
1339
1340 (defcustom c-style-variables-are-local-p t
1341 "*Whether style variables should be buffer local by default.
1342 If non-nil, then all indentation style related variables will be made
1343 buffer local by default. If nil, they will remain global. Variables
1344 are made buffer local when this file is loaded, and once buffer
1345 localized, they cannot be made global again.
1346
1347 This variable must be set appropriately before CC Mode is loaded.
1348
1349 The list of variables to buffer localize are:
1350 c-basic-offset
1351 c-comment-only-line-offset
1352 c-indent-comment-alist
1353 c-indent-comments-syntactically-p
1354 c-block-comment-prefix
1355 c-comment-prefix-regexp
1356 c-doc-comment-style
1357 c-cleanup-list
1358 c-hanging-braces-alist
1359 c-hanging-colons-alist
1360 c-hanging-semi&comma-criteria
1361 c-backslash-column
1362 c-backslash-max-column
1363 c-label-minimum-indentation
1364 c-offsets-alist
1365 c-special-indent-hook
1366 c-indentation-style"
1367 :type 'boolean
1368 :group 'c)
1369
1370 (defcustom c-mode-hook nil
1371 "*Hook called by `c-mode'."
1372 :type 'hook
1373 :group 'c)
1374
1375 (defcustom c++-mode-hook nil
1376 "*Hook called by `c++-mode'."
1377 :type 'hook
1378 :group 'c)
1379
1380 (defcustom objc-mode-hook nil
1381 "*Hook called by `objc-mode'."
1382 :type 'hook
1383 :group 'c)
1384
1385 (defcustom java-mode-hook nil
1386 "*Hook called by `java-mode'."
1387 :type 'hook
1388 :group 'c)
1389
1390 (defcustom idl-mode-hook nil
1391 "*Hook called by `idl-mode'."
1392 :type 'hook
1393 :group 'c)
1394
1395 (defcustom pike-mode-hook nil
1396 "*Hook called by `pike-mode'."
1397 :type 'hook
1398 :group 'c)
1399
1400 (defcustom awk-mode-hook nil
1401 "*Hook called by `awk-mode'."
1402 :type 'hook
1403 :group 'c)
1404
1405 (defcustom c-mode-common-hook nil
1406 "*Hook called by all CC Mode modes for common initializations."
1407 :type 'hook
1408 :group 'c)
1409
1410 (defcustom c-initialization-hook nil
1411 "*Hook called when the CC Mode package gets initialized.
1412 This hook is only run once per Emacs session and can be used as a
1413 `load-hook' or in place of using `eval-after-load'."
1414 :type 'hook
1415 :group 'c)
1416
1417 (defcustom c-enable-xemacs-performance-kludge-p nil
1418 "*Enables a XEmacs only hack that may improve speed for some coding styles.
1419 For styles that hang top-level opening braces (as is common with JDK
1420 Java coding styles) this can improve performance between 3 and 60
1421 times for core indentation functions (e.g. `c-parse-state'). For
1422 styles that conform to the Emacs recommendation of putting these
1423 braces in column zero, this can degrade performance about as much.
1424 This variable only has effect in XEmacs."
1425 :type 'boolean
1426 :group 'c)
1427
1428 (defvar c-old-style-variable-behavior nil
1429 "*Enables the old style variable behavior when non-nil.
1430
1431 Normally the values of the style variables will override the style
1432 settings specified by the variables `c-default-style' and
1433 `c-style-alist'. However, in CC Mode 5.25 and earlier, it was the
1434 other way around, meaning that changes made to the style variables
1435 from e.g. Customize would not take effect unless special precautions
1436 were taken. That was confusing, especially for novice users.
1437
1438 It's believed that despite this change, the new behavior will still
1439 produce the same results for most old CC Mode configurations, since
1440 all style variables are per default set in a special non-override
1441 state. Set this variable only if your configuration has stopped
1442 working due to this change.")
1443
1444 (define-widget 'c-extra-types-widget 'radio
1445 "Internal CC Mode widget for the `*-font-lock-extra-types' variables."
1446 :args '((const :tag "none" nil)
1447 (repeat :tag "types" regexp)))
1448
1449 (defun c-make-font-lock-extra-types-blurb (mode1 mode2 example)
1450 (concat "\
1451 *List of extra types (aside from the type keywords) to recognize in "
1452 mode1 " mode.
1453 Each list item should be a regexp matching a single identifier.
1454 " example "
1455
1456 Note that items on this list that don't include any regexp special
1457 characters are automatically optimized using `regexp-opt', so you
1458 should not use `regexp-opt' explicitly to build regexps here.
1459
1460 On decoration level 3 (and higher, where applicable), a method is used
1461 that finds most types and declarations by syntax alone. This variable
1462 is still used as a first step, but other types are recognized
1463 correctly anyway in most cases. Therefore this variable should be
1464 fairly restrictive and not contain patterns that are uncertain.
1465
1466 Note that this variable is only consulted when the major mode is
1467 initialized. If you change it later you have to reinitialize CC Mode
1468 by doing \\[" mode2 "].
1469
1470 Despite the name, this variable is not only used for font locking but
1471 also elsewhere in CC Mode to tell types from other identifiers."))
1472
1473 ;; Note: Most of the variables below are also defined in font-lock.el
1474 ;; in older versions of Emacs, so depending on the load order we might
1475 ;; not install the values below. There's no kludge to cope with this
1476 ;; (as opposed to the *-font-lock-keywords-* variables) since the old
1477 ;; values work fairly well anyway.
1478
1479 (defcustom c-font-lock-extra-types
1480 '("\\sw+_t"
1481 ;; Defined in C99:
1482 "bool" "complex" "imaginary"
1483 ;; Standard library types (except those matched by the _t pattern):
1484 "FILE" "lconv" "tm" "va_list" "jmp_buf"
1485 ;; I do not appreciate the following very Emacs-specific luggage
1486 ;; in the default value, but otoh it can hardly get in the way for
1487 ;; other users, and removing it would cause unnecessary grief for
1488 ;; the old timers that are used to it. /mast
1489 "Lisp_Object")
1490 (c-make-font-lock-extra-types-blurb "C" "c-mode"
1491 "For example, a value of (\"FILE\" \"\\\\sw+_t\") means the word \"FILE\"
1492 and words ending in \"_t\" are treated as type names.")
1493 :type 'c-extra-types-widget
1494 :group 'c)
1495
1496 (defcustom c++-font-lock-extra-types
1497 '("\\sw+_t"
1498 ;; C library types (except those matched by the _t pattern):
1499 "FILE" "lconv" "tm" "va_list" "jmp_buf"
1500 ;; Some standard C++ types that came from font-lock.el.
1501 ;; Experienced C++ users says there's no clear benefit in
1502 ;; extending this to all the types in the standard library, at
1503 ;; least not when they'll be recognized without "std::" too.
1504 "istream" "istreambuf"
1505 "ostream" "ostreambuf"
1506 "ifstream" "ofstream" "fstream"
1507 "strstream" "strstreambuf" "istrstream" "ostrstream"
1508 "ios"
1509 "string" "rope"
1510 "list" "slist"
1511 "deque" "vector" "bit_vector"
1512 "set" "multiset"
1513 "map" "multimap"
1514 "hash"
1515 "hash_set" "hash_multiset"
1516 "hash_map" "hash_multimap"
1517 "stack" "queue" "priority_queue"
1518 "type_info"
1519 "iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator"
1520 "reference" "const_reference")
1521 (c-make-font-lock-extra-types-blurb "C++" "c++-mode"
1522 "For example, a value of (\"string\") means the word \"string\" is treated
1523 as a type name.")
1524 :type 'c-extra-types-widget
1525 :group 'c)
1526
1527 (defcustom objc-font-lock-extra-types
1528 (list (concat "[" c-upper "]\\sw*[" c-lower "]\\sw*"))
1529 (c-make-font-lock-extra-types-blurb "ObjC" "objc-mode" (concat
1530 "For example, a value of (\"[" c-upper "]\\\\sw*[" c-lower "]\\\\sw*\") means
1531 capitalized words are treated as type names (the requirement for a
1532 lower case char is to avoid recognizing all-caps macro and constant
1533 names)."))
1534 :type 'c-extra-types-widget
1535 :group 'c)
1536
1537 (defcustom java-font-lock-extra-types
1538 (list (concat "[" c-upper "]\\sw*[" c-lower "]\\sw*"))
1539 (c-make-font-lock-extra-types-blurb "Java" "java-mode" (concat
1540 "For example, a value of (\"[" c-upper "]\\\\sw*[" c-lower "]\\\\sw*\") means
1541 capitalized words are treated as type names (the requirement for a
1542 lower case char is to avoid recognizing all-caps constant names)."))
1543 :type 'c-extra-types-widget
1544 :group 'c)
1545
1546 (defcustom idl-font-lock-extra-types nil
1547 (c-make-font-lock-extra-types-blurb "IDL" "idl-mode" "")
1548 :type 'c-extra-types-widget
1549 :group 'c)
1550
1551 (defcustom pike-font-lock-extra-types
1552 (list (concat "[" c-upper "]\\sw*[" c-lower "]\\sw*"))
1553 (c-make-font-lock-extra-types-blurb "Pike" "pike-mode" (concat
1554 "For example, a value of (\"[" c-upper "]\\\\sw*[" c-lower "]\\\\sw*\") means
1555 capitalized words are treated as type names (the requirement for a
1556 lower case char is to avoid recognizing all-caps macro and constant
1557 names)."))
1558 :type 'c-extra-types-widget
1559 :group 'c)
1560
1561 \f
1562 ;; Non-customizable variables, still part of the interface to CC Mode
1563 (defvar c-file-style nil
1564 "Variable interface for setting style via File Local Variables.
1565 In a file's Local Variable section, you can set this variable to a
1566 string suitable for `c-set-style'. When the file is visited, CC Mode
1567 will set the style of the file to this value automatically.
1568
1569 Note that file style settings are applied before file offset settings
1570 as designated in the variable `c-file-offsets'.")
1571 (make-variable-buffer-local 'c-file-style)
1572 ;;;###autoload(put 'c-file-style 'safe-local-variable 'string-or-null-p)
1573
1574 (defvar c-file-offsets nil
1575 "Variable interface for setting offsets via File Local Variables.
1576 In a file's Local Variable section, you can set this variable to an
1577 association list similar to the values allowed in `c-offsets-alist'.
1578 When the file is visited, CC Mode will institute these offset settings
1579 automatically.
1580
1581 Note that file offset settings are applied after file style settings
1582 as designated in the variable `c-file-style'.")
1583 (make-variable-buffer-local 'c-file-offsets)
1584
1585 ;; It isn't possible to specify a doc-string without specifying an
1586 ;; initial value with `defvar', so the following two variables have been
1587 ;; given doc-strings by setting the property `variable-documentation'
1588 ;; directly. C-h v will read this documentation only for versions of GNU
1589 ;; Emacs from 22.1. It's really good not to have an initial value for
1590 ;; variables like these that always should be dynamically bound, so it's
1591 ;; worth the inconvenience.
1592
1593 (cc-bytecomp-defvar c-syntactic-context)
1594 (defvar c-syntactic-context)
1595 (put 'c-syntactic-context 'variable-documentation
1596 "Variable containing the syntactic analysis list for a line of code.
1597
1598 It is a list with one element for each syntactic symbol pertinent to the
1599 line, for example \"((defun-block-intro 1) (comment-intro))\".
1600
1601 It is dynamically bound when calling \(i) a brace hanging \"action
1602 function\"; \(ii) a semicolon/comma hanging \"criteria function\"; \(iii) a
1603 \"line-up function\"; \(iv) a c-special-indent-hook function. It is also
1604 used internally by CC Mode.
1605
1606 c-syntactic-context is always bound dynamically. It must NEVER be set
1607 statically (e.g. with `setq').")
1608
1609
1610 (cc-bytecomp-defvar c-syntactic-element)
1611 (defvar c-syntactic-element)
1612 (put 'c-syntactic-element 'variable-documentation
1613 "Variable containing the current syntactic element during calls to
1614 the lineup functions. The value is one of the elements in the list in
1615 `c-syntactic-context' and is a list with the symbol name in the first
1616 position, followed by zero or more elements containing any additional
1617 info associated with the syntactic symbol. There are accessor functions
1618 `c-langelem-sym', `c-langelem-pos', `c-langelem-col', and
1619 `c-langelem-2nd-pos' to access the list.
1620
1621 Specifically, the element returned by `c-langelem-pos' is the anchor
1622 position, or nil if there isn't any. See the comments in the
1623 `c-offsets-alist' variable and the CC Mode manual for more detailed info
1624 about the data each syntactic symbol provides.
1625
1626 This is always bound dynamically. It should never be set
1627 statically (e.g. with `setq').")
1628
1629 (defvar c-indentation-style nil
1630 "Name of the currently installed style.
1631 Don't change this directly; call `c-set-style' instead, or set the variable
1632 `c-file-style' in the file's Local Variable list.")
1633
1634 (defvar c-current-comment-prefix nil
1635 "The current comment prefix regexp.
1636 Set from `c-comment-prefix-regexp' at mode initialization.")
1637 (make-variable-buffer-local 'c-current-comment-prefix)
1638
1639 ;; N.B. The next three variables are initialized in
1640 ;; c-setup-paragraph-variables. Their initializations here are "just in
1641 ;; case". ACM, 2004/2/15. They are NOT buffer local (yet?).
1642 (defvar c-string-par-start
1643 ;; (concat "\\(" (default-value 'paragraph-start) "\\)\\|[ \t]*\\\\$")
1644 "\f\\|[ \t]*\\\\?$"
1645 "Value of paragraph-start used when scanning strings.
1646 It treats escaped EOLs as whitespace.")
1647
1648 (defvar c-string-par-separate
1649 ;; (concat "\\(" (default-value 'paragraph-separate) "\\)\\|[ \t]*\\\\$")
1650 "[ \t\f]*\\\\?$"
1651 "Value of paragraph-separate used when scanning strings.
1652 It treats escaped EOLs as whitespace.")
1653
1654 (defvar c-sentence-end-with-esc-eol
1655 (concat "\\(\\(" (c-default-value-sentence-end) "\\)"
1656 ;; N.B.: "$" would be illegal when not enclosed like "\\($\\)".
1657 "\\|" "[.?!][]\"')}]* ?\\\\\\($\\)[ \t\n]*"
1658 "\\)")
1659 "Value used like sentence-end used when scanning strings.
1660 It treats escaped EOLs as whitespace.")
1661
1662 \f
1663 (cc-provide 'cc-vars)
1664
1665 ;; arch-tag: d62e9a55-c9fe-409b-b5b6-050b6aa202c9
1666 ;;; cc-vars.el ends here