comparison lisp/progmodes/cc-vars.el @ 44728:7a3ac6c387fe

CC Mode update to version 5.29. This is for testing; it's not a released version.
author Martin Stjernholm <mast@lysator.liu.se>
date Mon, 22 Apr 2002 00:35:36 +0000
parents 85a7b7660c2d
children 830d1dc661e0
comparison
equal deleted inserted replaced
44727:3936c522b4d3 44728:7a3ac6c387fe
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details. 25 ;; GNU General Public License for more details.
26 26
27 ;; You should have received a copy of the GNU General Public License 27 ;; You should have received a copy of the GNU General Public License
28 ;; along with this program; see the file COPYING. If not, write to 28 ;; along with GNU Emacs; see the file COPYING. If not, write to
29 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 29 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30 ;; Boston, MA 02111-1307, USA. 30 ;; Boston, MA 02111-1307, USA.
31 31
32 ;;; Commentary: 32 ;;; Commentary:
33 33
64 (message "Warning: Compiling without Customize support \ 64 (message "Warning: Compiling without Customize support \
65 since a (good enough) custom library wasn't found") 65 since a (good enough) custom library wasn't found")
66 (cc-bytecomp-defmacro define-widget (name class doc &rest args)) 66 (cc-bytecomp-defmacro define-widget (name class doc &rest args))
67 (cc-bytecomp-defmacro defcustom (symbol value doc &rest args) 67 (cc-bytecomp-defmacro defcustom (symbol value doc &rest args)
68 `(defvar ,symbol ,value ,doc)) 68 `(defvar ,symbol ,value ,doc))
69 (cc-bytecomp-defmacro custom-declare-variable (symbol value doc
70 &rest args)
71 `(defvar ,(eval symbol) ,(eval value) ,doc))
69 nil)))) 72 nil))))
73
74 (cc-eval-when-compile
75 ;; Need the function form of `backquote', which isn't standardized
76 ;; between Emacsen. It's called `bq-process' in XEmacs, and
77 ;; `backquote-process' in Emacs. `backquote-process' returns a
78 ;; slightly more convoluted form, so let `bq-process' be the norm.
79 (if (fboundp 'backquote-process)
80 (cc-bytecomp-defmacro bq-process (form)
81 `(cdr (backquote-process ,form)))))
70 82
71 83
72 ;;; Helpers 84 ;;; Helpers
73 85
74 ;; This widget will show up in newer versions of the Custom library 86 ;; This widget will show up in newer versions of the Custom library
101 (intern (progn 113 (intern (progn
102 (string-match "\\`[^ ]*" value) 114 (string-match "\\`[^ ]*" value)
103 (match-string 0 value))) 115 (match-string 0 value)))
104 value))) 116 value)))
105 117
118 (define-widget 'c-integer-or-nil 'sexp
119 "An integer or the value nil."
120 :value nil
121 :tag "Optional integer"
122 :match (lambda (widget value) (or (integerp value) (null value))))
123
106 (defvar c-style-variables 124 (defvar c-style-variables
107 '(c-basic-offset c-comment-only-line-offset c-block-comment-prefix 125 '(c-basic-offset c-comment-only-line-offset c-indent-comment-alist
126 c-indent-comments-syntactically-p c-block-comment-prefix
108 c-comment-prefix-regexp c-cleanup-list c-hanging-braces-alist 127 c-comment-prefix-regexp c-cleanup-list c-hanging-braces-alist
109 c-hanging-colons-alist c-hanging-semi&comma-criteria c-backslash-column 128 c-hanging-colons-alist c-hanging-semi&comma-criteria c-backslash-column
110 c-special-indent-hook c-label-minimum-indentation c-offsets-alist) 129 c-backslash-max-column c-special-indent-hook c-label-minimum-indentation
130 c-offsets-alist)
111 "List of the style variables.") 131 "List of the style variables.")
132
133 (defvar c-fallback-style nil)
134
135 (defsubst c-set-stylevar-fallback (name val)
136 (put name 'c-stylevar-fallback val)
137 (setq c-fallback-style (cons (cons name val) c-fallback-style)))
112 138
113 (defmacro defcustom-c-stylevar (name val doc &rest args) 139 (defmacro defcustom-c-stylevar (name val doc &rest args)
114 "Defines a style variable." 140 "Defines a style variable."
115 `(progn 141 `(let ((-value- ,val))
116 (put ',name 'c-stylevar-fallback ,val) 142 (c-set-stylevar-fallback ',name -value-)
117 (defcustom ,name 'set-from-style 143 (custom-declare-variable
118 ,(concat doc " 144 ',name ''set-from-style
145 ,(concat doc "
119 146
120 This is a style variable. Apart from the valid values described 147 This is a style variable. Apart from the valid values described
121 above, it can be set to the symbol `set-from-style'. In that case, it 148 above, it can be set to the symbol `set-from-style'. In that case, it
122 takes its value from the style system (see `c-default-style' and 149 takes its value from the style system (see `c-default-style' and
123 `c-styles-alist') when a CC Mode buffer is initialized. Otherwise, 150 `c-style-alist') when a CC Mode buffer is initialized. Otherwise,
124 the value set here overrides the style system (there is a variable 151 the value set here overrides the style system (there is a variable
125 `c-old-style-variable-behavior' that changes this, though).") 152 `c-old-style-variable-behavior' that changes this, though).")
126 ,@(plist-put 153 ,@(plist-put
127 args ':type 154 args ':type
128 `'(radio 155 `(` (radio
129 (const :tag "Use style settings" 156 (const :tag "Use style settings"
130 set-from-style) 157 set-from-style)
131 ,(let ((type (eval (plist-get args ':type)))) 158 ,(, (let ((type (eval (plist-get args ':type))))
132 (unless (consp type) 159 (unless (consp type)
133 (setq type (list type))) 160 (setq type (list type)))
134 (unless (c-safe (plist-get (cdr type) ':value)) 161 (unless (c-safe (plist-get (cdr type) ':value))
135 (setcdr type (append `(:value ,val) 162 (setcdr type (append '(:value (, -value-))
136 (cdr type)))) 163 (cdr type))))
137 (unless (c-safe (plist-get (cdr type) ':tag)) 164 (unless (c-safe (plist-get (cdr type) ':tag))
138 (setcdr type (append '(:tag "Override style settings") 165 (setcdr type (append '(:tag "Override style settings")
139 (cdr type)))) 166 (cdr type))))
140 type)))))) 167 (bq-process type)))))))))
141 168
142 (defun c-valid-offset (offset) 169 (defun c-valid-offset (offset)
143 "Return non-nil iff OFFSET is a valid offset for a syntactic symbol. 170 "Return non-nil iff OFFSET is a valid offset for a syntactic symbol.
144 See `c-offsets-alist'." 171 See `c-offsets-alist'."
145 (or (eq offset '+) 172 (or (eq offset '+)
147 (eq offset '++) 174 (eq offset '++)
148 (eq offset '--) 175 (eq offset '--)
149 (eq offset '*) 176 (eq offset '*)
150 (eq offset '/) 177 (eq offset '/)
151 (integerp offset) 178 (integerp offset)
152 (vectorp offset)
153 (functionp offset) 179 (functionp offset)
154 (and (symbolp offset) 180 (and (symbolp offset)
155 (or (boundp offset) 181 (or (boundp offset)
156 (fboundp offset))) 182 (fboundp offset)))
183 (and (vectorp offset)
184 (= (length offset) 1)
185 (integerp (elt offset 0)))
157 (progn 186 (progn
158 (while (and (consp offset) 187 (while (and (consp offset)
159 (c-valid-offset (car offset))) 188 (c-valid-offset (car offset)))
160 (setq offset (cdr offset))) 189 (setq offset (cdr offset)))
161 (null offset)))) 190 (null offset))))
177 :type 'boolean 206 :type 'boolean
178 :group 'c) 207 :group 'c)
179 208
180 (defcustom c-echo-syntactic-information-p nil 209 (defcustom c-echo-syntactic-information-p nil
181 "*If non-nil, syntactic info is echoed when the line is indented." 210 "*If non-nil, syntactic info is echoed when the line is indented."
211 :type 'boolean
212 :group 'c)
213
214 (defcustom c-report-syntactic-errors nil
215 "*If non-nil, certain syntactic errors are reported with a ding
216 and a message, for example when an \"else\" is indented for which
217 there's no corresponding \"if\".
218
219 Note however that CC Mode doesn't make any special effort to check for
220 syntactic errors; that's the job of the compiler. The reason it can
221 report cases like the one above is that it can't find the correct
222 anchoring position to indent the line in that case."
182 :type 'boolean 223 :type 'boolean
183 :group 'c) 224 :group 'c)
184 225
185 (defcustom-c-stylevar c-basic-offset 4 226 (defcustom-c-stylevar c-basic-offset 4
186 "*Amount of basic offset used by + and - symbols in `c-offsets-alist'. 227 "*Amount of basic offset used by + and - symbols in `c-offsets-alist'.
204 `c-insert-tab-function' is called. 245 `c-insert-tab-function' is called.
205 246
206 Note: indentation of lines containing only comments is also controlled 247 Note: indentation of lines containing only comments is also controlled
207 by the `c-comment-only-line-offset' variable." 248 by the `c-comment-only-line-offset' variable."
208 :type '(radio 249 :type '(radio
209 :extra-offset 8 250 (const :tag "TAB key always indents, never inserts TAB" t)
210 :format "%{C Tab Always Indent%}:\n The TAB key:\n%v" 251 (const :tag "TAB key indents in left margin, otherwise inserts TAB" nil)
211 (const :tag "always indents, never inserts TAB" t) 252 (other :tag "TAB key inserts TAB in literals, otherwise indents" other))
212 (const :tag "indents in left margin, otherwise inserts TAB" nil)
213 (other :tag "inserts TAB in literals, otherwise indent" other))
214 :group 'c) 253 :group 'c)
215 254
216 (defcustom c-insert-tab-function 'insert-tab 255 (defcustom c-insert-tab-function 'insert-tab
217 "*Function used when inserting a tab for \\[c-indent-command]. 256 "*Function used when inserting a tab for \\[c-indent-command].
218 Only used when `c-tab-always-indent' indicates a `real' tab character 257 Only used when `c-tab-always-indent' indicates a `real' tab character
221 :group 'c) 260 :group 'c)
222 261
223 (defcustom c-syntactic-indentation t 262 (defcustom c-syntactic-indentation t
224 "*Whether the indentation should be controlled by the syntactic context. 263 "*Whether the indentation should be controlled by the syntactic context.
225 264
226 If t, the indentation functions indents according to the syntactic 265 If t, the indentation functions indent according to the syntactic
227 context, using the style settings specified by `c-offsets-alist'. 266 context, using the style settings specified by `c-offsets-alist'.
228 267
229 If nil, every line is just indented to the same level as the previous 268 If nil, every line is just indented to the same level as the previous
230 one, and the \\[c-indent-command] command adjusts the indentation in steps 269 one, and the \\[c-indent-command] command adjusts the indentation in
231 specified by `c-basic-offset'. The indentation style have no effect 270 steps specified by `c-basic-offset'. The indentation style has no
232 in this mode, nor any of the indentation associated variables, 271 effect in this mode, nor any of the indentation associated variables,
233 e.g. `c-special-indent-hook'." 272 e.g. `c-special-indent-hook'."
273 :type 'boolean
274 :group 'c)
275
276 (defcustom c-syntactic-indentation-in-macros t
277 "*Enable syntactic analysis inside macros.
278 If this is nil, all lines inside macro definitions are analyzed as
279 `cpp-macro-cont'. Otherwise they are analyzed syntactically, just
280 like normal code, and `cpp-define-intro' is used to create the
281 additional indentation of the bodies of \"#define\" macros.
282
283 Having this enabled simplifies editing of large multiline macros, but
284 it might complicate editing if CC Mode doesn't recognize the context
285 of the macro content. The default context inside the macro is the
286 same as the top level, so if it contains \"bare\" statements they
287 might be indented wrongly, although there are special cases that
288 handles this in most cases. If this problem occurs, it's usually
289 countered easily by surrounding the statements by a block \(or even
290 better with the \"do { ... } while \(0)\" trick)."
234 :type 'boolean 291 :type 'boolean
235 :group 'c) 292 :group 'c)
236 293
237 (defcustom-c-stylevar c-comment-only-line-offset 0 294 (defcustom-c-stylevar c-comment-only-line-offset 0
238 "*Extra offset for line which contains only the start of a comment. 295 "*Extra offset for line which contains only the start of a comment.
249 lineup function is used on the `comment-intro' syntactic symbol (the 306 lineup function is used on the `comment-intro' syntactic symbol (the
250 default)." 307 default)."
251 :type '(choice (integer :tag "Non-anchored offset" 0) 308 :type '(choice (integer :tag "Non-anchored offset" 0)
252 (cons :tag "Non-anchored & anchored offset" 309 (cons :tag "Non-anchored & anchored offset"
253 :value (0 . 0) 310 :value (0 . 0)
254 :extra-offset 8
255 (integer :tag "Non-anchored offset") 311 (integer :tag "Non-anchored offset")
256 (integer :tag "Anchored offset"))) 312 (integer :tag "Anchored offset")))
257 :group 'c) 313 :group 'c)
258 314
259 (defcustom c-indent-comments-syntactically-p nil 315 (defcustom-c-stylevar c-indent-comment-alist
316 '((anchored-comment . (column . 0))
317 (end-block . (space . 1))
318 (cpp-end-block . (space . 2)))
319 "*Specifies how \\[indent-for-comment] calculates the comment start column.
320 This is an association list that contains entries of the form:
321
322 (LINE-TYPE . INDENT-SPEC)
323
324 LINE-TYPE specifies a type of line as described below, and INDENT-SPEC
325 says what \\[indent-for-comment] should do when used on that type of line.
326
327 The recognized values for LINE-TYPE are:
328
329 empty-line -- The line is empty.
330 anchored-comment -- The line contains a comment that starts in column 0.
331 end-block -- The line contains a solitary block closing brace.
332 cpp-end-block -- The line contains a preprocessor directive that
333 closes a block, i.e. either \"#endif\" or \"#else\".
334 other -- The line does not match any other entry
335 currently on the list.
336
337 An INDENT-SPEC is a cons cell of the form:
338
339 (ACTION . VALUE)
340
341 ACTION says how \\[indent-for-comment] should align the comment, and
342 VALUE is interpreted depending on ACTION. ACTION can be any of the
343 following:
344
345 space -- Put VALUE spaces between the end of the line and the start
346 of the comment.
347 column -- Start the comment at the column VALUE. If the line is
348 longer than that, the comment is preceded by a single
349 space. If VALUE is nil, `comment-column' is used.
350 align -- Align the comment with one on the previous line, if there
351 is any. If the line is too long, the comment is preceded
352 by a single space. If there isn't a comment start on the
353 previous line, the behavior is specified by VALUE, which
354 in turn is interpreted as an INDENT-SPEC.
355
356 If a LINE-TYPE is missing, then \\[indent-for-comment] indents the comment
357 according to `comment-column'.
358
359 Note that a non-nil value on `c-indent-comments-syntactically-p'
360 overrides this variable, so empty lines are indentented syntactically
361 in that case, i.e. as if \\[c-indent-command] was used instead."
362 :type
363 (let ((space '(cons :tag "space"
364 :format "%v"
365 :value (space . 1)
366 (const :format "space " space)
367 (integer :format "%v")))
368 (column '(cons :tag "column"
369 :format "%v"
370 (const :format "column " column)
371 (c-integer-or-nil :format "%v"))))
372 `(set ,@(mapcar
373 (lambda (elt)
374 `(cons :format "%v"
375 (c-const-symbol :format "%v: "
376 :size 20
377 :value ,elt)
378 (choice
379 :format "%[Choice%] %v"
380 :value (column . nil)
381 ,space
382 ,column
383 (cons :tag "align"
384 :format "%v"
385 (const :format "align " align)
386 (choice
387 :format "%[Choice%] %v"
388 :value (column . nil)
389 ,space
390 ,column)))))
391 '(empty-line anchored-comment end-block cpp-end-block other))))
392 :group 'c)
393
394 (defcustom-c-stylevar c-indent-comments-syntactically-p nil
260 "*Specifies how \\[indent-for-comment] should handle comment-only lines. 395 "*Specifies how \\[indent-for-comment] should handle comment-only lines.
261 When this variable is non-nil, comment-only lines are indented 396 When this variable is non-nil, comment-only lines are indented
262 according to syntactic analysis via `c-offsets-alist'. Otherwise, the 397 according to syntactic analysis via `c-offsets-alist'. Otherwise, the
263 comment is indented as if it was preceded by code. Note that this 398 comment is indented as if it was preceded by code. Note that this
264 variable does not affect how the normal line indentation treats 399 variable does not affect how the normal line indentation treats
289 424
290 It's only used when a one-line block comment is broken into two or 425 It's only used when a one-line block comment is broken into two or
291 more lines for the first time; otherwise the appropriate prefix is 426 more lines for the first time; otherwise the appropriate prefix is
292 adapted from the comment. This variable is not used for C++ line 427 adapted from the comment. This variable is not used for C++ line
293 style comments." 428 style comments."
294 ;; We need to specify a :value to prevent `defcustom-c-stylevar' from 429 :type 'string
295 ;; giving it an invalid value. Perhaps `defcustom-c-stylevar'
296 ;; should evaluate the value first?
297 ;; Per Abrahamsen <abraham@dina.kvl.dk> 2002-04-06.
298 :type '(string :value "* ")
299 :group 'c) 430 :group 'c)
300 431
301 (defcustom-c-stylevar c-comment-prefix-regexp 432 (defcustom-c-stylevar c-comment-prefix-regexp
302 '((pike-mode . "//+!?\\|\\**") 433 '((pike-mode . "//+!?\\|\\**")
303 (other . "//+\\|\\**")) 434 (other . "//+\\|\\**"))
317 block comment starter. In other words, it should at least match 448 block comment starter. In other words, it should at least match
318 \"//\" for line comments and the string in `c-block-comment-prefix', 449 \"//\" for line comments and the string in `c-block-comment-prefix',
319 which is sometimes inserted by CC Mode inside block comments. It 450 which is sometimes inserted by CC Mode inside block comments. It
320 should not match any surrounding whitespace. 451 should not match any surrounding whitespace.
321 452
322 Note that CC Mode modifies other variables from this one at mode 453 Note that CC Mode uses this variable to set many other variables that
323 initialization, so you will need to do \\[c-mode] (or whatever mode 454 handles the paragraph filling. That's done at mode initialization or
324 you're currently using) if you change it in a CC Mode buffer." 455 when you switch to a style which sets this variable. Thus, if you
456 change it in some other way, e.g. interactively in a CC Mode buffer,
457 you will need to do \\[c-mode] (or whatever mode you're currently
458 using) to reinitialize.
459
460 Note also that when CC Mode starts up, the other variables are
461 modified before the mode hooks are run. If you change this variable
462 in a mode hook, you can call `c-setup-paragraph-variables' afterwards
463 to redo it."
325 :type '(radio 464 :type '(radio
326 (regexp :tag "Regexp for all modes") 465 (regexp :tag "Regexp for all modes")
327 (list 466 (list
328 :tag "Mode-specific regexps" 467 :tag "Mode-specific regexps"
329 (set 468 (set
355 c -- inside a C style block comment 494 c -- inside a C style block comment
356 c++ -- inside a C++ style line comment 495 c++ -- inside a C++ style line comment
357 cpp -- inside a preprocessor directive 496 cpp -- inside a preprocessor directive
358 code -- anywhere else, i.e. in normal code" 497 code -- anywhere else, i.e. in normal code"
359 :type '(set 498 :type '(set
360 :extra-offset 8
361 (const :tag "String literals" string) 499 (const :tag "String literals" string)
362 (const :tag "C style block comments" c) 500 (const :tag "C style block comments" c)
363 (const :tag "C++ style line comments" c++) 501 (const :tag "C++ style line comments" c++)
364 (const :tag "Preprocessor directives" cpp) 502 (const :tag "Preprocessor directives" cpp)
365 (const :tag "Normal code" code)) 503 (const :tag "Normal code" code))
414 useful together with `space-before-funcall' to 552 useful together with `space-before-funcall' to
415 get the style \"foo (bar)\" and \"foo()\". 553 get the style \"foo (bar)\" and \"foo()\".
416 Clean up occurs when the closing parenthesis 554 Clean up occurs when the closing parenthesis
417 is typed." 555 is typed."
418 :type '(set 556 :type '(set
419 :extra-offset 8
420 (const :tag "Put \"} else {\" on one line" 557 (const :tag "Put \"} else {\" on one line"
421 brace-else-brace) 558 brace-else-brace)
422 (const :tag "Put \"} else if (...) {\" on one line" 559 (const :tag "Put \"} else if (...) {\" on one line"
423 brace-elseif-brace) 560 brace-elseif-brace)
424 (const :tag "Put \"} catch (...) {\" on one line" 561 (const :tag "Put \"} catch (...) {\" on one line"
482 `(cons :format "%v" 619 `(cons :format "%v"
483 (c-const-symbol :format "%v: " 620 (c-const-symbol :format "%v: "
484 :size 20 621 :size 20
485 :value ,elt) 622 :value ,elt)
486 (choice :format "%[Choice%] %v" 623 (choice :format "%[Choice%] %v"
487 :value (before after) 624 :value (before after)
488 (set :menu-tag "Before/after" 625 (set :menu-tag "Before/after"
489 :format "Newline %v brace\n" 626 :format "Newline %v brace\n"
490 (const :format "%v, " before) 627 (const :format "%v, " before)
491 (const :format "%v" after)) 628 (const :format "%v" after))
492 (function :menu-tag "Function" 629 (function :menu-tag "Function"
545 then no newline is inserted." 682 then no newline is inserted."
546 :type '(repeat function) 683 :type '(repeat function)
547 :group 'c) 684 :group 'c)
548 685
549 (defcustom-c-stylevar c-backslash-column 48 686 (defcustom-c-stylevar c-backslash-column 48
550 "*Column to insert backslashes when macroizing a region." 687 "*Minimum alignment column for line continuation backslashes.
688 This is used by the functions that automatically insert or align the
689 line continuation backslashes in multiline macros. If any line in the
690 macro exceeds this column then the next tab stop from that line is
691 used as alignment column instead."
551 :type 'integer 692 :type 'integer
693 :group 'c)
694
695 (defcustom-c-stylevar c-backslash-max-column 72
696 "*Maximum alignment column for line continuation backslashes.
697 This is used by the functions that automatically insert or align the
698 line continuation backslashes in multiline macros. If any line in the
699 macro exceeds this column then the backslashes for the other lines
700 will be aligned at this column."
701 :type 'integer
702 :group 'c)
703
704 (defcustom c-auto-align-backslashes t
705 "*Align automatically inserted line continuation backslashes.
706 When line continuation backslashes are inserted automatically for line
707 breaks in multiline macros, e.g. by \\[c-context-line-break], they are
708 aligned with the other backslashes in the same macro if this flag is
709 set. Otherwise the inserted backslashes are preceded by a single
710 space."
711 :type 'boolean
712 :group 'c)
713
714 (defcustom c-backspace-function 'backward-delete-char-untabify
715 "*Function called by `c-electric-backspace' when deleting backwards."
716 :type 'function
717 :group 'c)
718
719 (defcustom c-delete-function 'delete-char
720 "*Function called by `c-electric-delete' when deleting forwards."
721 :type 'function
722 :group 'c)
723
724 (defcustom c-electric-pound-behavior nil
725 "*List of behaviors for electric pound insertion.
726 Only currently supported behavior is `alignleft'."
727 :type '(set (const alignleft))
552 :group 'c) 728 :group 'c)
553 729
554 (defcustom c-special-indent-hook nil 730 (defcustom c-special-indent-hook nil
555 "*Hook for user defined special indentation adjustments. 731 "*Hook for user defined special indentation adjustments.
556 This hook gets called after a line is indented by the mode." 732 This hook gets called after a line is indented by the mode."
557 :type 'hook 733 :type 'hook
558 :group 'c)
559
560 (defcustom c-backspace-function 'backward-delete-char-untabify
561 "*Function called by `c-electric-backspace' when deleting backwards."
562 :type 'function
563 :group 'c)
564
565 (defcustom c-delete-function 'delete-char
566 "*Function called by `c-electric-delete' when deleting forwards."
567 :type 'function
568 :group 'c)
569
570 (defcustom c-electric-pound-behavior nil
571 "*List of behaviors for electric pound insertion.
572 Only currently supported behavior is `alignleft'."
573 :type '(set :extra-offset 8 (const alignleft))
574 :group 'c) 734 :group 'c)
575 735
576 (defcustom-c-stylevar c-label-minimum-indentation 1 736 (defcustom-c-stylevar c-label-minimum-indentation 1
577 "*Minimum indentation for lines inside of top-level constructs. 737 "*Minimum indentation for lines inside of top-level constructs.
578 This variable typically only affects code using the `gnu' style, which 738 This variable typically only affects code using the `gnu' style, which
627 (const :format "Pike " pike-mode) (string :format "%v")) 787 (const :format "Pike " pike-mode) (string :format "%v"))
628 (cons :format "%v" 788 (cons :format "%v"
629 (const :format "Other " other) (string :format "%v")))) 789 (const :format "Other " other) (string :format "%v"))))
630 :group 'c) 790 :group 'c)
631 791
632 (put 'c-offsets-alist 'c-stylevar-fallback 792 ;; *) At the start of a statement or declaration means in more detail:
793 ;; At the closest preceding statement/declaration that starts at boi
794 ;; and doesn't have a label or comment at that position. If there's
795 ;; no such statement within the same block, then back up to the
796 ;; surrounding block or statement, add the appropriate
797 ;; statement-block-intro, defun-block-intro or substatement syntax
798 ;; symbol and continue searching.
799 (c-set-stylevar-fallback 'c-offsets-alist
633 '((string . c-lineup-dont-change) 800 '((string . c-lineup-dont-change)
634 ;; Relpos: Beg of previous line. 801 ;; Relpos: Beg of previous line.
635 (c . c-lineup-C-comments) 802 (c . c-lineup-C-comments)
636 ;; Relpos: Beg of the comment. 803 ;; Relpos: Beg of the comment.
637 (defun-open . 0) 804 (defun-open . 0)
638 ;; Relpos: Boi at the func decl start when inside classes, bol 805 ;; Relpos: When inside a class: Boi at the func decl start.
639 ;; at the func decl start when at top level. 806 ;; When at top level: Bol at the func decl start. When inside
807 ;; a code block (only possible in Pike): At the func decl
808 ;; start(*).
640 (defun-close . 0) 809 (defun-close . 0)
641 ;; Relpos: Boi at the func decl start. 810 ;; Relpos: At the defun block open if it's at boi, otherwise
811 ;; boi at the func decl start.
642 (defun-block-intro . +) 812 (defun-block-intro . +)
643 ;; Relpos: Boi at the block open. 813 ;; Relpos: At the block open(*).
644 (class-open . 0) 814 (class-open . 0)
645 ;; Relpos: Boi at the class decl start. 815 ;; Relpos: Boi at the class decl start.
646 (class-close . 0) 816 (class-close . 0)
647 ;; Relpos: Boi at the class decl start. 817 ;; Relpos: Boi at the class decl start.
648 (inline-open . +) 818 (inline-open . +)
649 ;; Relpos: None for functions (inclass got the relpos then), 819 ;; Relpos: None for functions (inclass got the relpos then),
650 ;; boi at the lambda start for lambdas. 820 ;; boi at the lambda start for lambdas.
651 (inline-close . 0) 821 (inline-close . 0)
652 ;; Relpos: For functions: Boi at the func decl start. For 822 ;; Relpos: Inexpr functions: At the lambda block open if it's
653 ;; lambdas: At the block open if it's at boi, at the boi of the 823 ;; at boi, else at the statement(*) at boi of the start of the
654 ;; lambda start otherwise. 824 ;; lambda construct. Otherwise: At the inline block open if
825 ;; it's at boi, otherwise boi at the func decl start.
655 (func-decl-cont . +) 826 (func-decl-cont . +)
656 ;; Relpos: Boi at the func decl start. 827 ;; Relpos: Boi at the func decl start.
657 (knr-argdecl-intro . +) 828 (knr-argdecl-intro . +)
658 ;; Relpos: Boi at the current line. 829 ;; Relpos: Boi at the topmost intro line.
659 (knr-argdecl . 0) 830 (knr-argdecl . 0)
660 ;; Relpos: Boi at the argdecl intro line. 831 ;; Relpos: At the beginning of the first K&R argdecl.
661 (topmost-intro . 0) 832 (topmost-intro . 0)
662 ;; Relpos: Bol at the last line of previous construct. 833 ;; Relpos: Bol at the last line of previous construct.
663 (topmost-intro-cont . 0) 834 (topmost-intro-cont . c-lineup-topmost-intro-cont)
664 ;; Relpos: Boi at the topmost intro line. 835 ;; Relpos: Boi at the topmost intro line.
665 (member-init-intro . +) 836 (member-init-intro . +)
666 ;; Relpos: Boi at the func decl arglist open. 837 ;; Relpos: Boi at the func decl arglist open.
667 (member-init-cont . c-lineup-multi-inher) 838 (member-init-cont . c-lineup-multi-inher)
668 ;; Relpos: Beg of the first member init. 839 ;; Relpos: Beg of the first member init.
669 (inher-intro . +) 840 (inher-intro . +)
670 ;; Relpos: Java: Boi at the class decl start. Otherwise: Boi 841 ;; Relpos: Boi at the class decl start.
671 ;; of current line (a bug?), unless it begins with an inher
672 ;; start colon, in which case boi of previous line is used.
673 (inher-cont . c-lineup-multi-inher) 842 (inher-cont . c-lineup-multi-inher)
674 ;; Relpos: Java: At the implements/extends keyword start. 843 ;; Relpos: Java: At the implements/extends keyword start.
675 ;; Otherwise: At the inher start colon, or boi at the class 844 ;; Otherwise: At the inher start colon, or boi at the class
676 ;; decl start if the first inherit clause hangs and it's not a 845 ;; decl start if the first inherit clause hangs and it's not a
677 ;; func-local inherit clause (when does that occur?). 846 ;; func-local inherit clause (when does that occur?).
678 (block-open . 0) 847 (block-open . 0)
679 ;; Relpos: Inexpr statement: Boi at the preceding 848 ;; Relpos: Inexpr statement: At the statement(*) at boi of the
680 ;; paren. Otherwise: None. 849 ;; start of the inexpr construct. Otherwise: None.
681 (block-close . 0) 850 (block-close . 0)
682 ;; Relpos: At the open brace if it's at boi. Otherwise boi at 851 ;; Relpos: Inexpr statement: At the inexpr block open if it's
683 ;; the start of the statement the open brace hangs on, or boi 852 ;; at boi, else at the statement(*) at boi of the start of the
684 ;; at the preceding paren for inexpr statements. 853 ;; inexpr construct. Block hanging on a case/default label: At
854 ;; the closest preceding label that starts at boi. Otherwise:
855 ;; At the block open(*).
685 (brace-list-open . 0) 856 (brace-list-open . 0)
686 ;; Relpos: Boi at the brace list decl start, but a starting 857 ;; Relpos: Boi at the brace list decl start, but a starting
687 ;; "typedef" token is ignored. 858 ;; "typedef" token is ignored.
688 (brace-list-close . 0) 859 (brace-list-close . 0)
689 ;; Relpos: Boi at the brace list open. 860 ;; Relpos: At the brace list decl start(*).
690 (brace-list-intro . +) 861 (brace-list-intro . +)
691 ;; Relpos: Boi at the brace list open. 862 ;; Relpos: At the brace list decl start(*).
692 (brace-list-entry . 0) 863 (brace-list-entry . 0)
693 ;; Relpos: At the first non-ws char after the open paren if the 864 ;; Relpos: At the first non-ws char after the open paren if the
694 ;; first token is on the same line, otherwise boi at that 865 ;; first token is on the same line, otherwise boi at that
695 ;; token. 866 ;; token.
696 (brace-entry-open . 0) 867 (brace-entry-open . 0)
697 ;; Relpos: Same as brace-list-entry. 868 ;; Relpos: Same as brace-list-entry.
698 (statement . 0) 869 (statement . 0)
699 ;; Relpos: After a ';' in the condition clause of a for 870 ;; Relpos: After a `;' in the condition clause of a for
700 ;; statement: At the first token after the starting paren. 871 ;; statement: At the first token after the starting paren.
701 ;; Otherwise: Boi at the start of the closest non-hanging 872 ;; Otherwise: At the preceding statement(*).
702 ;; previous statement, but after any switch label.
703 (statement-cont . +) 873 (statement-cont . +)
704 ;; Relpos: After the first token in the condition clause of a 874 ;; Relpos: After the first token in the condition clause of a
705 ;; for statement: At the first token after the starting paren. 875 ;; for statement: At the first token after the starting paren.
706 ;; On the first line in a continued expression that starts with 876 ;; Otherwise: At the containing statement(*).
707 ;; a stream op and there's no stream op on the previous line:
708 ;; Boi of previous line. Otherwise: Boi at the beginning of
709 ;; the statement, but after any type of label.
710 (statement-block-intro . +) 877 (statement-block-intro . +)
711 ;; Relpos: At the block start if it's at boi, otherwise boi at 878 ;; Relpos: In inexpr statement block: At the inexpr block open
712 ;; the start of the statement the open brace hangs on, or boi 879 ;; if it's at boi, else at the statement(*) at boi of the start
713 ;; at the preceding paren for inexpr statements. 880 ;; of the inexpr construct. In a block hanging on a
881 ;; case/default label: At the closest preceding label that
882 ;; starts at boi. Otherwise: At the start of the containing
883 ;; block(*).
714 (statement-case-intro . +) 884 (statement-case-intro . +)
715 ;; Relpos: At the label keyword (always at boi). 885 ;; Relpos: At the case/default label(*).
716 (statement-case-open . 0) 886 (statement-case-open . 0)
717 ;; Relpos: At the label keyword (always at boi). 887 ;; Relpos: At the case/default label(*).
718 (substatement . +) 888 (substatement . +)
719 ;; Relpos: Boi at the containing statement or else clause. 889 ;; Relpos: At the containing statement(*).
720 (substatement-open . +) 890 (substatement-open . +)
721 ;; Relpos: Boi at the containing statement or else clause. 891 ;; Relpos: At the containing statement(*).
892 (substatement-label . 2)
893 ;; Relpos: At the containing statement(*).
722 (case-label . 0) 894 (case-label . 0)
723 ;; Relpos: At the switch block start if it's at boi, otherwise 895 ;; Relpos: At the start of the switch block(*).
724 ;; boi at the start of the switch condition clause.
725 (access-label . -) 896 (access-label . -)
726 ;; Relpos: Eol (a bug?). 897 ;; Relpos: Same as inclass.
727 (label . 2) 898 (label . 2)
728 ;; Relpos: At the start of the containing block if it's at boi, 899 ;; Relpos: At the start of the containing block(*).
729 ;; otherwise boi at the start of the sexp before the block.
730 (do-while-closure . 0) 900 (do-while-closure . 0)
731 ;; Relpos: Boi at the corresponding while keyword. 901 ;; Relpos: At the corresponding while statement(*).
732 (else-clause . 0) 902 (else-clause . 0)
733 ;; Relpos: Boi at the corresponding if keyword. 903 ;; Relpos: At the corresponding if statement(*).
734 (catch-clause . 0) 904 (catch-clause . 0)
735 ;; Relpos: Boi at the previous try or catch keyword in the try 905 ;; Relpos: At the previous try or catch statement clause(*).
736 ;; statement. 906 (comment-intro . (c-lineup-knr-region-comment c-lineup-comment))
737 (comment-intro . c-lineup-comment)
738 ;; Relpos: None. 907 ;; Relpos: None.
739 (arglist-intro . +) 908 (arglist-intro . +)
740 ;; Relpos: Boi at the open paren, or at the first non-ws after 909 ;; Relpos: Boi at the open paren, or at the first non-ws after
741 ;; the open paren of the surrounding sexp, whichever is later. 910 ;; the open paren of the surrounding sexp, whichever is later.
742 (arglist-cont . 0) 911 (arglist-cont . (c-lineup-gcc-asm-reg 0))
743 ;; Relpos: At the first token after the open paren. 912 ;; Relpos: At the first token after the open paren.
744 (arglist-cont-nonempty . c-lineup-arglist) 913 (arglist-cont-nonempty . (c-lineup-gcc-asm-reg c-lineup-arglist))
745 ;; Relpos: Boi at the open paren, or at the first non-ws after 914 ;; Relpos: Boi at the open paren, or at the first non-ws after
746 ;; the open paren of the surrounding sexp, whichever is later. 915 ;; the open paren of the surrounding sexp, whichever is later.
747 (arglist-close . +) 916 (arglist-close . +)
748 ;; Relpos: Boi at the open paren, or at the first non-ws after 917 ;; Relpos: Boi at the open paren, or at the first non-ws after
749 ;; the open paren of the surrounding sexp, whichever is later. 918 ;; the open paren of the surrounding sexp, whichever is later.
752 (inclass . +) 921 (inclass . +)
753 ;; Relpos: At the class open brace if it's at boi, otherwise 922 ;; Relpos: At the class open brace if it's at boi, otherwise
754 ;; boi at the class decl start. 923 ;; boi at the class decl start.
755 (cpp-macro . [0]) 924 (cpp-macro . [0])
756 ;; Relpos: None. 925 ;; Relpos: None.
757 (cpp-macro-cont . c-lineup-dont-change) 926 (cpp-macro-cont . +)
758 ;; Relpos: At the macro start (always at boi). 927 ;; Relpos: At the macro start (always at boi).
928 (cpp-define-intro . (c-lineup-cpp-define +))
929 ;; Relpos: None.
759 (friend . 0) 930 (friend . 0)
760 ;; Relpos: None. 931 ;; Relpos: None.
761 (objc-method-intro . [0]) 932 (objc-method-intro . [0])
762 ;; Relpos: Boi. 933 ;; Relpos: Boi.
763 (objc-method-args-cont . c-lineup-ObjC-method-args) 934 (objc-method-args-cont . c-lineup-ObjC-method-args)
777 ;; Relpos: Boi at the corresponding namespace keyword. 948 ;; Relpos: Boi at the corresponding namespace keyword.
778 (innamespace . +) 949 (innamespace . +)
779 ;; Relpos: At the namespace block open brace if it's at boi, 950 ;; Relpos: At the namespace block open brace if it's at boi,
780 ;; otherwise boi at the namespace keyword. 951 ;; otherwise boi at the namespace keyword.
781 (template-args-cont . (c-lineup-template-args +)) 952 (template-args-cont . (c-lineup-template-args +))
782 ;; Relpos: Boi at the decl start. 953 ;; Relpos: Boi at the decl start. This might be changed; the
954 ;; logical position is clearly the opening '<'.
783 (inlambda . c-lineup-inexpr-block) 955 (inlambda . c-lineup-inexpr-block)
784 ;; Relpos: None. 956 ;; Relpos: None.
785 (lambda-intro-cont . +) 957 (lambda-intro-cont . +)
786 ;; Relpos: Boi at the lambda start. 958 ;; Relpos: Boi at the lambda start.
787 (inexpr-statement . 0) 959 (inexpr-statement . +)
788 ;; Relpos: None. 960 ;; Relpos: None.
789 (inexpr-class . +) 961 (inexpr-class . +)
790 ;; Relpos: None. 962 ;; Relpos: None.
791 )) 963 ))
792 (defcustom c-offsets-alist nil 964 (defcustom c-offsets-alist nil
842 value succeeds. If none of the elements returns a non-nil value, the 1014 value succeeds. If none of the elements returns a non-nil value, the
843 syntactic element is ignored. 1015 syntactic element is ignored.
844 1016
845 `c-offsets-alist' is a style variable. This means that the offsets on 1017 `c-offsets-alist' is a style variable. This means that the offsets on
846 this variable are normally taken from the style system in CC Mode 1018 this variable are normally taken from the style system in CC Mode
847 \(see `c-default-style' and `c-styles-alist'). However, any offsets 1019 \(see `c-default-style' and `c-style-alist'). However, any offsets
848 put explicitly on this list will override the style system when a CC 1020 put explicitly on this list will override the style system when a CC
849 Mode buffer is initialized \(there is a variable 1021 Mode buffer is initialized \(there is a variable
850 `c-old-style-variable-behavior' that changes this, though). 1022 `c-old-style-variable-behavior' that changes this, though).
851 1023
852 Here is the current list of valid syntactic element symbols: 1024 Here is the current list of valid syntactic element symbols:
887 statement-block-intro -- The first line in a new statement block. 1059 statement-block-intro -- The first line in a new statement block.
888 statement-case-intro -- The first line in a case \"block\". 1060 statement-case-intro -- The first line in a case \"block\".
889 statement-case-open -- The first line in a case block starting with brace. 1061 statement-case-open -- The first line in a case block starting with brace.
890 substatement -- The first line after an if/while/for/do/else. 1062 substatement -- The first line after an if/while/for/do/else.
891 substatement-open -- The brace that opens a substatement block. 1063 substatement-open -- The brace that opens a substatement block.
892 case-label -- A `case' or `default' label. 1064 substatement-label -- Labelled line after an if/while/for/do/else.
1065 case-label -- A \"case\" or \"default\" label.
893 access-label -- C++ private/protected/public access label. 1066 access-label -- C++ private/protected/public access label.
894 label -- Any ordinary label. 1067 label -- Any ordinary label.
895 do-while-closure -- The `while' that ends a do/while construct. 1068 do-while-closure -- The \"while\" that ends a do/while construct.
896 else-clause -- The `else' of an if/else construct. 1069 else-clause -- The \"else\" of an if/else construct.
897 catch-clause -- The `catch' or `finally' of a try/catch construct. 1070 catch-clause -- The \"catch\" or \"finally\" of a try/catch construct.
898 comment-intro -- A line containing only a comment introduction. 1071 comment-intro -- A line containing only a comment introduction.
899 arglist-intro -- The first line in an argument list. 1072 arglist-intro -- The first line in an argument list.
900 arglist-cont -- Subsequent argument list lines when no 1073 arglist-cont -- Subsequent argument list lines when no
901 arguments follow on the same line as the 1074 arguments follow on the same line as the
902 arglist opening paren. 1075 arglist opening paren.
906 arglist-close -- The solo close paren of an argument list. 1079 arglist-close -- The solo close paren of an argument list.
907 stream-op -- Lines continuing a stream operator construct. 1080 stream-op -- Lines continuing a stream operator construct.
908 inclass -- The construct is nested inside a class definition. 1081 inclass -- The construct is nested inside a class definition.
909 Used together with e.g. `topmost-intro'. 1082 Used together with e.g. `topmost-intro'.
910 cpp-macro -- The start of a C preprocessor macro definition. 1083 cpp-macro -- The start of a C preprocessor macro definition.
911 cpp-macro-cont -- Subsequent lines in a multi-line C preprocessor 1084 cpp-macro-cont -- Inside a multi-line C preprocessor macro definition.
912 macro definition.
913 friend -- A C++ friend declaration. 1085 friend -- A C++ friend declaration.
914 objc-method-intro -- The first line of an Objective-C method definition. 1086 objc-method-intro -- The first line of an Objective-C method definition.
915 objc-method-args-cont -- Lines continuing an Objective-C method definition. 1087 objc-method-args-cont -- Lines continuing an Objective-C method definition.
916 objc-method-call-cont -- Lines continuing an Objective-C method call. 1088 objc-method-call-cont -- Lines continuing an Objective-C method call.
917 extern-lang-open -- Brace that opens an external language block. 1089 extern-lang-open -- Brace that opens an external language block.
1019 For styles that hang top-level opening braces (as is common with JDK 1191 For styles that hang top-level opening braces (as is common with JDK
1020 Java coding styles) this can improve performance between 3 and 60 1192 Java coding styles) this can improve performance between 3 and 60
1021 times for core indentation functions (e.g. `c-parse-state'). For 1193 times for core indentation functions (e.g. `c-parse-state'). For
1022 styles that conform to the Emacs recommendation of putting these 1194 styles that conform to the Emacs recommendation of putting these
1023 braces in column zero, this can degrade performance about as much. 1195 braces in column zero, this can degrade performance about as much.
1024 This variable only has effect in XEmacs.") 1196 This variable only has effect in XEmacs."
1025 1197 :type 'boolean
1026 (defcustom c-old-style-variable-behavior nil 1198 :group 'c)
1199
1200 (defvar c-old-style-variable-behavior nil
1027 "*Enables the old style variable behavior when non-nil. 1201 "*Enables the old style variable behavior when non-nil.
1028 1202
1029 Normally the values of the style variables will override the style 1203 Normally the values of the style variables will override the style
1030 settings specified by the variables `c-default-style' and 1204 settings specified by the variables `c-default-style' and
1031 `c-styles-alist'. However, in CC Mode 5.25 and earlier, it was the 1205 `c-style-alist'. However, in CC Mode 5.25 and earlier, it was the
1032 other way around, meaning that changes made to the style variables 1206 other way around, meaning that changes made to the style variables
1033 from e.g. Customize would not take effect unless special precautions 1207 from e.g. Customize would not take effect unless special precautions
1034 were taken. That was confusing, especially for novice users. 1208 were taken. That was confusing, especially for novice users.
1035 1209
1036 It's believed that despite this change, the new behavior will still 1210 It's believed that despite this change, the new behavior will still
1074 1248
1075 (defvar c-current-comment-prefix nil 1249 (defvar c-current-comment-prefix nil
1076 "The current comment prefix regexp. 1250 "The current comment prefix regexp.
1077 Set from `c-comment-prefix-regexp' at mode initialization.") 1251 Set from `c-comment-prefix-regexp' at mode initialization.")
1078 (make-variable-buffer-local 'c-current-comment-prefix) 1252 (make-variable-buffer-local 'c-current-comment-prefix)
1253
1254 (defvar c-buffer-is-cc-mode nil
1255 "Non-nil for all buffers with a major mode derived from CC Mode.
1256 Otherwise, this variable is nil. I.e. this variable is non-nil for
1257 `c-mode', `c++-mode', `objc-mode', `java-mode', `idl-mode',
1258 `pike-mode', and any other non-CC Mode mode that calls
1259 `c-initialize-cc-mode' (e.g. `awk-mode'). The value is the mode
1260 symbol itself (i.e. `c-mode' etc) of the original CC Mode mode, or
1261 just t if it's not known.")
1262 (make-variable-buffer-local 'c-buffer-is-cc-mode)
1263
1264 ;; Have to make `c-buffer-is-cc-mode' permanently local so that it
1265 ;; survives the initialization of the derived mode.
1266 (put 'c-buffer-is-cc-mode 'permanent-local t)
1079 1267
1080 1268
1081 ;; Figure out what features this Emacs has 1269 ;; Figure out what features this Emacs has
1082 ;;;###autoload 1270 ;;;###autoload
1083 (defconst c-emacs-features 1271 (defconst c-emacs-features