Variable: c-indent-comment-alist
c-indent-comment-alist is a customizable and buffer-local variable
defined in cc-vars.el.gz.
Documentation
Specifies how M-x indent-for-comment (indent-for-comment) calculates the comment start column.
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 M-x indent-for-comment (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 M-x indent-for-comment (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 M-x indent-for-comment (indent-for-comment) indents the comment
according to comment-column.
Note that a non-nil value on c-indent-comments-syntactically-p
overrides this variable, so empty lines are indented syntactically
in that case, i.e. as if M-x c-indent-command (c-indent-command) was used instead.
This is a style variable. Apart from the valid values described
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
c-style-alist) when a CC Mode buffer is initialized. Otherwise,
the value set here overrides the style system (there is a variable
c-old-style-variable-behavior that changes this, though).
Probably introduced at or before Emacs version 22.1.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-vars.el.gz
(defcustom-c-stylevar c-indent-comment-alist
'((anchored-comment . (column . 0))
(end-block . (space . 1))
(cpp-end-block . (space . 2)))
"Specifies how \\[indent-for-comment] calculates the comment start column.
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'
overrides this variable, so empty lines are indented syntactically
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"
,(c-constant-symbol elt 20)
(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)