From 94ad13b93c6fc099a353c8eb27c00a68ee79a952 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Wed, 1 Feb 2017 20:20:09 +0000 Subject: Allow C++ nested brace-list-entries to be better indented. This fixes bug #24431. The key change of this bug fix is correctly analyzing nested brace lists when the opening element stands on the same line as both its introductory brace and an enclosing parameter list parenthesis. * list/progmodes/cc-align.el (c-lineup-under-anchor): New line-up function. * list/progmodes/cc-engine.el (c-looking-at-or-maybe-in-bracelist): Accept the presence of exactly an identifier between an open parenthesis and an open brace as evidence of the brace starting a brace list. (c-looking-at-statement-block): New function, extracted from c-looking-at-inexpr-block. Enhance it to analyze inner blocks recursively when needed. (c-looking-at-inexpr-block): Extract new function (see above) and call it. (c-add-stmt-syntax): Enhance, with new &optional parameter, to supply the prime syntactic symbol with a fixed anchor point. When this is used, restrict all added syntactic symbols to those having an anchor point on the same line. Add, in addition to the current additional symbols, c-brace-list-entry when needed; use c-looking-at-statement-block to determine the latter. (c-guess-basic-syntax, CASE 9D): Use c-add-stmt-syntax rather than just c-add-syntax, to assemble the syntactic context of a 'brace-list-entry, thus getting, possibly, several accompanying syntactic entries. * lisp/progmodes/cc-styles.el (c-style-alist, "gnu" style): New entry for 'brace-list-intro, namely c-lineup-arglist-intro-after-paren. * lisp/progmodes/cc-vars.el (c-offsets-alist): Change the factory default offset for 'brace-list-entry from 0 to c-lineup-under-anchor. * doc/misc/cc-mode.texi (Syntactic Symbols): Amend the definition of brace-list-intro. (Brace List Symbols): Amend the example to show the new analysis of brace lists when the first element comes on the same line as the opening brace. (Misc Line-Up): Document the new line-up function c-lineup-under-anchor. --- lisp/progmodes/cc-align.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lisp/progmodes/cc-align.el') diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el index 7cb36c4396b..0f7e4b598dc 100644 --- a/lisp/progmodes/cc-align.el +++ b/lisp/progmodes/cc-align.el @@ -1221,6 +1221,18 @@ Works with: arglist-cont, arglist-cont-nonempty." (vector (progn (goto-char alignto) (current-column))))))) +(defun c-lineup-under-anchor (langelem) + "Line up the current line directly under the anchor position in LANGELEM. + +This is like 0, except it supersedes any indentation already calculated for +previous syntactic elements in the syntactic context. + +Works with: Any syntactic symbol which has an anchor position." + (save-excursion + (goto-char (c-langelem-pos langelem)) + (vector (current-column)))) + + (defun c-lineup-dont-change (langelem) "Do not change the indentation of the current line. -- cgit v1.2.1