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