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