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