[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 356fb18: CC Mode: fix indentation in switch stateme
From: |
Alan Mackenzie |
Subject: |
[Emacs-diffs] master 356fb18: CC Mode: fix indentation in switch statement after "case a(1):". |
Date: |
Wed, 15 May 2019 05:00:38 -0400 (EDT) |
branch: master
commit 356fb18a1f64e58559fef92016be258b8cc70753
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>
CC Mode: fix indentation in switch statement after "case a(1):".
* lisp/progmodes/cc-engine.el (c-beginning-of-statement-1): Enhance the
analysis of case labels to handle parenthesised expressions (e.g. macros).
* lisp/progmodes/cc-langs.el (c-nonlabel-nonparen-token-key): New lang const
and lang var.
---
lisp/progmodes/cc-engine.el | 12 ++++++++++--
lisp/progmodes/cc-langs.el | 25 +++++++++++++++++++++++++
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index a25d059..ed8310d 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -1253,12 +1253,20 @@ comment at the start of cc-engine.el for more info."
;; (including a case label) or something like C++'s "public:"?
;; A case label might use an expression rather than a token.
(setq after-case:-pos (or tok start))
- (if (or (looking-at c-nonlabel-token-key) ; e.g. "while" or
"'a'"
+ (if (or (looking-at c-nonlabel-nonparen-token-key)
+ ; e.g. "while" or "'a'"
;; Catch C++'s inheritance construct "class foo :
bar".
(save-excursion
(and
(c-safe (c-backward-sexp) t)
- (looking-at c-nonlabel-token-2-key))))
+ (looking-at c-nonlabel-token-2-key)))
+ ;; Catch C++'s "case a(1):"
+ (and (c-major-mode-is 'c++-mode)
+ (eq (char-after) ?\()
+ (save-excursion
+ (not (and
+ (zerop (c-backward-token-2 2))
+ (looking-at c-case-kwds-regexp))))))
(setq c-maybe-labelp nil)
(if after-labels-pos ; Have we already encountered a label?
(if (not last-label-pos)
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 8b7e4ef..30da10a 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -3674,6 +3674,31 @@ i.e. before \":\". Only used if
`c-recognize-colon-labels' is set."
c++ (concat "\\s(\\|\"\\|" (c-lang-const c-nonlabel-token-key)))
(c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
+(c-lang-defconst c-nonlabel-nonparen-token-key
+ "Regexp matching things that can't occur in generic colon labels,
+neither in a statement nor in a declaration context, with the
+exception of an open parenthesis. The regexp is tested at the
+beginning of every sexp in a suspected label, i.e. before \":\".
+Only used if `c-recognize-colon-labels' is set."
+ ;; This lang const is the same as `c-nonlabel-token-key', except for a
+ ;; slight difference in the c++-mode value.
+ t (concat
+ ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
+ (c-make-keywords-re t
+ (c--set-difference (c-lang-const c-keywords)
+ (append (c-lang-const c-label-kwds)
+ (c-lang-const c-protection-kwds))
+ :test 'string-equal)))
+ ;; Don't allow string literals, except in AWK and Java. Character constants
are OK.
+ (c objc pike idl) (concat "\"\\|"
+ (c-lang-const c-nonlabel-nonparen-token-key))
+ ;; Also check for open parens in C++, to catch member init lists in
+ ;; constructors. We normally allow it so that macros with arguments
+ ;; work in labels.
+ c++ (concat "[{[]\\|\"\\|" (c-lang-const c-nonlabel-nonparen-token-key)))
+(c-lang-defvar c-nonlabel-nonparen-token-key
+ (c-lang-const c-nonlabel-nonparen-token-key))
+
(c-lang-defconst c-nonlabel-token-2-key
"Regexp matching things that can't occur two symbols before a colon in
a label construct. This catches C++'s inheritance construct \"class foo
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 356fb18: CC Mode: fix indentation in switch statement after "case a(1):".,
Alan Mackenzie <=