cc-vars.el 76.7 KB
Newer Older
Richard M. Stallman's avatar
Richard M. Stallman committed
1 2
;;; cc-vars.el --- user customization variables for CC Mode

Paul Eggert's avatar
Paul Eggert committed
3
;; Copyright (C) 1985, 1987, 1992-2019 Free Software Foundation, Inc.
Richard M. Stallman's avatar
Richard M. Stallman committed
4

Alan Mackenzie's avatar
Alan Mackenzie committed
5 6
;; Authors:    2002- Alan Mackenzie
;;             1998- Martin Stjernholm
7
;;             1992-1999 Barry A. Warsaw
8 9
;;             1987 Dave Detlefs
;;             1987 Stewart Clamen
Richard M. Stallman's avatar
Richard M. Stallman committed
10
;;             1985 Richard M. Stallman
Barry A. Warsaw's avatar
Barry A. Warsaw committed
11
;; Maintainer: bug-cc-mode@gnu.org
Richard M. Stallman's avatar
Richard M. Stallman committed
12
;; Created:    22-Apr-1997 (split from cc-mode.el)
13 14
;; Keywords:   c languages
;; Package:    cc-mode
Richard M. Stallman's avatar
Richard M. Stallman committed
15 16 17

;; This file is part of GNU Emacs.

18
;; GNU Emacs is free software: you can redistribute it and/or modify
Richard M. Stallman's avatar
Richard M. Stallman committed
19
;; it under the terms of the GNU General Public License as published by
20 21
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Richard M. Stallman's avatar
Richard M. Stallman committed
22 23 24 25 26 27 28

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
29
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
Richard M. Stallman's avatar
Richard M. Stallman committed
30

31 32 33 34
;;; Commentary:

;;; Code:

