From 8dd588b1fb51bb9178bf34a6be9f35de84e95045 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Tue, 2 Mar 2021 20:31:36 +0000 Subject: CC Mode: Fix analysis of brace lists, particularly in C++ Mode Fix some alignment functionality in cc-align.el. * lisp/progmodes/cc-align.el (c-lineup-arglist-intro-after-paren): Align the next line under the previous entry rather than one to the right of the paren. (c-lineup-2nd-brace-entry-in-arglist): Take the anchor point from the brace-list-entry element, not the brace-list-intro one. * lisp/progmodes/cc-engine.el (c-looking-at-decl-block): Use c-looking-at-statement-block to test whether "struct A {" begins a brace list or a struct declaration. (c-looking-at-or-maybe-in-bracelist): Several detailed amendments, correctly to recognize brace lists. (c-looking-at-statement-block): No longer search for commas, as they are not reliable indicators of a brace list. Search now for a restricted set of keywords, since some can appear in brace lists in C++ mode. * lisp/progmodes/cc-langs.el (c-stmt-block-only-keywords) (c-stmt-block-only-keywords-regexp): New lang consts/vars. (c-pre-id-bracelist-kwds): New lang const. (c-pre-id-bracelist-key): Derive now from the above. (c-pre-brace-non-bracelist-key): New lang const/var. --- lisp/progmodes/cc-align.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lisp/progmodes/cc-align.el') diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el index d14ef1744af..51d51deef71 100644 --- a/lisp/progmodes/cc-align.el +++ b/lisp/progmodes/cc-align.el @@ -274,8 +274,10 @@ statement-block-intro, statement-case-intro, arglist-intro." (save-excursion (beginning-of-line) (backward-up-list 1) + (forward-char) (skip-chars-forward " \t" (c-point 'eol)) - (vector (1+ (current-column))))) + (if (eolp) (skip-chars-backward " \t")) + (vector (current-column)))) (defun c-lineup-arglist-close-under-paren (langelem) "Line up a line under the enclosing open paren. @@ -1145,7 +1147,8 @@ Works with brace-list-intro." ; the line. (save-excursion ; "{" earlier on the line (goto-char (c-langelem-pos - (assq 'brace-list-intro c-syntactic-context))) + (assq 'brace-list-entry + c-syntactic-context))) (and (eq (c-backward-token-2 1 nil -- cgit v1.2.3