From 38de11bd5a80cf3de1f0d8dfa90f5faef1c4e2f9 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Sat, 28 Sep 2013 17:17:01 +0000 Subject: [PATCH] Fix indentation/fontification of Java enum with "implements". * progmodes/cc-langs.el (c-postfix-decl-spec-key): New variable, a regexp which matches "implements", etc., in Java. * progmodes/cc-engine.el (c-inside-bracelist-p): Check for extra specifier clauses coming after "enum". * progmodes/cc-fonts.el (c-font-lock-declarations) (c-font-lock-enum-tail): Check for extra specifier clauses coming after "enum". --- lisp/ChangeLog | 12 ++++++++++++ lisp/progmodes/cc-engine.el | 26 ++++++++++++++----------- lisp/progmodes/cc-fonts.el | 47 ++++++++++++++++++++++++++++++--------------- lisp/progmodes/cc-langs.el | 6 ++++++ 4 files changed, 65 insertions(+), 26 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0affac1deaa..9a04acfa686 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2013-09-28 Alan Mackenzie + + Fix indentation/fontification of Java enum with "implements". + + * progmodes/cc-langs.el (c-postfix-decl-spec-key): New variable, a + regexp which matches "implements", etc., in Java. + * progmodes/cc-engine.el (c-inside-bracelist-p): Check for extra + specifier clauses coming after "enum". + * progmodes/cc-fonts.el (c-font-lock-declarations) + (c-font-lock-enum-tail): Check for extra specifier clauses coming + after "enum". + 2013-09-28 Jan Djärv * faces.el (region): Change ns_selection_color to diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index ce83efd114b..b3a6a0e3f03 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -8486,17 +8486,21 @@ comment at the start of cc-engine.el for more info." (or ;; This will pick up brace list declarations. (c-safe - (save-excursion - (goto-char containing-sexp) - (c-forward-sexp -1) - (let (bracepos) - (if (and (or (looking-at c-brace-list-key) - (progn (c-forward-sexp -1) - (looking-at c-brace-list-key))) - (setq bracepos (c-down-list-forward (point))) - (not (c-crosses-statement-barrier-p (point) - (- bracepos 2)))) - (point))))) + (save-excursion + (goto-char containing-sexp) + (let (before-identifier) + (while + (progn + (c-forward-sexp -1) + (cond + ((c-on-identifier) (setq before-identifier t)) + ((and before-identifier + (looking-at c-postfix-decl-spec-key)) + (setq before-identifier nil) + t) + ((looking-at c-brace-list-key) nil) + (t nil)))) + (looking-at c-brace-list-key)))) ;; this will pick up array/aggregate init lists, even if they are nested. (save-excursion (let ((class-key diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 4e8ce6bac28..4f9289c307d 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1471,13 +1471,22 @@ casts and declarations are fontified. Used on level 2 and higher." (let ((paren-state (c-parse-state))) (and (numberp (car paren-state)) - (save-excursion - (goto-char (car paren-state)) - (c-backward-token-2) - (or (looking-at c-brace-list-key) - (progn - (c-backward-token-2) - (looking-at c-brace-list-key))))))) + (c-safe + (save-excursion + (goto-char (car paren-state)) + (let (before-identifier) + (while + (progn + (c-forward-sexp -1) + (cond + ((c-on-identifier) (setq before-identifier t)) + ((and before-identifier + (looking-at c-postfix-decl-spec-key)) + (setq before-identifier nil) + t) + ((looking-at c-brace-list-key) nil) ; "enum" + (t nil)))) + (looking-at c-brace-list-key))))))) (c-forward-token-2) nil) @@ -1565,14 +1574,22 @@ casts and declarations are fontified. Used on level 2 and higher." (when (and encl-pos (eq (char-after encl-pos) ?\{) - (save-excursion - (goto-char encl-pos) - (c-backward-syntactic-ws) - (c-simple-skip-symbol-backward) - (or (looking-at c-brace-list-key) ; "enum" - (progn (c-backward-syntactic-ws) - (c-simple-skip-symbol-backward) - (looking-at c-brace-list-key))))) + (c-safe + (save-excursion + (goto-char encl-pos) + (let (before-identifier) + (while + (progn + (c-forward-sexp -1) + (cond + ((c-on-identifier) (setq before-identifier t)) + ((and before-identifier + (looking-at c-postfix-decl-spec-key)) + (setq before-identifier nil) + t) + ((looking-at c-brace-list-key) nil) ; "enum" + (t nil)))) + (looking-at c-brace-list-key))))) (c-syntactic-skip-backward "^{," nil t) (c-put-char-property (1- (point)) 'c-type 'c-decl-id-start) diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index c1e8a1524dc..bf72ab879af 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -2040,6 +2040,12 @@ declarations." ;; In CORBA PSDL: "as" "const" "implements" "of" "ref")) +(c-lang-defconst c-postfix-decl-spec-key + ;; Regexp matching the keywords in `c-postfix-decl-spec-kwds'. + t (c-make-keywords-re t (c-lang-const c-postfix-decl-spec-kwds))) +(c-lang-defvar c-postfix-decl-spec-key + (c-lang-const c-postfix-decl-spec-key)) + (c-lang-defconst c-nonsymbol-sexp-kwds "Keywords that may be followed by a nonsymbol sexp before whatever construct it's part of continues." -- 2.11.4.GIT