Barry A. Warsaw's avatar
Barry A. Warsaw committed
35
(eval-when-compile
Gerd Moellmann's avatar
Gerd Moellmann committed
36
  (let ((load-path
Gerd Moellmann's avatar
Gerd Moellmann committed
37 38 39
	 (if (and (boundp 'byte-compile-dest-file)
		  (stringp byte-compile-dest-file))
	     (cons (file-name-directory byte-compile-dest-file) load-path)
Gerd Moellmann's avatar
Gerd Moellmann committed
40
	   load-path)))
41
    (load "cc-bytecomp" nil t)))
Gerd Moellmann's avatar
Gerd Moellmann committed
42 43 44

(cc-require 'cc-defs)

45 46 47
(cc-eval-when-compile
  (require 'custom)
  (require 'widget))
Gerd Moellmann's avatar
Gerd Moellmann committed
48 49 50

;;; Helpers

51 52 53 54 55 56 57 58 59

;; Emacs has 'other since at least version 21.1.
;; FIXME this is probably broken, since the widget is defined
;; in wid-edit, which this file does not load.  So we will always
;; define the widget, even when we don't need to.
(when (featurep 'xemacs)
  (or (get 'other 'widget-type)
      (define-widget 'other 'sexp
	"Matches everything, but doesn't let the user edit the value.
Gerd Moellmann's avatar
Gerd Moellmann committed
60
Useful as last item in a `choice' widget."
61 62 63
	:tag "Other"
	:format "%t%n"
	:value 'other)))
Gerd Moellmann's avatar
Gerd Moellmann committed
64

65
;; The next defun will supersede c-const-symbol.
66 67
(eval-and-compile
  (defun c-constant-symbol (sym len)
68 69 70 71 72 73 74 75 76 77 78 79 80 81
  "Create an uneditable symbol for customization buffers.
SYM is the name of the symbol, LEN the length of the field (in
characters) the symbol will be displayed in.  LEN must be big
enough.

This returns a (const ....) structure, suitable for embedding
within a customization type."
  (or (symbolp sym) (error "c-constant-symbol: %s is not a symbol" sym))
  (let* ((name (symbol-name sym))
	 (l (length name))
	 (disp (concat name ":" (make-string (- len l 1) ?\ ))))
    `(const
      :size ,len
      :format ,disp
82
      :value ,sym))))
83

Gerd Moellmann's avatar
Gerd Moellmann committed
84
(define-widget 'c-const-symbol 'item
85 86
  "An uneditable lisp symbol.  This is obsolete -
use c-constant-symbol instead."
Gerd Moellmann's avatar
Gerd Moellmann committed
87 88 89
  :value nil
  :tag "Symbol"
  :format "%t: %v\n%d"
90
  :match (lambda (_widget value) (symbolp value))
Gerd Moellmann's avatar
Gerd Moellmann committed
91 92 93 94 95 96 97 98 99 100
  :value-to-internal
  (lambda (widget value)
    (let ((s (if (symbolp value)
		 (symbol-name value)
	       value))
	  (l (widget-get widget :size)))
      (if l
	  (setq s (concat s (make-string (- l (length s)) ?\ ))))
      s))
  :value-to-external
101
  (lambda (_widget value)
Gerd Moellmann's avatar
Gerd Moellmann committed
102 103 104 105 106 107
    (if (stringp value)
	(intern (progn
		  (string-match "\\`[^ ]*" value)
		  (match-string 0 value)))
      value)))

108 109 110 111
(define-widget 'c-integer-or-nil 'sexp
  "An integer or the value nil."
  :value nil
  :tag "Optional integer"
112
  :match (lambda (_widget value) (or (integerp value) (null value))))
113

114 115 116 117 118
(define-widget 'c-symbol-list 'sexp
  "A single symbol or a list of symbols."
  :tag "Symbols separated by spaces"
  :validate 'widget-field-validate
  :match
119
  (lambda (_widget value)
120 121 122 123 124 125 126 127
    (or (symbolp value)
	(catch 'ok
	  (while (listp value)
	    (unless (symbolp (car value))
	      (throw 'ok nil))
	    (setq value (cdr value)))
	  (null value))))
  :value-to-internal
128
  (lambda (_widget value)
129 130 131 132 133 134 135 136 137 138 139 140
    (cond ((null value)
	   "")
	  ((symbolp value)
	   (symbol-name value))
	  ((consp value)
	   (mapconcat (lambda (symbol)
			(symbol-name symbol))
		      value
		      " "))
	  (t
	   value)))
  :value-to-external
141
  (lambda (_widget value)
142 143 144 145 146 147 148 149 150 151
    (if (stringp value)
	(let (list end)
	  (while (string-match "\\S +" value end)
	    (setq list (cons (intern (match-string 0 value)) list)
		  end (match-end 0)))
	  (if (and list (not (cdr list)))
	      (car list)
	    (nreverse list)))
      value)))

Gerd Moellmann's avatar
Gerd Moellmann committed
152
(defvar c-style-variables
153 154
  '(c-basic-offset c-comment-only-line-offset c-indent-comment-alist
    c-indent-comments-syntactically-p c-block-comment-prefix
155 156 157 158
    c-comment-prefix-regexp c-doc-comment-style c-cleanup-list
    c-hanging-braces-alist c-hanging-colons-alist
    c-hanging-semi&comma-criteria c-backslash-column c-backslash-max-column
    c-special-indent-hook c-label-minimum-indentation c-offsets-alist)
Gerd Moellmann's avatar
Gerd Moellmann committed
159 160
  "List of the style variables.")

161 162 163 164 165 166
(defvar c-fallback-style nil)

(defsubst c-set-stylevar-fallback (name val)
  (put name 'c-stylevar-fallback val)
  (setq c-fallback-style (cons (cons name val) c-fallback-style)))

Gerd Moellmann's avatar
Gerd Moellmann committed
167
(defmacro defcustom-c-stylevar (name val doc &rest args)
168 169
  "Define a style variable NAME with VAL and DOC.
More precisely, convert the given `:type FOO', mined out of ARGS,
170
to an aggregate `:type (radio STYLE (PREAMBLE FOO))', append
171 172 173 174 175 176 177 178 179 180
some boilerplate documentation to DOC, arrange for the fallback
value of NAME to be VAL, and call `custom-declare-variable' to
do the rest of the work.

STYLE stands for the choice where the value is taken from some
style setting.  PREAMBLE is optionally prepended to FOO; that is,
if FOO contains :tag or :value, the respective two-element list
component is ignored."
  (declare (debug (symbolp form stringp &rest)))
  (let* ((expanded-doc (concat doc "
Gerd Moellmann's avatar
Gerd Moellmann committed
181 182

This is a style variable.  Apart from the valid values described
183 184
above, it can be set to the symbol `set-from-style'.  In that case,
it takes its value from the style system (see `c-default-style' and
185
`c-style-alist') when a CC Mode buffer is initialized.  Otherwise,
Gerd Moellmann's avatar
Gerd Moellmann committed
186
the value set here overrides the style system (there is a variable
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
`c-old-style-variable-behavior' that changes this, though)."))
         (typ (eval (plist-get args :type)))
         (type (if (consp typ) typ (list typ)))
         (head (car type))
         (tail (cdr type))
         (newt (append (unless (plist-get tail :tag)
                         '(:tag "Override style settings"))
                       (unless (plist-get tail :value)
                         `(:value ,(eval val)))
                       tail))
         (aggregate `'(radio
                       (const :tag "Use style settings" set-from-style)
                       ,(cons head newt))))
    `(progn
       (c-set-stylevar-fallback ',name ,val)
       (custom-declare-variable
        ',name ''set-from-style
        ,expanded-doc
        ,@(plist-put args :type aggregate)))))
Gerd Moellmann's avatar
Gerd Moellmann committed
206 207

(defun c-valid-offset (offset)
208
  "Return non-nil if OFFSET is a valid offset for a syntactic symbol.
Gerd Moellmann's avatar
Gerd Moellmann committed
209 210 211 212 213 214 215 216 217
See `c-offsets-alist'."
  (or (eq offset '+)
      (eq offset '-)
      (eq offset '++)
      (eq offset '--)
      (eq offset '*)
      (eq offset '/)
      (integerp offset)
      (functionp offset)
218
      (and (symbolp offset) (boundp offset))
219 220 221
      (and (vectorp offset)
	   (= (length offset) 1)
	   (integerp (elt offset 0)))
222 223 224 225 226 227 228 229 230
      (and (consp offset)
	   (not (eq (car offset) 'quote)) ; Detect misquoted lists.
	   (progn
	     (when (memq (car offset) '(first min max add))
	       (setq offset (cdr offset)))
	     (while (and (consp offset)
			 (c-valid-offset (car offset)))
	       (setq offset (cdr offset)))
	     (null offset)))))
Gerd Moellmann's avatar
Gerd Moellmann committed
231

232 233 234 235 236 237 238 239 240 241 242 243 244 245
(defun c-string-list-p (val)
  "Return non-nil if VAL is a list of strings."
  (and
   (listp val)
   (catch 'string
     (dolist (elt val)
       (if (not (stringp elt))
	   (throw 'string nil)))
     t)))

(defun c-string-or-string-list-p (val)
  "Return non-nil if VAL is a string or a list of strings."
  (or (stringp val)
      (c-string-list-p val)))
Richard M. Stallman's avatar
Richard M. Stallman committed
246

Gerd Moellmann's avatar
Gerd Moellmann committed
247 248
;;; User variables

Richard M. Stallman's avatar
Richard M. Stallman committed
249
(defcustom c-strict-syntax-p nil
250
  "If non-nil, all syntactic symbols must be found in `c-offsets-alist'.
Richard M. Stallman's avatar
Richard M. Stallman committed
251
If the syntactic symbol for a particular line does not match a symbol
Barry A. Warsaw's avatar
Barry A. Warsaw committed
252 253
in the offsets alist, or if no non-nil offset value can be determined
for a symbol, an error is generated, otherwise no error is reported
Gerd Moellmann's avatar
Gerd Moellmann committed
254 255 256 257 258
and the syntactic symbol is ignored.

This variable is considered obsolete; it doesn't work well with lineup
functions that return nil to support the feature of using lists on
syntactic symbols in `c-offsets-alist'.  Please keep it set to nil."
Richard M. Stallman's avatar
Richard M. Stallman committed
259 260 261 262
  :type 'boolean
  :group 'c)

(defcustom c-echo-syntactic-information-p nil
263
  "If non-nil, syntactic info is echoed when the line is indented."
Richard M. Stallman's avatar
Richard M. Stallman committed
264 265 266
  :type 'boolean
  :group 'c)

267
(defcustom c-report-syntactic-errors nil
268
  "If non-nil, certain syntactic errors are reported with a ding
269 270 271 272 273 274 275 276 277 278
and a message, for example when an \"else\" is indented for which
there's no corresponding \"if\".

Note however that CC Mode doesn't make any special effort to check for
syntactic errors; that's the job of the compiler.  The reason it can
report cases like the one above is that it can't find the correct
anchoring position to indent the line in that case."
  :type 'boolean
  :group 'c)

Gerd Moellmann's avatar
Gerd Moellmann committed
279
(defcustom-c-stylevar c-basic-offset 4
280
  "Amount of basic offset used by + and - symbols in `c-offsets-alist'.
281 282
Also used as the indentation step when `c-syntactic-indentation' is
nil."
Richard M. Stallman's avatar
Richard M. Stallman committed
283 284
  :type 'integer
  :group 'c)
285
;;;###autoload(put 'c-basic-offset 'safe-local-variable 'integerp)
Richard M. Stallman's avatar
Richard M. Stallman committed
286

287

Richard M. Stallman's avatar
Richard M. Stallman committed
288
(defcustom c-tab-always-indent t
289
  "Controls the operation of the TAB key.
290 291
If t, hitting TAB always just indents the current line.  If nil, hitting
TAB indents the current line if point is at the left margin or in the
292 293 294
line's indentation, otherwise it inserts a `real' tab character (see
note).  If some other value (not nil or t), then tab is inserted only
within literals (comments and strings), but the line is always
295 296 297 298 299 300 301 302 303
reindented.

Note: The value of `indent-tabs-mode' will determine whether a real
tab character will be inserted, or the equivalent number of spaces.
When inserting a tab, actually the function stored in the variable
`c-insert-tab-function' is called.

Note: indentation of lines containing only comments is also controlled
by the `c-comment-only-line-offset' variable."
Richard M. Stallman's avatar
Richard M. Stallman committed
304
  :type '(radio
305 306 307
	  (const :tag "TAB key always indents, never inserts TAB" t)
	  (const :tag "TAB key indents in left margin, otherwise inserts TAB" nil)
	  (other :tag "TAB key inserts TAB in literals, otherwise indents" other))
Richard M. Stallman's avatar
Richard M. Stallman committed
308 309 310
  :group 'c)

(defcustom c-insert-tab-function 'insert-tab
311
  "Function used when inserting a tab for \\[c-indent-command].
Richard M. Stallman's avatar
Richard M. Stallman committed
312
Only used when `c-tab-always-indent' indicates a `real' tab character
313 314 315
should be inserted.  Value must be a function taking no arguments.
The default, `insert-tab', inserts either a tab or the equivalent
number of spaces depending on the value of `indent-tabs-mode'."
Richard M. Stallman's avatar
Richard M. Stallman committed
316 317 318
  :type 'function
  :group 'c)

319
(defcustom c-syntactic-indentation t
320
  "Whether the indentation should be controlled by the syntactic context.
321

322
If t, the indentation functions indent according to the syntactic
323 324 325
context, using the style settings specified by `c-offsets-alist'.

If nil, every line is just indented to the same level as the previous
326 327 328
one, and the \\[c-indent-command] command adjusts the indentation in
steps specified by `c-basic-offset'.  The indentation style has no
effect in this mode, nor any of the indentation associated variables,
329 330 331
e.g. `c-special-indent-hook'."
  :type 'boolean
  :group 'c)
332
(make-variable-buffer-local 'c-syntactic-indentation)
333
(put 'c-syntactic-indentation 'safe-local-variable 'booleanp)
334

335
(defcustom c-syntactic-indentation-in-macros t
336
  "Enable syntactic analysis inside macros.
337 338 339 340 341 342 343 344 345 346
If this is nil, all lines inside macro definitions are analyzed as
`cpp-macro-cont'.  Otherwise they are analyzed syntactically, just
like normal code, and `cpp-define-intro' is used to create the
additional indentation of the bodies of \"#define\" macros.

Having this enabled simplifies editing of large multiline macros, but
it might complicate editing if CC Mode doesn't recognize the context
of the macro content.  The default context inside the macro is the
same as the top level, so if it contains \"bare\" statements they
might be indented wrongly, although there are special cases that
347
handle this in most cases.  If this problem occurs, it's usually
348 349
countered easily by surrounding the statements by a block (or even
better with the \"do { ... } while (0)\" trick)."
350 351
  :type 'boolean
  :group 'c)
352

353
(put 'c-syntactic-indentation-in-macros 'safe-local-variable 'booleanp)
354

355
(defcustom c-defun-tactic 'go-outward
356
  "Whether functions are recognized inside, e.g., a class.
357 358 359 360 361 362 363
This is used by `c-beginning-of-defun' and like functions.

Its value is one of:
 t           -- Functions are recognized only at the top level.
 go-outward  -- Nested functions are also recognized.  Should a function
                command hit the beginning/end of a nested scope, it will
                carry on at the less nested level."
364
  :version "24.1"
365 366 367 368 369
  :type '(radio
	  (const :tag "Functions are at the top-level" t)
	  (const :tag "Functions are also recognized inside declaration scopes" go-outward))
  :group 'c)

Gerd Moellmann's avatar
Gerd Moellmann committed
370
(defcustom-c-stylevar c-comment-only-line-offset 0
371
  "Extra offset for line which contains only the start of a comment.
Richard M. Stallman's avatar
Richard M. Stallman committed
372 373 374 375 376 377 378
Can contain an integer or a cons cell of the form:

 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)

Where NON-ANCHORED-OFFSET is the amount of offset given to
non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
the amount of offset to give column-zero anchored comment-only lines.
Gerd Moellmann's avatar
Gerd Moellmann committed
379 380 381 382 383 384
Just an integer as value is equivalent to (<val> . -1000).

Note that this variable only has effect when the `c-lineup-comment'
lineup function is used on the `comment-intro' syntactic symbol (the
default)."
  :type '(choice (integer :tag "Non-anchored offset" 0)
Richard M. Stallman's avatar
Richard M. Stallman committed
385 386 387 388 389 390
		 (cons :tag "Non-anchored & anchored offset"
		       :value (0 . 0)
		       (integer :tag "Non-anchored offset")
		       (integer :tag "Anchored offset")))
  :group 'c)

391 392 393 394
(defcustom-c-stylevar c-indent-comment-alist
  '((anchored-comment . (column . 0))
    (end-block . (space . 1))
    (cpp-end-block . (space . 2)))
395
  "Specifies how \\[indent-for-comment] calculates the comment start column.
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
This is an association list that contains entries of the form:

 (LINE-TYPE . INDENT-SPEC)

LINE-TYPE specifies a type of line as described below, and INDENT-SPEC
says what \\[indent-for-comment] should do when used on that type of line.

The recognized values for LINE-TYPE are:

 empty-line        -- The line is empty.
 anchored-comment  -- The line contains a comment that starts in column 0.
 end-block         -- The line contains a solitary block closing brace.
 cpp-end-block     -- The line contains a preprocessor directive that
                      closes a block, i.e. either \"#endif\" or \"#else\".
 other             -- The line does not match any other entry
                      currently on the list.

An INDENT-SPEC is a cons cell of the form:

 (ACTION . VALUE)

ACTION says how \\[indent-for-comment] should align the comment, and
VALUE is interpreted depending on ACTION.  ACTION can be any of the
following:

 space   -- Put VALUE spaces between the end of the line and the start
            of the comment.
 column  -- Start the comment at the column VALUE.  If the line is
            longer than that, the comment is preceded by a single
            space.  If VALUE is nil, `comment-column' is used.
 align   -- Align the comment with one on the previous line, if there
            is any.  If the line is too long, the comment is preceded
            by a single space.  If there isn't a comment start on the
            previous line, the behavior is specified by VALUE, which
            in turn is interpreted as an INDENT-SPEC.

If a LINE-TYPE is missing, then \\[indent-for-comment] indents the comment
according to `comment-column'.

Note that a non-nil value on `c-indent-comments-syntactically-p'
Paul Eggert's avatar
Paul Eggert committed
436
overrides this variable, so empty lines are indented syntactically
437 438 439 440 441 442 443 444 445 446 447 448 449 450
in that case, i.e. as if \\[c-indent-command] was used instead."
  :type
  (let ((space '(cons :tag "space"
		      :format "%v"
		      :value (space . 1)
		      (const :format "space  " space)
		      (integer :format "%v")))
	(column '(cons :tag "column"
		       :format "%v"
		       (const :format "column " column)
		       (c-integer-or-nil :format "%v"))))
    `(set ,@(mapcar
	     (lambda (elt)
	       `(cons :format "%v"
451
		      ,(c-constant-symbol elt 20)
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
		      (choice
		       :format "%[Choice%] %v"
		       :value (column . nil)
		       ,space
		       ,column
		       (cons :tag "align"
			     :format "%v"
			     (const :format "align  " align)
			     (choice
			      :format "%[Choice%] %v"
			      :value (column . nil)
			      ,space
			      ,column)))))
	     '(empty-line anchored-comment end-block cpp-end-block other))))
  :group 'c)

(defcustom-c-stylevar c-indent-comments-syntactically-p nil
469
  "Specifies how \\[indent-for-comment] should handle comment-only lines.
Richard M. Stallman's avatar
Richard M. Stallman committed
470
When this variable is non-nil, comment-only lines are indented
Gerd Moellmann's avatar
Gerd Moellmann committed
471 472 473 474
according to syntactic analysis via `c-offsets-alist'.  Otherwise, the
comment is indented as if it was preceded by code.  Note that this
variable does not affect how the normal line indentation treats
comment-only lines."
Richard M. Stallman's avatar
Richard M. Stallman committed
475 476 477
  :type 'boolean
  :group 'c)

Gerd Moellmann's avatar
Gerd Moellmann committed
478
(make-obsolete-variable 'c-comment-continuation-stars
479
			'c-block-comment-prefix "21.1")
Gerd Moellmann's avatar
Gerd Moellmann committed
480 481 482 483

;; Although c-comment-continuation-stars is obsolete, we look at it in
;; some places in CC Mode anyway, so make the compiler ignore it
;; during our compilation.
484 485 486
;; [This is unclean; better to use `symbol-value'. --ttn]
;;(cc-bytecomp-obsolete-var c-comment-continuation-stars)
;;(cc-bytecomp-defvar c-comment-continuation-stars)
Gerd Moellmann's avatar
Gerd Moellmann committed
487

Gerd Moellmann's avatar
Gerd Moellmann committed
488 489
(defcustom-c-stylevar c-block-comment-prefix
  (if (boundp 'c-comment-continuation-stars)
490
      (symbol-value 'c-comment-continuation-stars)
Gerd Moellmann's avatar
Gerd Moellmann committed
491
    "* ")
492
  "Specifies the line prefix of continued C-style block comments.
493 494
You should set this variable to the literal string that gets inserted
at the front of continued block style comment lines.  This should
Gerd Moellmann's avatar
Gerd Moellmann committed
495 496 497 498 499 500 501 502 503
either be the empty string, or some characters without preceding
spaces.  To adjust the alignment under the comment starter, put an
appropriate value on the `c' syntactic symbol (see the
`c-offsets-alist' variable).

It's only used when a one-line block comment is broken into two or
more lines for the first time; otherwise the appropriate prefix is
adapted from the comment.  This variable is not used for C++ line
style comments."
504
  :type 'string
Gerd Moellmann's avatar
Gerd Moellmann committed
505 506
  :group 'c)

Gerd Moellmann's avatar
Gerd Moellmann committed
507 508
(defcustom-c-stylevar c-comment-prefix-regexp
  '((pike-mode . "//+!?\\|\\**")
509
    (awk-mode . "#+")
Gerd Moellmann's avatar
Gerd Moellmann committed
510
    (other . "//+\\|\\**"))
511
  "Regexp to match the line prefix inside comments.
Gerd Moellmann's avatar
Gerd Moellmann committed
512 513 514
This regexp is used to recognize the fill prefix inside comments for
correct paragraph filling and other things.

Gerd Moellmann's avatar
Gerd Moellmann committed
515 516 517 518 519 520 521 522 523 524 525 526 527
If this variable is a string, it will be used in all CC Mode major
modes.  It can also be an association list, to associate specific
regexps to specific major modes.  The symbol for the major mode is
looked up in the association list, and its value is used as the line
prefix regexp.  If it's not found, then the symbol `other' is looked
up and its value is used instead.

The regexp should match the prefix used in both C++ style line
comments and C style block comments, but it does not need to match a
block comment starter.  In other words, it should at least match
\"//\" for line comments and the string in `c-block-comment-prefix',
which is sometimes inserted by CC Mode inside block comments.  It
should not match any surrounding whitespace.
Gerd Moellmann's avatar
Gerd Moellmann committed
528

529
Note that CC Mode uses this variable to set many other variables that
530
handle the paragraph filling.  That's done at mode initialization or
531 532
when you switch to a style which sets this variable.  Thus, if you
change it in some other way, e.g. interactively in a CC Mode buffer,
533 534
you will need to do \\[c-setup-paragraph-variables] afterwards so that
the other variables are updated with the new value.
535

536 537 538 539
Note also that when CC Mode starts up, all variables are initialized
before the mode hooks are run.  It's therefore necessary to make a
call to `c-setup-paragraph-variables' explicitly if you change this
variable in a mode hook."
Gerd Moellmann's avatar
Gerd Moellmann committed
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
  :type '(radio
	  (regexp :tag "Regexp for all modes")
	  (list
	   :tag "Mode-specific regexps"
	   (set
	    :inline t :format "%v"
	    (cons :format "%v"
		  (const :format "C     " c-mode) (regexp :format "%v"))
	    (cons :format "%v"
		  (const :format "C++   " c++-mode) (regexp :format "%v"))
	    (cons :format "%v"
		  (const :format "ObjC  " objc-mode) (regexp :format "%v"))
	    (cons :format "%v"
		  (const :format "Java  " java-mode) (regexp :format "%v"))
	    (cons :format "%v"
		  (const :format "IDL   " idl-mode) (regexp :format "%v"))
	    (cons :format "%v"
557
		  (const :format "Pike  " pike-mode) (regexp :format "%v"))
558
	    (cons :format "%v"
559
		  (const :format "AWK   " awk-mode) (regexp :format "%v")))
Gerd Moellmann's avatar
Gerd Moellmann committed
560 561
	   (cons :format "    %v"
		 (const :format "Other " other) (regexp :format "%v"))))
562 563
  :group 'c)

564 565
(defcustom-c-stylevar c-doc-comment-style
  '((java-mode . javadoc)
566
    (pike-mode . autodoc)
567 568
    (c-mode    . gtkdoc)
    (c++-mode  . gtkdoc))
569
  "Specifies documentation comment style(s) to recognize.
570 571 572 573 574 575 576 577
This is primarily used to fontify doc comments and the markup within
them, e.g. Javadoc comments.

The value can be any of the following symbols for various known doc
comment styles:

 javadoc -- Javadoc style for \"/** ... */\" comments (default in Java mode).
 autodoc -- Pike autodoc style for \"//! ...\" comments (default in Pike mode).
578
 gtkdoc  -- GtkDoc style for \"/** ... **/\" comments (default in C and C++ modes).
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602

The value may also be a list of doc comment styles, in which case all
of them are recognized simultaneously (presumably with markup cues
that don't conflict).

The value may also be an association list to specify different doc
comment styles for different languages.  The symbol for the major mode
is then looked up in the alist, and the value of that element is
interpreted as above if found.  If it isn't found then the symbol
`other' is looked up and its value is used instead.

Note that CC Mode uses this variable to set other variables that
handle fontification etc.  That's done at mode initialization or when
you switch to a style which sets this variable.  Thus, if you change
it in some other way, e.g. interactively in a CC Mode buffer, you will
need to do \\[java-mode] (or whatever mode you're currently using) to
reinitialize.

Note also that when CC Mode starts up, the other variables are
modified before the mode hooks are run.  If you change this variable
in a mode hook, you have to call `c-setup-doc-comment-style'
afterwards to redo that work."
  ;; Symbols other than those documented above may be used on this
  ;; variable.  If a variable exists that has that name with
Juanma Barranquero's avatar
Juanma Barranquero committed
603
  ;; "-font-lock-keywords" appended, its value is prepended to the
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
  ;; font lock keywords list.  If it's a function then it's called and
  ;; the result is prepended.
  :type '(radio
	  (c-symbol-list :tag "Doc style(s) in all modes")
	  (list
	   :tag "Mode-specific doc styles"
	   (set
	    :inline t :format "%v"
	    (cons :format "%v"
		  (const :format "C     " c-mode)
		  (c-symbol-list :format "%v"))
	    (cons :format "%v"
		  (const :format "C++   " c++-mode)
		  (c-symbol-list :format "%v"))
	    (cons :format "%v"
		  (const :format "ObjC  " objc-mode)
		  (c-symbol-list :format "%v"))
	    (cons :format "%v"
		  (const :format "Java  " java-mode)
		  (c-symbol-list :format "%v"))
	    (cons :format "%v"
		  (const :format "IDL   " idl-mode)
		  (c-symbol-list :format "%v"))
	    (cons :format "%v"
		  (const :format "Pike  " pike-mode)
		  (c-symbol-list :format "%v"))
630 631 632
	    (cons :format "%v"
		  (const :format "AWK   " awk-mode)
		  (c-symbol-list :format "%v"))
633 634 635 636 637
	    (cons :format "%v"
		  (const :format "Other " other)
		  (c-symbol-list :format "%v")))))
  :group 'c)

Gerd Moellmann's avatar
Gerd Moellmann committed
638
(defcustom c-ignore-auto-fill '(string cpp code)
639
  "List of contexts in which automatic filling never occurs.
Gerd Moellmann's avatar
Gerd Moellmann committed
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
If Auto Fill mode is active, it will be temporarily disabled if point
is in any context on this list.  It's e.g. useful to enable Auto Fill
in comments only, but not in strings or normal code.  The valid
contexts are:

 string  -- inside a string or character literal
 c       -- inside a C style block comment
 c++     -- inside a C++ style line comment
 cpp     -- inside a preprocessor directive
 code    -- anywhere else, i.e. in normal code"
  :type '(set
	  (const :tag "String literals" string)
	  (const :tag "C style block comments" c)
	  (const :tag "C++ style line comments" c++)
	  (const :tag "Preprocessor directives" cpp)
	  (const :tag "Normal code" code))
  :group 'c)

(defcustom-c-stylevar c-cleanup-list '(scope-operator)
659
  "List of various C/C++/ObjC constructs to \"clean up\".
Gerd Moellmann's avatar
Gerd Moellmann committed
660
The following clean ups only take place when the auto-newline feature
661 662
is turned on, as evidenced by the `/la' appearing next to the mode
name:
Richard M. Stallman's avatar
Richard M. Stallman committed
663

Gerd Moellmann's avatar
Gerd Moellmann committed
664 665 666
 brace-else-brace    -- Clean up \"} else {\" constructs by placing
                        entire construct on a single line.  This clean
                        up only takes place when there is nothing but
Richard M. Stallman's avatar
Richard M. Stallman committed
667
                        white space between the braces and the `else'.
Gerd Moellmann's avatar
Gerd Moellmann committed
668
                        Clean up occurs when the open brace after the
Richard M. Stallman's avatar
Richard M. Stallman committed
669
                        `else' is typed.
Gerd Moellmann's avatar
Gerd Moellmann committed
670 671 672 673 674 675 676
 brace-elseif-brace  -- Similar to brace-else-brace, but clean up
                        \"} else if (...) {\" constructs.  Clean up
                        occurs after the open parenthesis and the open
                        brace.
 brace-catch-brace   -- Similar to brace-elseif-brace, but clean up
                        \"} catch (...) {\" constructs.
 empty-defun-braces  -- Clean up empty defun braces by placing the
Richard M. Stallman's avatar
Richard M. Stallman committed
677
                        braces on the same line.  Clean up occurs when
678
                        the defun closing brace is typed.
679 680 681 682
 one-liner-defun     -- If the code inside a function body can fit in
                        a single line, then remove any newlines
                        between that line and the defun braces so that
                        the whole body becomes a single line.
683 684 685
                        `c-max-one-liner-length' gives the maximum
                        length allowed for the resulting line.  Clean
                        up occurs when the closing brace is typed.
Gerd Moellmann's avatar
Gerd Moellmann committed
686
 defun-close-semi    -- Clean up the terminating semi-colon on defuns
687 688 689
                        by placing the semi-colon on the same line as
                        the closing brace.  Clean up occurs when the
                        semi-colon is typed.
Gerd Moellmann's avatar
Gerd Moellmann committed
690
 list-close-comma    -- Clean up commas following braces in array
Richard M. Stallman's avatar
Richard M. Stallman committed
691
                        and aggregate initializers.  Clean up occurs
692
                        when the comma is typed.
Gerd Moellmann's avatar
Gerd Moellmann committed
693
 scope-operator      -- Clean up double colons which may designate
694 695 696 697 698 699
                        a C++ scope operator split across multiple
                        lines.  Note that certain C++ constructs can
                        generate ambiguous situations.  This clean up
                        only takes place when there is nothing but
                        whitespace between colons.  Clean up occurs
                        when the second colon is typed.
Gerd Moellmann's avatar
Gerd Moellmann committed
700 701 702 703 704 705 706 707 708

The following clean ups always take place when they are on this list,
regardless of the auto-newline feature, since they typically don't
involve auto-newline inserted newlines:

 space-before-funcall -- Insert exactly one space before the opening
                        parenthesis of a function call.  Clean up
                        occurs when the opening parenthesis is typed.
 compact-empty-funcall -- Clean up any space before the function call
709
                        opening parenthesis if and only if the
Gerd Moellmann's avatar
Gerd Moellmann committed
710 711 712 713
                        argument list is empty.  This is typically
                        useful together with `space-before-funcall' to
                        get the style \"foo (bar)\" and \"foo()\".
                        Clean up occurs when the closing parenthesis
714 715 716 717 718
                        is typed.
 comment-close-slash -- When a slash is typed after the comment prefix
                        on a bare line in a c-style comment, the comment
                        is closed by cleaning up preceding space and
                        inserting a star if needed."
Richard M. Stallman's avatar
Richard M. Stallman committed
719
  :type '(set
720
	  (const :tag "Put \"} else {\" on one line (brace-else-brace)"
Gerd Moellmann's avatar
Gerd Moellmann committed
721
		 brace-else-brace)
722
	  (const :tag "Put \"} else if (...) {\" on one line (brace-elseif-brace)"
Gerd Moellmann's avatar
Gerd Moellmann committed
723
		 brace-elseif-brace)
724
	  (const :tag "Put \"} catch (...) {\" on one line (brace-catch-brace)"
Gerd Moellmann's avatar
Gerd Moellmann committed
725
		 brace-catch-brace)
726
	  (const :tag "Put empty defun braces on one line (empty-defun-braces)"
Gerd Moellmann's avatar
Gerd Moellmann committed
727
		 empty-defun-braces)
728 729 730
	  (const :tag "Put short function bodies on one line (one-liner-defun)"
		 one-liner-defun)
	  (const :tag "Put \"};\" ending defuns on one line (defun-close-semi)"
Gerd Moellmann's avatar
Gerd Moellmann committed
731
		 defun-close-semi)
732
	  (const :tag "Put \"},\" in aggregates on one line (list-close-comma)"
Gerd Moellmann's avatar
Gerd Moellmann committed
733
		 list-close-comma)
734
	  (const :tag "Put C++ style \"::\" on one line (scope-operator)"
Gerd Moellmann's avatar
Gerd Moellmann committed
735
		 scope-operator)
736
	  (const :tag "Put a space before funcall parens, e.g. \"foo (bar)\" (space-before-funcall)"
Gerd Moellmann's avatar
Gerd Moellmann committed
737
		 space-before-funcall)
738 739 740 741
	  (const :tag "Remove space before empty funcalls, e.g. \"foo()\" (compact-empty-funcall)"
		 compact-empty-funcall)
	  (const :tag "Make / on a bare line of a C-style comment close it (comment-close-slash)"
		 comment-close-slash))
Richard M. Stallman's avatar
Richard M. Stallman committed
742 743
  :group 'c)

Gerd Moellmann's avatar
Gerd Moellmann committed
744 745
(defcustom-c-stylevar c-hanging-braces-alist '((brace-list-open)
					       (brace-entry-open)
746
					       (statement-cont)
Gerd Moellmann's avatar
Gerd Moellmann committed
747 748 749
					       (substatement-open after)
					       (block-close . c-snug-do-while)
					       (extern-lang-open after)
750 751 752
					       (namespace-open after)
					       (module-open after)
					       (composition-open after)
Gerd Moellmann's avatar
Gerd Moellmann committed
753
					       (inexpr-class-open after)
754 755
					       (inexpr-class-close before)
					       (arglist-cont-nonempty))
756
  "Controls the insertion of newlines before and after braces
Gerd Moellmann's avatar
Gerd Moellmann committed
757 758 759
when the auto-newline feature is active.  This variable contains an
association list with elements of the following form:
\(SYNTACTIC-SYMBOL . ACTION).
Richard M. Stallman's avatar
Richard M. Stallman committed
760 761 762 763 764 765 766

When a brace (either opening or closing) is inserted, the syntactic
context it defines is looked up in this list, and if found, the
associated ACTION is used to determine where newlines are inserted.
If the context is not found, the default is to insert a newline both
before and after the brace.

767 768 769 770 771 772 773
SYNTACTIC-SYMBOL can be statement-cont, brace-list-intro,
inexpr-class-open, inexpr-class-close, and any of the *-open and
*-close symbols.  See `c-offsets-alist' for details, except for
inexpr-class-open and inexpr-class-close, which doesn't have any
corresponding symbols there.  Those two symbols are used for the
opening and closing braces, respectively, of anonymous inner classes
in Java.
Richard M. Stallman's avatar
Richard M. Stallman committed
774 775 776 777 778 779 780 781 782 783 784

ACTION can be either a function symbol or a list containing any
combination of the symbols `before' or `after'.  If the list is empty,
no newlines are inserted either before or after the brace.

When ACTION is a function symbol, the function is called with a two
arguments: the syntactic symbol for the brace and the buffer position
at which the brace was inserted.  The function must return a list as
described in the preceding paragraph.  Note that during the call to
the function, the variable `c-syntactic-context' is set to the entire
syntactic context for the brace line."
Gerd Moellmann's avatar
Gerd Moellmann committed
785 786 787 788
  :type
  `(set ,@(mapcar
	   (lambda (elt)
	     `(cons :format "%v"
789
		    ,(c-constant-symbol elt 24)
Gerd Moellmann's avatar
Gerd Moellmann committed
790
		    (choice :format "%[Choice%] %v"
791
			    :value (before after)
Gerd Moellmann's avatar
Gerd Moellmann committed
792
			    (set :menu-tag "Before/after"
793 794 795
				 :format "Newline  %v brace\n"
				 (const :format "%v,  " before)
				 (const :format "%v " after))
Gerd Moellmann's avatar
Gerd Moellmann committed
796
			    (function :menu-tag "Function"
797
				      :format "Run function: %v"))))
Gerd Moellmann's avatar
Gerd Moellmann committed
798 799 800 801
	   '(defun-open defun-close
	      class-open class-close
	      inline-open inline-close
	      block-open block-close
802
	      statement-cont substatement-open statement-case-open
Gerd Moellmann's avatar
Gerd Moellmann committed
803 804
	      brace-list-open brace-list-close
	      brace-list-intro brace-entry-open
805
	      extern-lang-open extern-lang-close
Gerd Moellmann's avatar
Gerd Moellmann committed
806
	      namespace-open namespace-close
807 808
	      module-open module-close
	      composition-open composition-close
809 810
	      inexpr-class-open inexpr-class-close
	      arglist-cont-nonempty)))
Gerd Moellmann's avatar
Gerd Moellmann committed
811 812
    :group 'c)

813 814 815 816 817 818
(defcustom c-max-one-liner-length 80
  "Maximum length of line that clean-up \"one-liner-defun\" will compact to.
Zero or nil means no limit."
  :type 'integer
  :group 'c)

Gerd Moellmann's avatar
Gerd Moellmann committed
819
(defcustom-c-stylevar c-hanging-colons-alist nil
820
  "Controls the insertion of newlines before and after certain colons.
Richard M. Stallman's avatar
Richard M. Stallman committed
821 822 823 824 825 826 827 828 829
This variable contains an association list with elements of the
following form: (SYNTACTIC-SYMBOL . ACTION).

SYNTACTIC-SYMBOL can be any of: case-label, label, access-label,
member-init-intro, or inher-intro.

See the variable `c-hanging-braces-alist' for the semantics of this
variable.  Note however that making ACTION a function symbol is
currently not supported for this variable."
Gerd Moellmann's avatar
Gerd Moellmann committed
830 831 832 833
  :type
  `(set ,@(mapcar
	   (lambda (elt)
	     `(cons :format "%v"
834 835 836
		    ,(c-constant-symbol elt 20)
		    (set :format "Newline  %v  colon\n"
			 (const :format "%v,  " before)
Gerd Moellmann's avatar
Gerd Moellmann committed
837 838
			 (const :format "%v" after))))
	   '(case-label label access-label member-init-intro inher-intro)))
Richard M. Stallman's avatar
Richard M. Stallman committed
839 840
  :group 'c)

Gerd Moellmann's avatar
Gerd Moellmann committed
841 842
(defcustom-c-stylevar c-hanging-semi&comma-criteria
  '(c-semi&comma-inside-parenlist)
843
  "List of functions that decide whether to insert a newline or not.
Richard M. Stallman's avatar
Richard M. Stallman committed
844 845 846 847 848 849 850
The functions in this list are called, in order, whenever the
auto-newline minor mode is activated (as evidenced by a `/a' or `/ah'
string in the mode line), and a semicolon or comma is typed (see
`c-electric-semi&comma').  Each function in this list is called with
no arguments, and should return one of the following values:

  nil             -- no determination made, continue checking
851
  `stop'          -- do not insert a newline, and stop checking
Richard M. Stallman's avatar
Richard M. Stallman committed
852 853 854 855 856 857 858
  (anything else) -- insert a newline, and stop checking

If every function in the list is called with no determination made,
then no newline is inserted."
  :type '(repeat function)
  :group 'c)

Gerd Moellmann's avatar
Gerd Moellmann committed
859
(defcustom-c-stylevar c-backslash-column 48
860
  "Minimum alignment column for line continuation backslashes.
861 862 863
This is used by the functions that automatically insert or align the
line continuation backslashes in multiline macros.  If any line in the
macro exceeds this column then the next tab stop from that line is
864
used as alignment column instead.  See also `c-backslash-max-column'."
Richard M. Stallman's avatar
Richard M. Stallman committed
865 866
  :type 'integer
  :group 'c)
867
;;;###autoload(put 'c-backslash-column 'safe-local-variable 'integerp)
Richard M. Stallman's avatar
Richard M. Stallman committed
868

869
(defcustom-c-stylevar c-backslash-max-column 72
870
  "Maximum alignment column for line continuation backslashes.
871 872 873 874 875 876 877 878
This is used by the functions that automatically insert or align the
line continuation backslashes in multiline macros.  If any line in the
macro exceeds this column then the backslashes for the other lines
will be aligned at this column."
  :type 'integer
  :group 'c)

(defcustom c-auto-align-backslashes t
879
  "Align automatically inserted line continuation backslashes.
880 881 882 883 884 885
When line continuation backslashes are inserted automatically for line
breaks in multiline macros, e.g. by \\[c-context-line-break], they are
aligned with the other backslashes in the same macro if this flag is
set.  Otherwise the inserted backslashes are preceded by a single
space."
  :type 'boolean
Richard M. Stallman's avatar
Richard M. Stallman committed
886 887 888
  :group 'c)

(defcustom c-backspace-function 'backward-delete-char-untabify
889
  "Function called by `c-electric-backspace' when deleting backwards."
Richard M. Stallman's avatar
Richard M. Stallman committed
890 891 892 893
  :type 'function
  :group 'c)

(defcustom c-delete-function 'delete-char
894
  "Function called by `c-electric-delete-forward' when deleting forwards."
Richard M. Stallman's avatar
Richard M. Stallman committed
895 896 897
  :type 'function
  :group 'c)

898
(defcustom c-require-final-newline
899
  ;; C and C++ mandate that all nonempty files should end with a
900
  ;; newline.  Objective-C refers to C for all things it doesn't
901
  ;; specify, so the same holds there.  The other languages do not
902 903 904 905
  ;; require it (at least not explicitly in a normative text).
  '((c-mode    . t)
    (c++-mode  . t)
    (objc-mode . t))
906
  "Controls whether a final newline is ensured when the file is saved.
907 908 909 910 911
The value is an association list that for each language mode specifies
the value to give to `require-final-newline' at mode initialization;
see that variable for details about the value.  If a language isn't
present on the association list, CC Mode won't touch
`require-final-newline' in buffers for that language."
912 913
  :type `(set (cons :format "%v"
		    (const :format "C     " c-mode)
914
		    (symbol :format "%v" :value ,require-final-newline))
915 916
	      (cons :format "%v"
		    (const :format "C++   " c++-mode)
917
		    (symbol :format "%v" :value ,require-final-newline))
918 919
	      (cons :format "%v"
		    (const :format "ObjC  " objc-mode)
920
		    (symbol :format "%v" :value ,require-final-newline))
921 922
	      (cons :format "%v"
		    (const :format "Java  " java-mode)
923
		    (symbol :format "%v" :value ,require-final-newline))
924 925
	      (cons :format "%v"
		    (const :format "IDL   " idl-mode)
926
		    (symbol :format "%v" :value ,require-final-newline))
927 928
	      (cons :format "%v"
		    (const :format "Pike  " pike-mode)
929 930 931 932
		    (symbol :format "%v" :value ,require-final-newline))
	      (cons :format "%v"
		    (const :format "AWK   " awk-mode)
		    (symbol :format "%v" :value ,require-final-newline)))
933 934
  :group 'c)

Richard M. Stallman's avatar
Richard M. Stallman committed
935
(defcustom c-electric-pound-behavior nil
936
  "List of behaviors for electric pound insertion.
Richard M. Stallman's avatar
Richard M. Stallman committed
937
Only currently supported behavior is `alignleft'."
938 939 940 941
  :type '(set (const alignleft))
  :group 'c)

(defcustom c-special-indent-hook nil
942
  "Hook for user defined special indentation adjustments.
943
This hook gets called after each line is indented by the mode.  It is only
944
called when `c-syntactic-indentation' is non-nil."
945
  :type 'hook
Richard M. Stallman's avatar
Richard M. Stallman committed
946 947
  :group 'c)

Gerd Moellmann's avatar
Gerd Moellmann committed
948
(defcustom-c-stylevar c-label-minimum-indentation 1
949
  "Minimum indentation for lines inside code blocks.
Richard M. Stallman's avatar
Richard M. Stallman committed
950
This variable typically only affects code using the `gnu' style, which
Martin Stjernholm's avatar
Martin Stjernholm committed
951 952 953
mandates a minimum of one space in front of every line inside code
blocks.  Specifically, the function `c-gnu-impose-minimum' on your
`c-special-indent-hook' is what enforces this."
Richard M. Stallman's avatar
Richard M. Stallman committed
954 955 956 957
  :type 'integer
  :group 'c)

(defcustom c-progress-interval 5
958
  "Interval used to update progress status during long re-indentation.
Richard M. Stallman's avatar
Richard M. Stallman committed
959
If a number, percentage complete gets updated after each interval of
960 961
that many seconds.  To inhibit all messages during indentation, set
this variable to nil."
Richard M. Stallman's avatar
Richard M. Stallman committed
962 963 964
  :type 'integer
  :group 'c)

965
(defcustom c-objc-method-arg-min-delta-to-bracket 2
966
  "Minimum number of chars to the opening bracket.
967 968 969 970 971 972 973 974 975 976 977 978 979

Consider this ObjC snippet:

	[foo blahBlah: fred
	|<-x->|barBaz: barney

If `x' is less than this number then `c-lineup-ObjC-method-call-colons'
will defer the indentation decision to the next function.  By default
this is `c-lineup-ObjC-method-call', which would align it like:

	[foo blahBlahBlah: fred
	     thisIsTooDamnLong: barney

Paul Eggert's avatar
Paul Eggert committed
980
This behavior can be overridden by customizing the indentation of
981 982 983 984 985
`objc-method-call-cont' in the \"objc\" style."
  :type 'integer
  :group 'c)

(defcustom c-objc-method-arg-unfinished-offset 4
986
  "Offset relative to bracket if first selector is on a new line.
987 988 989 990 991 992 993 994

    [aaaaaaaaa
    |<-x->|bbbbbbb:  cccccc
             ddddd: eeee];"
  :type 'integer
  :group 'c)

(defcustom c-objc-method-parameter-offset 4
995
  "Offset for selector parameter on a new line (relative to first selector.
996 997 998 999 1000 1001 1002 1003

    [aaaaaaa bbbbbbbbbb:
	     |<-x->|cccccccc
                    ddd: eeee
                   ffff: ggg];"
  :type 'integer
  :group 'c)

1004 1005
(defcustom c-default-style '((java-mode . "java") (awk-mode . "awk")
			     (other . "gnu"))
1006
  "Style which gets installed by default when a file is visited.
1007 1008

The value of this variable can be any style defined in
Barry A. Warsaw's avatar
Barry A. Warsaw committed
1009 1010 1011 1012
`c-style-alist', including styles you add.  The value can also be an
association list of major mode symbols to style names.

When the value is a string, all CC Mode major modes will install this
Gerd Moellmann's avatar
Gerd Moellmann committed
1013
style by default.
Barry A. Warsaw's avatar
Barry A. Warsaw committed
1014

Gerd Moellmann's avatar
Gerd Moellmann committed
1015 1016 1017 1018 1019 1020 1021 1022
When the value is an alist, the major mode symbol is looked up in it
and the associated style is installed.  If the major mode is not
listed in the alist, then the symbol `other' is looked up in it, and
if found, the style in that entry is used.  If `other' is not found in
the alist, then \"gnu\" style is used.

The default style gets installed before your mode hooks run, so you
can always override the use of `c-default-style' by making calls to
Gerd Moellmann's avatar
Gerd Moellmann committed
1023
`c-set-style' in the appropriate mode hook."
Gerd Moellmann's avatar
Gerd Moellmann committed
1024
  :type '(radio
Gerd Moellmann's avatar
Gerd Moellmann committed
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
	  (string :tag "Style in all modes")
	  (set :tag "Mode-specific styles"
	    (cons :format "%v"
		  (const :format "C     " c-mode) (string :format "%v"))
	    (cons :format "%v"
		  (const :format "C++   " c++-mode) (string :format "%v"))
	    (cons :format "%v"
		  (const :format "ObjC  " objc-mode) (string :format "%v"))
	    (cons :format "%v"
		  (const :format "Java  " java-mode) (string :format "%v"))
	    (cons :format "%v"
		  (const :format "IDL   " idl-mode) (string :format "%v"))
	    (cons :format "%v"
		  (const :format "Pike  " pike-mode) (string :format "%v"))
1039 1040
	    (cons :format "%v"
		  (const :format "AWK   " awk-mode) (string :format "%v"))
Gerd Moellmann's avatar
Gerd Moellmann committed
1041 1042
	    (cons :format "%v"
		  (const :format "Other " other) (string :format "%v"))))
Gerd Moellmann's avatar
Gerd Moellmann committed
1043 1044
  :group 'c)

1045 1046 1047 1048 1049 1050 1051 1052
;; *) At the start of a statement or declaration means in more detail:
;; At the closest preceding statement/declaration that starts at boi
;; and doesn't have a label or comment at that position.  If there's
;; no such statement within the same block, then back up to the
;; surrounding block or statement, add the appropriate
;; statement-block-intro, defun-block-intro or substatement syntax
;; symbol and continue searching.
(c-set-stylevar-fallback 'c-offsets-alist
Gerd Moellmann's avatar
Gerd Moellmann committed
1053
     '((string                . c-lineup-dont-change)
1054
       ;; Anchor pos: Beg of previous line.
Gerd Moellmann's avatar
Gerd Moellmann committed
1055
       (c                     . c-lineup-C-comments)
1056
       ;; Anchor pos: Beg of the comment.
Gerd Moellmann's avatar
Gerd Moellmann committed
1057
       (defun-open            . 0)
1058
       ;; Anchor pos: When inside a class: Boi at the func decl start.
1059 1060 1061
       ;; When at top level: Bol at the func decl start.  When inside
       ;; a code block (only possible in Pike): At the func decl
       ;; start(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1062
       (defun-close           . 0)
1063 1064
       ;; Anchor pos: At the defun block open if it's at boi,
       ;; otherwise boi at the func decl start.
Gerd Moellmann's avatar
Gerd Moellmann committed
1065
       (defun-block-intro     . +)
1066
       ;; Anchor pos: At the block open(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1067
       (class-open            . 0)
1068
       ;; Anchor pos: Boi at the class decl start.
Gerd Moellmann's avatar
Gerd Moellmann committed
1069
       (class-close           . 0)
1070
       ;; Anchor pos: Boi at the class decl start.
Gerd Moellmann's avatar
Gerd Moellmann committed
1071
       (inline-open           . +)
1072 1073
       ;; Anchor pos: None for functions (inclass got the relpos
       ;; then), boi at the lambda start for lambdas.
Gerd Moellmann's avatar
Gerd Moellmann committed
1074
       (inline-close          . 0)
1075 1076 1077 1078
       ;; Anchor pos: Inexpr functions: At the lambda block open if
       ;; it's at boi, else at the statement(*) at boi of the start of
       ;; the lambda construct.  Otherwise: At the inline block open
       ;; if it's at boi, otherwise boi at the func decl start.
Gerd Moellmann's avatar
Gerd Moellmann committed
1079
       (func-decl-cont        . +)
1080
       ;; Anchor pos: Boi at the func decl start.
Gerd Moellmann's avatar
Gerd Moellmann committed
1081
       (knr-argdecl-intro     . +)
1082
       ;; Anchor pos: Boi at the topmost intro line.
Gerd Moellmann's avatar
Gerd Moellmann committed
1083
       (knr-argdecl           . 0)
1084
       ;; Anchor pos: At the beginning of the first K&R argdecl.
1085
       (topmost-intro	      . 0)
1086
       ;; Anchor pos: Bol at the last line of previous construct.
1087
       (topmost-intro-cont    . c-lineup-topmost-intro-cont)
1088 1089 1090 1091
       ;;Anchor pos: Bol at the topmost annotation line
       (annotation-top-cont   .   0)
       ;;Anchor pos: Bol at the topmost annotation line
       (annotation-var-cont   .   +)
1092
       ;; Anchor pos: Boi at the topmost intro line.
Gerd Moellmann's avatar
Gerd Moellmann committed
1093
       (member-init-intro     . +)
1094
       ;; Anchor pos: Boi at the func decl arglist open.
1095
       (member-init-cont      . c-lineup-multi-inher)
1096
       ;; Anchor pos: Beg of the first member init.
Gerd Moellmann's avatar
Gerd Moellmann committed
1097
       (inher-intro           . +)
1098
       ;; Anchor pos: Boi at the class decl start.
Gerd Moellmann's avatar
Gerd Moellmann committed
1099
       (inher-cont            . c-lineup-multi-inher)
1100
       ;; Anchor pos: Java: At the implements/extends keyword start.
Gerd Moellmann's avatar
Gerd Moellmann committed
1101 1102 1103 1104
       ;; Otherwise: At the inher start colon, or boi at the class
       ;; decl start if the first inherit clause hangs and it's not a
       ;; func-local inherit clause (when does that occur?).
       (block-open            . 0)
1105 1106
       ;; Anchor pos: Inexpr statement: At the statement(*) at boi of
       ;; the start of the inexpr construct.  Otherwise: None.
Gerd Moellmann's avatar
Gerd Moellmann committed
1107
       (block-close           . 0)
1108 1109 1110 1111 1112
       ;; Anchor pos: Inexpr statement: At the inexpr block open if
       ;; it's at boi, else at the statement(*) at boi of the start of
       ;; the inexpr construct.  Block hanging on a case/default
       ;; label: At the closest preceding label that starts at boi.
       ;; Otherwise: At the block open(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1113
       (brace-list-open       . 0)
1114
       ;; Anchor pos: Boi at the brace list decl start, but a starting
Gerd Moellmann's avatar
Gerd Moellmann committed
1115 1116
       ;; "typedef" token is ignored.
       (brace-list-close      . 0)
1117
       ;; Anchor pos: At the brace list decl start(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1118
       (brace-list-intro      . +)
1119
       ;; Anchor pos: At the brace list decl start(*).
1120
       (brace-list-entry      . 0)
1121 1122
       ;; Anchor pos: At the first non-ws char after the open paren if
       ;; the first token is on the same line, otherwise boi at that
Gerd Moellmann's avatar
Gerd Moellmann committed
1123 1124
       ;; token.
       (brace-entry-open      . 0)
1125
       ;; Anchor pos: Same as brace-list-entry.
Gerd Moellmann's avatar
Gerd Moellmann committed
1126
       (statement             . 0)
1127
       ;; Anchor pos: After a `;' in the condition clause of a for
Gerd Moellmann's avatar
Gerd Moellmann committed
1128
       ;; statement: At the first token after the starting paren.
1129
       ;; Otherwise: At the preceding statement(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1130
       (statement-cont        . +)
1131 1132 1133
       ;; Anchor pos: After the first token in the condition clause of
       ;; a for statement: At the first token after the starting
       ;; paren.  Otherwise: At the containing statement(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1134
       (statement-block-intro . +)
1135 1136 1137
       ;; Anchor pos: In inexpr statement block: At the inexpr block
       ;; open if it's at boi, else at the statement(*) at boi of the
       ;; start of the inexpr construct.  In a block hanging on a
1138 1139 1140
       ;; case/default label: At the closest preceding label that
       ;; starts at boi.  Otherwise: At the start of the containing
       ;; block(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1141
       (statement-case-intro  . +)
1142
       ;; Anchor pos: At the case/default label(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1143
       (statement-case-open   . 0)
1144
       ;; Anchor pos: At the case/default label(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1145
       (substatement          . +)
1146
       ;; Anchor pos: At the containing statement(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1147
       (substatement-open     . +)
1148
       ;; Anchor pos: At the containing statement(*).
1149
       (substatement-label    . 2)
1150
       ;; Anchor pos: At the containing statement(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1151
       (case-label            . 0)
1152
       ;; Anchor pos: At the start of the switch block(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1153
       (access-label          . -)
1154
       ;; Anchor pos: Same as inclass.
Gerd Moellmann's avatar
Gerd Moellmann committed
1155
       (label                 . 2)
1156
       ;; Anchor pos: At the start of the containing block(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1157
       (do-while-closure      . 0)
1158
       ;; Anchor pos: At the corresponding while statement(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1159
       (else-clause           . 0)
1160
       ;; Anchor pos: At the corresponding if statement(*).
Gerd Moellmann's avatar
Gerd Moellmann committed
1161
       (catch-clause          . 0)
1162
       ;; Anchor pos: At the previous try or catch statement clause(*).
1163
       (comment-intro         . (c-lineup-knr-region-comment c-lineup-comment))
1164
       ;; Anchor pos: None.
Gerd Moellmann's avatar
Gerd Moellmann committed
1165
       (arglist-intro         . +)
1166 1167
       ;; Anchor pos: At the containing statement(*).
       ;; 2nd pos: At the open paren.
1168
       (arglist-cont          . (c-lineup-gcc-asm-reg 0))
1169
       ;; Anchor pos: At the first token after the open paren.
1170
       (arglist-cont-nonempty . (c-lineup-gcc-asm-reg c-lineup-arglist))
1171
       ;; Anchor pos: At the containing statement(*).
1172
       ;; 2nd pos: At the open paren.
Gerd Moellmann's avatar
Gerd Moellmann committed
1173
       (arglist-close         . +)
1174
       ;; Anchor pos: At the containing statement(*).
1175
       ;; 2nd pos: At the open paren.
Gerd Moellmann's avatar
Gerd Moellmann committed
1176
       (stream-op             . c-lineup-streamop)
1177
       ;; Anchor pos: Boi at the first stream op in the statement.
Gerd Moellmann's avatar
Gerd Moellmann committed
1178
       (inclass               . +)
1179 1180
       ;; Anchor pos: At the class open brace if it's at boi,
       ;; otherwise boi at the class decl start.
Gerd Moellmann's avatar
Gerd Moellmann committed
1181
       (cpp-macro             . [0])
1182
       ;; Anchor pos: None.
1183
       (cpp-macro-cont        . +)
1184
       ;; Anchor pos: At the macro start (always at boi).
1185
       (cpp-define-intro      . (c-lineup-cpp-define +))
Alan Mackenzie's avatar