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