mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Correct the indentation of CC Mode brace lists
while preserving the indentation of nested C++ uniform initialization. * lisp/progmodes/cc-align.el (c-lineup-2nd-brace-entry-in-arglist) (c-lineup-class-decl-init-+, c-lineup-class-decl-init-after-brace): New indentation functions. * lisp/progmodes/cc-engine.el (c-forward-class-decl): New function. (c-do-declarators): New function, partially extracted from c-font-lock-declarators, which now calls the new function. (c-inside-bracelist-p): Amend the introductory comment. (c-add-stmt-syntax): Add code to prevent the spurious recognition of a 'defun-block-intro when a brace pair is used as an initializer. (c-evaluate-offset): No longer ignore vectors of length >= 2. (c-calc-offset): Refactor clumsily nested `if'/`or' into a cond form. * lisp/progmodes/cc-fonts.el (c-font-lock-declarators): Replace the bulk of this function by a call to the new c-forward-class-decl. * lisp/progmodes/cc-langs.el (c-type-decl-prefix-key): Recognize "~" as a type decl operator. * lisp/progmodes/cc-mode.el (c-fl-decl-start): While searching backward for a "}" at an EOD, deal with actually finding the end of a brace list. * doc/misc/cc-mode.texi (List Line-Up): document c-lineup-2nd-brace-entry-in-arglist, c-lineup-class-decl-init-+, and c-lineup-class-decl-init-after-brace. * lisp/progmodes/cc-styles.el (c-style-alist): In styles "gnu", "bsd", "stroustrup", "python", and "java", change the offset for brace-list-intro from the default value or c-lineup-arglist-intro-after-paren to a list beginning with the symbol first, followed by two of the new alignment functions, followed by +. * lisp/progmodes/cc-vars.el (c-offset-alist): Change the default value of brace-list-entry from c-lineup-under-anchor back to 0.
This commit is contained in:
parent
d58c29b345
commit
aa1a4cceca
8 changed files with 524 additions and 170 deletions
|
|
@ -5638,9 +5638,9 @@ any problems writing custom line-up functions for AWK mode.
|
|||
|
||||
The calling convention for line-up functions is described fully in
|
||||
@ref{Custom Line-Up}. Roughly speaking, the return value is either an
|
||||
offset itself (such as @code{+} or @code{[0]}) or it's @code{nil},
|
||||
meaning ``this function is inappropriate in this case; try a
|
||||
different one''. @xref{c-offsets-alist}.
|
||||
offset itself (such as @code{+} or @code{[0]}), another line-up
|
||||
function, or it's @code{nil}, meaning ``this function is inappropriate
|
||||
in this case - try a different one''. @xref{c-offsets-alist}.
|
||||
|
||||
The subsections below describe all the standard line-up functions,
|
||||
categorized by the sort of token the lining-up centers around. For
|
||||
|
|
@ -5995,6 +5995,125 @@ brace block.
|
|||
|
||||
@comment ------------------------------------------------------------
|
||||
|
||||
@defun c-lineup-2nd-brace-entry-in-arglist
|
||||
@findex lineup-2nd-brace-entry-in-arglist (c-)
|
||||
Line up the second entry of a brace block under the first, when the
|
||||
first line is also contained in an arglist or an enclosing brace
|
||||
@emph{on that line}.
|
||||
|
||||
I.e. handle something like the following:
|
||||
|
||||
@example
|
||||
@group
|
||||
set_line (line_t @{point_t@{0.4, 0.2@},
|
||||
point_t@{0.2, 0.5@}, @hereFn{brace-list-intro}
|
||||
.....@});
|
||||
^ enclosing parenthesis.
|
||||
@end group
|
||||
@end example
|
||||
|
||||
|
||||
The middle line of that example will have a syntactic context with
|
||||
three syntactic symbols, @code{arglist-cont-nonempty},
|
||||
@code{brace-list-intro}, and @code{brace-list-entry} (@pxref{Brace
|
||||
List Symbols}).
|
||||
|
||||
This function is intended for use in a list. If the construct being
|
||||
analyzed isn't like the preceding, the function returns nil.
|
||||
Otherwise it returns the function
|
||||
@code{c-lineup-arglist-intro-after-paren}, which the caller then uses
|
||||
to perform indentation.
|
||||
|
||||
@workswith{} @code{brace-list-intro}.
|
||||
@end defun
|
||||
|
||||
@comment ------------------------------------------------------------
|
||||
|
||||
@defun c-lineup-class-decl-init-+
|
||||
@findex lineup-class-decl-init-+ (c-)
|
||||
Line up the second entry of a class (etc.) initializer
|
||||
@code{c-basic-offset} characters in from the identifier when:
|
||||
@enumerate
|
||||
@item
|
||||
The type is a class, struct, union, etc. (but not an enum);
|
||||
@item
|
||||
There is a brace block in the type declaration, specifying it; and
|
||||
@item
|
||||
The first element of the initializer is on the same line as its
|
||||
opening brace.
|
||||
@end enumerate
|
||||
|
||||
I.e. we have a construct like this:
|
||||
|
||||
@example
|
||||
@group
|
||||
struct STR @{
|
||||
int i; float f;
|
||||
@} str_1 = @{1, 1.7@},
|
||||
str_2 = @{2,
|
||||
3.1 @hereFn{brace-list-intro}
|
||||
@};
|
||||
@sssTBasicOffset{}
|
||||
@end group
|
||||
@end example
|
||||
|
||||
|
||||
Note that the syntactic context of the @code{brace-list-intro} line
|
||||
also has a syntactic element with the symbol @code{brace-list-entry}
|
||||
(@pxref{Brace List Symbols}).
|
||||
|
||||
This function is intended for use in a list. If the above structure
|
||||
isn't present, the function returns nil, allowing a different offset
|
||||
specification to indent the line.
|
||||
|
||||
@workswith{} @code{brace-list-intro}.
|
||||
@end defun
|
||||
|
||||
@comment ------------------------------------------------------------
|
||||
|
||||
@defun c-lineup-class-decl-init-after-brace
|
||||
@findex lineup-class-decl-init-after-brace (c-)
|
||||
Line up the second entry of a class (etc.) initializer after its
|
||||
opening brace when:
|
||||
@enumerate
|
||||
@item
|
||||
The type is a class, struct, union, etc. (but not an enum);
|
||||
@item
|
||||
There is a brace block in the type declaration, specifying it; and
|
||||
@item
|
||||
The first element of the initializer is on the same line as its
|
||||
opening brace.
|
||||
@end enumerate
|
||||
|
||||
I.e. we have a construct like this:
|
||||
|
||||
@example
|
||||
@group
|
||||
struct STR @{
|
||||
int i; float f;
|
||||
@} str_1 = @{1, 1.7@},
|
||||
str_2 = @{2,
|
||||
3.1 @hereFn{brace-list-intro}
|
||||
@};
|
||||
@end group
|
||||
@end example
|
||||
|
||||
|
||||
Note that the syntactic context of the @code{brace-list-intro} line
|
||||
also has a syntactic element with the symbol @code{brace-list-entry}
|
||||
(@pxref{Brace List Symbols}). Also note that this function works by
|
||||
returning the symbol @code{c-lineup-arglist-intro-after-paren}, which
|
||||
the caller then uses to perform the indentation.
|
||||
|
||||
This function is intended for use in a list. If the above structure
|
||||
isn't present, the function returns nil, allowing a different offset
|
||||
specification to indent the line.
|
||||
|
||||
@workswith{} @code{brace-list-intro}.
|
||||
@end defun
|
||||
|
||||
@comment ------------------------------------------------------------
|
||||
|
||||
@defun c-lineup-multi-inher
|
||||
@findex lineup-multi-inher @r{(c-)}
|
||||
Line up the classes in C++ multiple inheritance clauses and member
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue