From 7a068717166757eacc702cb499dc803be0645211 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Sun, 13 Oct 2013 19:54:46 +0000 Subject: [PATCH] Fix indentation/fontification of Java enum with "implements"/generic. * progmodes/cc-engine.el (c-backward-over-enum-header): Extracted from the three other places and enhanced to handle generics. (c-inside-bracelist-p): Uses new function above. * progmodes/cc-fonts.el (c-font-lock-declarations): Uses new function above. (c-font-lock-enum-tail): Uses new function above. --- lisp/ChangeLog | 12 ++++++++++++ lisp/progmodes/cc-engine.el | 45 +++++++++++++++++++++++++++++---------------- lisp/progmodes/cc-fonts.el | 38 ++++++-------------------------------- 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1abd0482ec6..e3f32150ee6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2013-10-13 Alan Mackenzie + + Fix indentation/fontification of Java enum with + "implements"/generic. + + * progmodes/cc-engine.el (c-backward-over-enum-header): Extracted + from the three other places and enhanced to handle generics. + (c-inside-bracelist-p): Uses new function above. + * progmodes/cc-fonts.el (c-font-lock-declarations): Uses new + function above. + (c-font-lock-enum-tail): Uses new function above. + 2013-10-13 Kenichi Handa * international/mule-cmds.el (select-safe-coding-system): Remove a diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index b3a6a0e3f03..d624d1eaed2 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -8471,6 +8471,32 @@ comment at the start of cc-engine.el for more info." (not (looking-at "="))))) b-pos))) +(defun c-backward-over-enum-header () + ;; We're at a "{". Move back to the enum-like keyword that starts this + ;; declaration and return t, otherwise don't move and return nil. + (let ((here (point)) + up-sexp-pos before-identifier) + (while + (and + (eq (c-backward-token-2) 0) + (or (not (looking-at "\\s)")) + (c-go-up-list-backward)) + (cond + ((and (looking-at c-symbol-key) (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) + ((and c-recognize-<>-arglists + (eq (char-after) ?<) + (looking-at "\\s(")) + t) + (t nil)))) + (or (looking-at c-brace-list-key) + (progn (goto-char here) nil)))) + (defun c-inside-bracelist-p (containing-sexp paren-state) ;; return the buffer position of the beginning of the brace list ;; statement if we're inside a brace list, otherwise return nil. @@ -8485,22 +8511,9 @@ comment at the start of cc-engine.el for more info." ;; This function might do hidden buffer changes. (or ;; This will pick up brace list declarations. - (c-safe - (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)))) + (save-excursion + (goto-char containing-sexp) + (c-backward-over-enum-header)) ;; 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 4f9289c307d..bcd4a5f28f8 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1471,22 +1471,9 @@ casts and declarations are fontified. Used on level 2 and higher." (let ((paren-state (c-parse-state))) (and (numberp (car paren-state)) - (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))))))) + (save-excursion + (goto-char (car paren-state)) + (c-backward-over-enum-header))))) (c-forward-token-2) nil) @@ -1574,22 +1561,9 @@ casts and declarations are fontified. Used on level 2 and higher." (when (and encl-pos (eq (char-after encl-pos) ?\{) - (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))))) + (save-excursion + (goto-char encl-pos) + (c-backward-over-enum-header))) (c-syntactic-skip-backward "^{," nil t) (c-put-char-property (1- (point)) 'c-type 'c-decl-id-start) -- 2.11.4.GIT