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