Fix indentation/fontification of Java enum with "implements"/generic.
authorAlan Mackenzie <acm@muc.de>
Sun, 13 Oct 2013 19:54:46 +0000 (19:54 +0000)
committerAlan Mackenzie <acm@muc.de>
Sun, 13 Oct 2013 19:54:46 +0000 (19:54 +0000)
* 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
lisp/progmodes/cc-engine.el
lisp/progmodes/cc-fonts.el

index 1abd048..e3f3215 100644 (file)
@@ -1,3 +1,15 @@
+2013-10-13  Alan Mackenzie  <acm@muc.de>
+
+       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  <handa@gnu.org>
 
        * international/mule-cmds.el (select-safe-coding-system): Remove a
index b3a6a0e..d624d1e 100644 (file)
@@ -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
index 4f9289c..bcd4a5f 100644 (file)
@@ -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)