]> code.delx.au - gnu-emacs/blob - lisp/progmodes/cc-vars.el
b28c0b0f09c1a0f59d08bff6c1d9c499a1a1882e
[gnu-emacs] / lisp / progmodes / cc-vars.el
1 ;;; cc-vars.el --- user customization variables for CC Mode
2
3 ;; Copyright (C) 1985, 1987, 1992-2011
4 ;; Free Software Foundation, Inc.
5
6 ;; Authors: 2002- Alan Mackenzie
7 ;; 1998- Martin Stjernholm
8 ;; 1992-1999 Barry A. Warsaw
9 ;; 1987 Dave Detlefs
10 ;; 1987 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 ;; Keywords: c languages
15 ;; Package: cc-mode
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 "21.1")
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-objc-method-arg-min-delta-to-bracket 2
939 "*Minimum number of chars to the opening bracket.
940
941 Consider this ObjC snippet:
942
943 [foo blahBlah: fred
944 |<-x->|barBaz: barney
945
946 If `x' is less than this number then `c-lineup-ObjC-method-call-colons'
947 will defer the indentation decision to the next function. By default
948 this is `c-lineup-ObjC-method-call', which would align it like:
949
950 [foo blahBlahBlah: fred
951 thisIsTooDamnLong: barney
952
953 This behaviour can be overridden by customizing the indentation of
954 `objc-method-call-cont' in the \"objc\" style."
955 :type 'integer
956 :group 'c)
957
958 (defcustom c-objc-method-arg-unfinished-offset 4
959 "*Offset relative to bracket if first selector is on a new line.
960
961 [aaaaaaaaa
962 |<-x->|bbbbbbb: cccccc
963 ddddd: eeee];"
964 :type 'integer
965 :group 'c)
966
967 (defcustom c-objc-method-parameter-offset 4
968 "*Offset for selector parameter on a new line (relative to first selector.
969
970 [aaaaaaa bbbbbbbbbb:
971 |<-x->|cccccccc
972 ddd: eeee
973 ffff: ggg];"
974 :type 'integer
975 :group 'c)
976
977 (defcustom c-default-style '((java-mode . "java") (awk-mode . "awk")
978 (other . "gnu"))
979 "*Style which gets installed by default when a file is visited.
980
981 The value of this variable can be any style defined in
982 `c-style-alist', including styles you add. The value can also be an
983 association list of major mode symbols to style names.
984
985 When the value is a string, all CC Mode major modes will install this
986 style by default.
987
988 When the value is an alist, the major mode symbol is looked up in it
989 and the associated style is installed. If the major mode is not
990 listed in the alist, then the symbol `other' is looked up in it, and
991 if found, the style in that entry is used. If `other' is not found in
992 the alist, then \"gnu\" style is used.
993
994 The default style gets installed before your mode hooks run, so you
995 can always override the use of `c-default-style' by making calls to
996 `c-set-style' in the appropriate mode hook."
997 :type '(radio
998 (string :tag "Style in all modes")
999 (set :tag "Mode-specific styles"
1000 (cons :format "%v"
1001 (const :format "C " c-mode) (string :format "%v"))
1002 (cons :format "%v"
1003 (const :format "C++ " c++-mode) (string :format "%v"))
1004 (cons :format "%v"
1005 (const :format "ObjC " objc-mode) (string :format "%v"))
1006 (cons :format "%v"
1007 (const :format "Java " java-mode) (string :format "%v"))
1008 (cons :format "%v"
1009 (const :format "IDL " idl-mode) (string :format "%v"))
1010 (cons :format "%v"
1011 (const :format "Pike " pike-mode) (string :format "%v"))
1012 (cons :format "%v"
1013 (const :format "AWK " awk-mode) (string :format "%v"))
1014 (cons :format "%v"
1015 (const :format "Other " other) (string :format "%v"))))
1016 :group 'c)
1017
1018 ;; *) At the start of a statement or declaration means in more detail:
1019 ;; At the closest preceding statement/declaration that starts at boi
1020 ;; and doesn't have a label or comment at that position. If there's
1021 ;; no such statement within the same block, then back up to the
1022 ;; surrounding block or statement, add the appropriate
1023 ;; statement-block-intro, defun-block-intro or substatement syntax
1024 ;; symbol and continue searching.
1025 (c-set-stylevar-fallback 'c-offsets-alist
1026 '((string . c-lineup-dont-change)
1027 ;; Anchor pos: Beg of previous line.
1028 (c . c-lineup-C-comments)
1029 ;; Anchor pos: Beg of the comment.
1030 (defun-open . 0)
1031 ;; Anchor pos: When inside a class: Boi at the func decl start.
1032 ;; When at top level: Bol at the func decl start. When inside
1033 ;; a code block (only possible in Pike): At the func decl
1034 ;; start(*).
1035 (defun-close . 0)
1036 ;; Anchor pos: At the defun block open if it's at boi,
1037 ;; otherwise boi at the func decl start.
1038 (defun-block-intro . +)
1039 ;; Anchor pos: At the block open(*).
1040 (class-open . 0)
1041 ;; Anchor pos: Boi at the class decl start.
1042 (class-close . 0)
1043 ;; Anchor pos: Boi at the class decl start.
1044 (inline-open . +)
1045 ;; Anchor pos: None for functions (inclass got the relpos
1046 ;; then), boi at the lambda start for lambdas.
1047 (inline-close . 0)
1048 ;; Anchor pos: Inexpr functions: At the lambda block open if
1049 ;; it's at boi, else at the statement(*) at boi of the start of
1050 ;; the lambda construct. Otherwise: At the inline block open
1051 ;; if it's at boi, otherwise boi at the func decl start.
1052 (func-decl-cont . +)
1053 ;; Anchor pos: Boi at the func decl start.
1054 (knr-argdecl-intro . +)
1055 ;; Anchor pos: Boi at the topmost intro line.
1056 (knr-argdecl . 0)
1057 ;; Anchor pos: At the beginning of the first K&R argdecl.
1058 (topmost-intro . 0)
1059 ;; Anchor pos: Bol at the last line of previous construct.
1060 (topmost-intro-cont . c-lineup-topmost-intro-cont)
1061 ;;Anchor pos: Bol at the topmost annotation line
1062 (annotation-top-cont . 0)
1063 ;;Anchor pos: Bol at the topmost annotation line
1064 (annotation-var-cont . +)
1065 ;; Anchor pos: Boi at the topmost intro line.
1066 (member-init-intro . +)
1067 ;; Anchor pos: Boi at the func decl arglist open.
1068 (member-init-cont . c-lineup-multi-inher)
1069 ;; Anchor pos: Beg of the first member init.
1070 (inher-intro . +)
1071 ;; Anchor pos: Boi at the class decl start.
1072 (inher-cont . c-lineup-multi-inher)
1073 ;; Anchor pos: Java: At the implements/extends keyword start.
1074 ;; Otherwise: At the inher start colon, or boi at the class
1075 ;; decl start if the first inherit clause hangs and it's not a
1076 ;; func-local inherit clause (when does that occur?).
1077 (block-open . 0)
1078 ;; Anchor pos: Inexpr statement: At the statement(*) at boi of
1079 ;; the start of the inexpr construct. Otherwise: None.
1080 (block-close . 0)
1081 ;; Anchor pos: Inexpr statement: At the inexpr block open if
1082 ;; it's at boi, else at the statement(*) at boi of the start of
1083 ;; the inexpr construct. Block hanging on a case/default
1084 ;; label: At the closest preceding label that starts at boi.
1085 ;; Otherwise: At the block open(*).
1086 (brace-list-open . 0)
1087 ;; Anchor pos: Boi at the brace list decl start, but a starting
1088 ;; "typedef" token is ignored.
1089 (brace-list-close . 0)
1090 ;; Anchor pos: At the brace list decl start(*).
1091 (brace-list-intro . +)
1092 ;; Anchor pos: At the brace list decl start(*).
1093 (brace-list-entry . 0)
1094 ;; Anchor pos: At the first non-ws char after the open paren if
1095 ;; the first token is on the same line, otherwise boi at that
1096 ;; token.
1097 (brace-entry-open . 0)
1098 ;; Anchor pos: Same as brace-list-entry.
1099 (statement . 0)
1100 ;; Anchor pos: After a `;' in the condition clause of a for
1101 ;; statement: At the first token after the starting paren.
1102 ;; Otherwise: At the preceding statement(*).
1103 (statement-cont . +)
1104 ;; Anchor pos: After the first token in the condition clause of
1105 ;; a for statement: At the first token after the starting
1106 ;; paren. Otherwise: At the containing statement(*).
1107 (statement-block-intro . +)
1108 ;; Anchor pos: In inexpr statement block: At the inexpr block
1109 ;; open if it's at boi, else at the statement(*) at boi of the
1110 ;; start of the inexpr construct. In a block hanging on a
1111 ;; case/default label: At the closest preceding label that
1112 ;; starts at boi. Otherwise: At the start of the containing
1113 ;; block(*).
1114 (statement-case-intro . +)
1115 ;; Anchor pos: At the case/default label(*).
1116 (statement-case-open . 0)
1117 ;; Anchor pos: At the case/default label(*).
1118 (substatement . +)
1119 ;; Anchor pos: At the containing statement(*).
1120 (substatement-open . +)
1121 ;; Anchor pos: At the containing statement(*).
1122 (substatement-label . 2)
1123 ;; Anchor pos: At the containing statement(*).
1124 (case-label . 0)
1125 ;; Anchor pos: At the start of the switch block(*).
1126 (access-label . -)
1127 ;; Anchor pos: Same as inclass.
1128 (label . 2)
1129 ;; Anchor pos: At the start of the containing block(*).
1130 (do-while-closure . 0)
1131 ;; Anchor pos: At the corresponding while statement(*).
1132 (else-clause . 0)
1133 ;; Anchor pos: At the corresponding if statement(*).
1134 (catch-clause . 0)
1135 ;; Anchor pos: At the previous try or catch statement clause(*).
1136 (comment-intro . (c-lineup-knr-region-comment c-lineup-comment))
1137 ;; Anchor pos: None.
1138 (arglist-intro . +)
1139 ;; Anchor pos: At the containing statement(*).
1140 ;; 2nd pos: At the open paren.
1141 (arglist-cont . (c-lineup-gcc-asm-reg 0))
1142 ;; Anchor pos: At the first token after the open paren.
1143 (arglist-cont-nonempty . (c-lineup-gcc-asm-reg c-lineup-arglist))
1144 ;; Anchor pos: At the containing statement(*).
1145 ;; 2nd pos: At the open paren.
1146 (arglist-close . +)
1147 ;; Anchor pos: At the containing statement(*).
1148 ;; 2nd pos: At the open paren.
1149 (stream-op . c-lineup-streamop)
1150 ;; Anchor pos: Boi at the first stream op in the statement.
1151 (inclass . +)
1152 ;; Anchor pos: At the class open brace if it's at boi,
1153 ;; otherwise boi at the class decl start.
1154 (cpp-macro . [0])
1155 ;; Anchor pos: None.
1156 (cpp-macro-cont . +)
1157 ;; Anchor pos: At the macro start (always at boi).
1158 (cpp-define-intro . (c-lineup-cpp-define +))
1159 ;; Anchor pos: None.
1160 (friend . 0)
1161 ;; Anchor pos: None.
1162 (objc-method-intro . [0])
1163 ;; Anchor pos: Boi.
1164 (objc-method-args-cont . c-lineup-ObjC-method-args)
1165 ;; Anchor pos: At the method start (always at boi).
1166 (objc-method-call-cont . (c-lineup-ObjC-method-call-colons
1167 c-lineup-ObjC-method-call +))
1168 ;; Anchor pos: At the open bracket.
1169 (extern-lang-open . 0)
1170 (namespace-open . 0)
1171 (module-open . 0)
1172 (composition-open . 0)
1173 ;; Anchor pos: Boi at the extern/namespace/etc keyword.
1174 (extern-lang-close . 0)
1175 (namespace-close . 0)
1176 (module-close . 0)
1177 (composition-close . 0)
1178 ;; Anchor pos: Boi at the corresponding extern/namespace/etc keyword.
1179 (inextern-lang . +)
1180 (innamespace . +)
1181 (inmodule . +)
1182 (incomposition . +)
1183 ;; Anchor pos: At the extern/namespace/etc block open brace if
1184 ;; it's at boi, otherwise boi at the keyword.
1185 (template-args-cont . (c-lineup-template-args +))
1186 ;; Anchor pos: Boi at the decl start. This might be changed;
1187 ;; the logical position is clearly the opening '<'.
1188 (inlambda . c-lineup-inexpr-block)
1189 ;; Anchor pos: None.
1190 (lambda-intro-cont . +)
1191 ;; Anchor pos: Boi at the lambda start.
1192 (inexpr-statement . +)
1193 ;; Anchor pos: None.
1194 (inexpr-class . +)
1195 ;; Anchor pos: None.
1196 ))
1197 (defcustom c-offsets-alist nil
1198 "Association list of syntactic element symbols and indentation offsets.
1199 As described below, each cons cell in this list has the form:
1200
1201 (SYNTACTIC-SYMBOL . OFFSET)
1202
1203 When a line is indented, CC Mode first determines the syntactic
1204 context of it by generating a list of symbols called syntactic
1205 elements. The global variable `c-syntactic-context' is bound to the
1206 that list. Each element in the list is in turn a list where the first
1207 element is a syntactic symbol which tells what kind of construct the
1208 indentation point is located within. More elements in the syntactic
1209 element lists are optional. If there is one more and it isn't nil,
1210 then it's the anchor position for that construct.
1211
1212 After generating the syntactic context for the line, CC Mode
1213 calculates the absolute indentation: First the base indentation is
1214 found by using the anchor position for the first syntactic element
1215 that provides one. If none does, zero is used as base indentation.
1216 Then CC Mode looks at each syntactic element in the context in turn.
1217 It compares the car of the syntactic element against the
1218 SYNTACTIC-SYMBOL's in `c-offsets-alist'. When it finds a match, it
1219 adds OFFSET to the base indentation. The sum of this calculation is
1220 the absolute offset for line being indented.
1221
1222 If the syntactic element does not match any in the `c-offsets-alist',
1223 the element is ignored.
1224
1225 OFFSET can specify an offset in several different ways:
1226
1227 If OFFSET is nil then it's ignored.
1228
1229 If OFFSET is an integer then it's used as relative offset, i.e. it's
1230 added to the base indentation.
1231
1232 If OFFSET is one of the symbols `+', `-', `++', `--', `*', or `/'
1233 then a positive or negative multiple of `c-basic-offset' is added to
1234 the base indentation; 1, -1, 2, -2, 0.5, and -0.5, respectively.
1235
1236 If OFFSET is a symbol with a value binding then that value, which
1237 must be an integer, is used as relative offset.
1238
1239 If OFFSET is a vector then its first element, which must be an
1240 integer, is used as an absolute indentation column. This overrides
1241 the previous base indentation and the relative offsets applied to
1242 it, and it becomes the new base indentation.
1243
1244 If OFFSET is a function or a lambda expression then it's called with
1245 a single argument containing the cons of the syntactic symbol and
1246 the anchor position (or nil if there is none). The return value
1247 from the function is then reinterpreted as an offset specification.
1248
1249 If OFFSET is a list then its elements are evaluated recursively as
1250 offset specifications. If the first element is any of the symbols
1251 below then it isn't evaluated but instead specifies how the
1252 remaining offsets in the list should be combined. If it's something
1253 else then the list is combined according the method `first'. The
1254 valid combination methods are:
1255
1256 `first' -- Use the first offset (that doesn't evaluate to nil).
1257 `min' -- Use the minimum of all the offsets. All must be either
1258 relative or absolute - they can't be mixed.
1259 `max' -- Use the maximum of all the offsets. All must be either
1260 relative or absolute - they can't be mixed.
1261 `add' -- Add all the evaluated offsets together. Exactly one of
1262 them may be absolute, in which case the result is
1263 absolute. Any relative offsets that preceded the
1264 absolute one in the list will be ignored in that case.
1265
1266 `c-offsets-alist' is a style variable. This means that the offsets on
1267 this variable are normally taken from the style system in CC Mode
1268 \(see `c-default-style' and `c-style-alist'). However, any offsets
1269 put explicitly on this list will override the style system when a CC
1270 Mode buffer is initialized \(there is a variable
1271 `c-old-style-variable-behavior' that changes this, though).
1272
1273 Here is the current list of valid syntactic element symbols:
1274
1275 string -- Inside multi-line string.
1276 c -- Inside a multi-line C style block comment.
1277 defun-open -- Brace that opens a function definition.
1278 defun-close -- Brace that closes a function definition.
1279 defun-block-intro -- The first line in a top-level defun.
1280 class-open -- Brace that opens a class definition.
1281 class-close -- Brace that closes a class definition.
1282 inline-open -- Brace that opens an in-class inline method.
1283 inline-close -- Brace that closes an in-class inline method.
1284 func-decl-cont -- The region between a function definition's
1285 argument list and the function opening brace
1286 (excluding K&R argument declarations). In C, you
1287 cannot put anything but whitespace and comments
1288 between them; in C++ and Java, throws declarations
1289 and other things can appear in this context.
1290 knr-argdecl-intro -- First line of a K&R C argument declaration.
1291 knr-argdecl -- Subsequent lines in a K&R C argument declaration.
1292 topmost-intro -- The first line in a topmost construct definition.
1293 topmost-intro-cont -- Topmost definition continuation lines.
1294 annotation-top-cont -- Topmost definition continuation line where only
1295 annotations are on previous lines.
1296 annotation-var-cont -- A continuation of a C (or like) statement where
1297 only annotations are on previous lines.
1298 member-init-intro -- First line in a member initialization list.
1299 member-init-cont -- Subsequent member initialization list lines.
1300 inher-intro -- First line of a multiple inheritance list.
1301 inher-cont -- Subsequent multiple inheritance lines.
1302 block-open -- Statement block open brace.
1303 block-close -- Statement block close brace.
1304 brace-list-open -- Open brace of an enum or static array list.
1305 brace-list-close -- Close brace of an enum or static array list.
1306 brace-list-intro -- First line in an enum or static array list.
1307 brace-list-entry -- Subsequent lines in an enum or static array list.
1308 brace-entry-open -- Subsequent lines in an enum or static array
1309 list that start with an open brace.
1310 statement -- A C (or like) statement.
1311 statement-cont -- A continuation of a C (or like) statement.
1312 statement-block-intro -- The first line in a new statement block.
1313 statement-case-intro -- The first line in a case \"block\".
1314 statement-case-open -- The first line in a case block starting with brace.
1315 substatement -- The first line after an if/while/for/do/else.
1316 substatement-open -- The brace that opens a substatement block.
1317 substatement-label -- Labelled line after an if/while/for/do/else.
1318 case-label -- A \"case\" or \"default\" label.
1319 access-label -- C++ private/protected/public access label.
1320 label -- Any ordinary label.
1321 do-while-closure -- The \"while\" that ends a do/while construct.
1322 else-clause -- The \"else\" of an if/else construct.
1323 catch-clause -- The \"catch\" or \"finally\" of a try/catch construct.
1324 comment-intro -- A line containing only a comment introduction.
1325 arglist-intro -- The first line in an argument list.
1326 arglist-cont -- Subsequent argument list lines when no
1327 arguments follow on the same line as the
1328 arglist opening paren.
1329 arglist-cont-nonempty -- Subsequent argument list lines when at
1330 least one argument follows on the same
1331 line as the arglist opening paren.
1332 arglist-close -- The solo close paren of an argument list.
1333 stream-op -- Lines continuing a stream operator construct.
1334 inclass -- The construct is nested inside a class definition.
1335 Used together with e.g. `topmost-intro'.
1336 cpp-macro -- The start of a C preprocessor macro definition.
1337 cpp-macro-cont -- Inside a multi-line C preprocessor macro definition.
1338 friend -- A C++ friend declaration.
1339 objc-method-intro -- The first line of an Objective-C method definition.
1340 objc-method-args-cont -- Lines continuing an Objective-C method definition.
1341 objc-method-call-cont -- Lines continuing an Objective-C method call.
1342 extern-lang-open -- Brace that opens an \"extern\" block.
1343 extern-lang-close -- Brace that closes an \"extern\" block.
1344 inextern-lang -- Analogous to the `inclass' syntactic symbol,
1345 but used inside \"extern\" blocks.
1346 namespace-open, namespace-close, innamespace
1347 -- Similar to the three `extern-lang' symbols, but for
1348 C++ \"namespace\" blocks.
1349 module-open, module-close, inmodule
1350 -- Similar to the three `extern-lang' symbols, but for
1351 CORBA IDL \"module\" blocks.
1352 composition-open, composition-close, incomposition
1353 -- Similar to the three `extern-lang' symbols, but for
1354 CORBA CIDL \"composition\" blocks.
1355 template-args-cont -- C++ template argument list continuations.
1356 inlambda -- In the header or body of a lambda function.
1357 lambda-intro-cont -- Continuation of the header of a lambda function.
1358 inexpr-statement -- The statement is inside an expression.
1359 inexpr-class -- The class is inside an expression. Used e.g. for
1360 Java anonymous classes."
1361 :type
1362 `(set :format "%{%t%}:
1363 Override style setting
1364 | Syntax Offset
1365 %v"
1366 ,@(mapcar
1367 (lambda (elt)
1368 `(cons :format "%v"
1369 :value ,elt
1370 ,(c-constant-symbol (car elt) 25)
1371 (sexp :format "%v"
1372 :validate
1373 (lambda (widget)
1374 (unless (c-valid-offset (widget-value widget))
1375 (widget-put widget :error "Invalid offset")
1376 widget)))))
1377 (get 'c-offsets-alist 'c-stylevar-fallback)))
1378 :group 'c)
1379
1380 ;; The syntactic symbols that can occur inside code blocks. Used by
1381 ;; `c-gnu-impose-minimum'.
1382 (defconst c-inside-block-syms
1383 '(defun-block-intro block-open block-close statement statement-cont
1384 statement-block-intro statement-case-intro statement-case-open
1385 substatement substatement-open substatement-label case-label label
1386 do-while-closure else-clause catch-clause inlambda annotation-var-cont))
1387
1388 (defcustom c-style-variables-are-local-p t
1389 "*Whether style variables should be buffer local by default.
1390 If non-nil, then all indentation style related variables will be made
1391 buffer local by default. If nil, they will remain global. Variables
1392 are made buffer local when this file is loaded, and once buffer
1393 localized, they cannot be made global again.
1394
1395 This variable must be set appropriately before CC Mode is loaded.
1396
1397 The list of variables to buffer localize are:
1398 c-basic-offset
1399 c-comment-only-line-offset
1400 c-indent-comment-alist
1401 c-indent-comments-syntactically-p
1402 c-block-comment-prefix
1403 c-comment-prefix-regexp
1404 c-doc-comment-style
1405 c-cleanup-list
1406 c-hanging-braces-alist
1407 c-hanging-colons-alist
1408 c-hanging-semi&comma-criteria
1409 c-backslash-column
1410 c-backslash-max-column
1411 c-label-minimum-indentation
1412 c-offsets-alist
1413 c-special-indent-hook
1414 c-indentation-style"
1415 :type 'boolean
1416 :safe 'booleanp
1417 :group 'c)
1418
1419 (defcustom c-mode-hook nil
1420 "*Hook called by `c-mode'."
1421 :type 'hook
1422 :group 'c)
1423
1424 (defcustom c++-mode-hook nil
1425 "*Hook called by `c++-mode'."
1426 :type 'hook
1427 :group 'c)
1428
1429 (defcustom objc-mode-hook nil
1430 "*Hook called by `objc-mode'."
1431 :type 'hook
1432 :group 'c)
1433
1434 (defcustom java-mode-hook nil
1435 "*Hook called by `java-mode'."
1436 :type 'hook
1437 :group 'c)
1438
1439 (defcustom idl-mode-hook nil
1440 "*Hook called by `idl-mode'."
1441 :type 'hook
1442 :group 'c)
1443
1444 (defcustom pike-mode-hook nil
1445 "*Hook called by `pike-mode'."
1446 :type 'hook
1447 :group 'c)
1448
1449 (defcustom awk-mode-hook nil
1450 "*Hook called by `awk-mode'."
1451 :type 'hook
1452 :group 'c)
1453
1454 (defcustom c-mode-common-hook nil
1455 "*Hook called by all CC Mode modes for common initializations."
1456 :type 'hook
1457 :group 'c)
1458
1459 (defcustom c-initialization-hook nil
1460 "*Hook called when the CC Mode package gets initialized.
1461 This hook is only run once per Emacs session and can be used as a
1462 `load-hook' or in place of using `eval-after-load'."
1463 :type 'hook
1464 :group 'c)
1465
1466 (defcustom c-enable-xemacs-performance-kludge-p nil
1467 "*Enables a XEmacs only hack that may improve speed for some coding styles.
1468 For styles that hang top-level opening braces (as is common with JDK
1469 Java coding styles) this can improve performance between 3 and 60
1470 times for core indentation functions (e.g. `c-parse-state'). For
1471 styles that conform to the Emacs recommendation of putting these
1472 braces in column zero, this can degrade performance about as much.
1473 This variable only has effect in XEmacs."
1474 :type 'boolean
1475 :group 'c)
1476
1477 (defvar c-old-style-variable-behavior nil
1478 "*Enables the old style variable behavior when non-nil.
1479
1480 Normally the values of the style variables will override the style
1481 settings specified by the variables `c-default-style' and
1482 `c-style-alist'. However, in CC Mode 5.25 and earlier, it was the
1483 other way around, meaning that changes made to the style variables
1484 from e.g. Customize would not take effect unless special precautions
1485 were taken. That was confusing, especially for novice users.
1486
1487 It's believed that despite this change, the new behavior will still
1488 produce the same results for most old CC Mode configurations, since
1489 all style variables are per default set in a special non-override
1490 state. Set this variable only if your configuration has stopped
1491 working due to this change.")
1492
1493 (define-widget 'c-extra-types-widget 'radio
1494 "Internal CC Mode widget for the `*-font-lock-extra-types' variables."
1495 :args '((const :tag "none" nil)
1496 (repeat :tag "types" regexp)))
1497
1498 (defun c-make-font-lock-extra-types-blurb (mode1 mode2 example)
1499 (concat "\
1500 *List of extra types (aside from the type keywords) to recognize in "
1501 mode1 " mode.
1502 Each list item should be a regexp matching a single identifier.
1503 " example "
1504
1505 Note that items on this list that don't include any regexp special
1506 characters are automatically optimized using `regexp-opt', so you
1507 should not use `regexp-opt' explicitly to build regexps here.
1508
1509 On decoration level 3 (and higher, where applicable), a method is used
1510 that finds most types and declarations by syntax alone. This variable
1511 is still used as a first step, but other types are recognized
1512 correctly anyway in most cases. Therefore this variable should be
1513 fairly restrictive and not contain patterns that are uncertain.
1514
1515 Note that this variable is only consulted when the major mode is
1516 initialized. If you change it later you have to reinitialize CC Mode
1517 by doing \\[" mode2 "].
1518
1519 Despite the name, this variable is not only used for font locking but
1520 also elsewhere in CC Mode to tell types from other identifiers."))
1521
1522 ;; Note: Most of the variables below are also defined in font-lock.el
1523 ;; in older versions of Emacs, so depending on the load order we might
1524 ;; not install the values below. There's no kludge to cope with this
1525 ;; (as opposed to the *-font-lock-keywords-* variables) since the old
1526 ;; values work fairly well anyway.
1527
1528 (defcustom c-font-lock-extra-types
1529 '("\\sw+_t"
1530 ;; Defined in C99:
1531 "bool" "complex" "imaginary"
1532 ;; Standard library types (except those matched by the _t pattern):
1533 "FILE" "lconv" "tm" "va_list" "jmp_buf"
1534 ;; I do not appreciate the following very Emacs-specific luggage
1535 ;; in the default value, but otoh it can hardly get in the way for
1536 ;; other users, and removing it would cause unnecessary grief for
1537 ;; the old timers that are used to it. /mast
1538 "Lisp_Object")
1539 (c-make-font-lock-extra-types-blurb "C" "c-mode"
1540 "For example, a value of (\"FILE\" \"\\\\sw+_t\") means the word \"FILE\"
1541 and words ending in \"_t\" are treated as type names.")
1542 :type 'c-extra-types-widget
1543 :group 'c)
1544
1545 (defcustom c++-font-lock-extra-types
1546 '("\\sw+_t"
1547 ;; C library types (except those matched by the _t pattern):
1548 "FILE" "lconv" "tm" "va_list" "jmp_buf"
1549 ;; Some standard C++ types that came from font-lock.el.
1550 ;; Experienced C++ users says there's no clear benefit in
1551 ;; extending this to all the types in the standard library, at
1552 ;; least not when they'll be recognized without "std::" too.
1553 "istream" "istreambuf"
1554 "ostream" "ostreambuf"
1555 "ifstream" "ofstream" "fstream"
1556 "strstream" "strstreambuf" "istrstream" "ostrstream"
1557 "ios"
1558 "string" "rope"
1559 "list" "slist"
1560 "deque" "vector" "bit_vector"
1561 "set" "multiset"
1562 "map" "multimap"
1563 "hash"
1564 "hash_set" "hash_multiset"
1565 "hash_map" "hash_multimap"
1566 "stack" "queue" "priority_queue"
1567 "type_info"
1568 "iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator"
1569 "reference" "const_reference")
1570 (c-make-font-lock-extra-types-blurb "C++" "c++-mode"
1571 "For example, a value of (\"string\") means the word \"string\" is treated
1572 as a type name.")
1573 :type 'c-extra-types-widget
1574 :group 'c)
1575
1576 (defcustom objc-font-lock-extra-types
1577 (list (concat "[" c-upper "]\\sw*[" c-lower "]\\sw*"))
1578 (c-make-font-lock-extra-types-blurb "ObjC" "objc-mode" (concat
1579 "For example, a value of (\"[" c-upper "]\\\\sw*[" c-lower "]\\\\sw*\") means
1580 capitalized words are treated as type names (the requirement for a
1581 lower case char is to avoid recognizing all-caps macro and constant
1582 names)."))
1583 :type 'c-extra-types-widget
1584 :group 'c)
1585
1586 (defcustom java-font-lock-extra-types
1587 (list (concat "[" c-upper "]\\sw*[" c-lower "]\\sw"))
1588 (c-make-font-lock-extra-types-blurb "Java" "java-mode" (concat
1589 "For example, a value of (\"[" c-upper "]\\\\sw*[" c-lower "]\\\\sw*\") means
1590 capitalized words are treated as type names (the requirement for a
1591 lower case char is to avoid recognizing all-caps constant names)."))
1592 :type 'c-extra-types-widget
1593 :group 'c)
1594
1595 (defcustom idl-font-lock-extra-types nil
1596 (c-make-font-lock-extra-types-blurb "IDL" "idl-mode" "")
1597 :type 'c-extra-types-widget
1598 :group 'c)
1599
1600 (defcustom pike-font-lock-extra-types
1601 (list (concat "[" c-upper "]\\sw*[" c-lower "]\\sw*"))
1602 (c-make-font-lock-extra-types-blurb "Pike" "pike-mode" (concat
1603 "For example, a value of (\"[" c-upper "]\\\\sw*[" c-lower "]\\\\sw*\") means
1604 capitalized words are treated as type names (the requirement for a
1605 lower case char is to avoid recognizing all-caps macro and constant
1606 names)."))
1607 :type 'c-extra-types-widget
1608 :group 'c)
1609
1610 \f
1611 ;; Non-customizable variables, still part of the interface to CC Mode
1612 (defvar c-file-style nil
1613 "Variable interface for setting style via File Local Variables.
1614 In a file's Local Variable section, you can set this variable to a
1615 string suitable for `c-set-style'. When the file is visited, CC Mode
1616 will set the style of the file to this value automatically.
1617
1618 Note that file style settings are applied before file offset settings
1619 as designated in the variable `c-file-offsets'.")
1620 (make-variable-buffer-local 'c-file-style)
1621 ;;;###autoload(put 'c-file-style 'safe-local-variable 'string-or-null-p)
1622
1623 (defvar c-file-offsets nil
1624 "Variable interface for setting offsets via File Local Variables.
1625 In a file's Local Variable section, you can set this variable to an
1626 association list similar to the values allowed in `c-offsets-alist'.
1627 When the file is visited, CC Mode will institute these offset settings
1628 automatically.
1629
1630 Note that file offset settings are applied after file style settings
1631 as designated in the variable `c-file-style'.")
1632 (make-variable-buffer-local 'c-file-offsets)
1633
1634 ;; It isn't possible to specify a doc-string without specifying an
1635 ;; initial value with `defvar', so the following two variables have been
1636 ;; given doc-strings by setting the property `variable-documentation'
1637 ;; directly. C-h v will read this documentation only for versions of GNU
1638 ;; Emacs from 22.1. It's really good not to have an initial value for
1639 ;; variables like these that always should be dynamically bound, so it's
1640 ;; worth the inconvenience.
1641
1642 (cc-bytecomp-defvar c-syntactic-context)
1643 (defvar c-syntactic-context)
1644 (put 'c-syntactic-context 'variable-documentation
1645 "Variable containing the syntactic analysis list for a line of code.
1646
1647 It is a list with one element for each syntactic symbol pertinent to the
1648 line, for example \"((defun-block-intro 1) (comment-intro))\".
1649
1650 It is dynamically bound when calling \(i) a brace hanging \"action
1651 function\"; \(ii) a semicolon/comma hanging \"criteria function\"; \(iii) a
1652 \"line-up function\"; \(iv) a c-special-indent-hook function. It is also
1653 used internally by CC Mode.
1654
1655 c-syntactic-context is always bound dynamically. It must NEVER be set
1656 statically (e.g. with `setq').")
1657
1658
1659 (cc-bytecomp-defvar c-syntactic-element)
1660 (defvar c-syntactic-element)
1661 (put 'c-syntactic-element 'variable-documentation
1662 "Variable containing the current syntactic element during calls to
1663 the lineup functions. The value is one of the elements in the list in
1664 `c-syntactic-context' and is a list with the symbol name in the first
1665 position, followed by zero or more elements containing any additional
1666 info associated with the syntactic symbol. There are accessor functions
1667 `c-langelem-sym', `c-langelem-pos', `c-langelem-col', and
1668 `c-langelem-2nd-pos' to access the list.
1669
1670 Specifically, the element returned by `c-langelem-pos' is the anchor
1671 position, or nil if there isn't any. See the comments in the
1672 `c-offsets-alist' variable and the CC Mode manual for more detailed info
1673 about the data each syntactic symbol provides.
1674
1675 This is always bound dynamically. It should never be set
1676 statically (e.g. with `setq').")
1677
1678 (defvar c-indentation-style nil
1679 "Name of the currently installed style.
1680 Don't change this directly; call `c-set-style' instead, or set the variable
1681 `c-file-style' in the file's Local Variable list.")
1682
1683 (defvar c-current-comment-prefix nil
1684 "The current comment prefix regexp.
1685 Set from `c-comment-prefix-regexp' at mode initialization.")
1686 (make-variable-buffer-local 'c-current-comment-prefix)
1687
1688 ;; N.B. The next three variables are initialized in
1689 ;; c-setup-paragraph-variables. Their initializations here are "just in
1690 ;; case". ACM, 2004/2/15. They are NOT buffer local (yet?).
1691 (defvar c-string-par-start
1692 ;; (concat "\\(" (default-value 'paragraph-start) "\\)\\|[ \t]*\\\\$")
1693 "\f\\|[ \t]*\\\\?$"
1694 "Value of paragraph-start used when scanning strings.
1695 It treats escaped EOLs as whitespace.")
1696
1697 (defvar c-string-par-separate
1698 ;; (concat "\\(" (default-value 'paragraph-separate) "\\)\\|[ \t]*\\\\$")
1699 "[ \t\f]*\\\\?$"
1700 "Value of paragraph-separate used when scanning strings.
1701 It treats escaped EOLs as whitespace.")
1702
1703 (defvar c-sentence-end-with-esc-eol
1704 (concat "\\(\\(" (c-default-value-sentence-end) "\\)"
1705 ;; N.B.: "$" would be illegal when not enclosed like "\\($\\)".
1706 "\\|" "[.?!][]\"')}]* ?\\\\\\($\\)[ \t\n]*"
1707 "\\)")
1708 "Value used like sentence-end used when scanning strings.
1709 It treats escaped EOLs as whitespace.")
1710
1711 \f
1712 (cc-provide 'cc-vars)
1713
1714 ;;; cc-vars.el ends here