[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#15465: CC-mode misaligns enums that implement an interface in Java
From: |
Alan Mackenzie |
Subject: |
bug#15465: CC-mode misaligns enums that implement an interface in Java |
Date: |
Sun, 29 Sep 2013 15:03:45 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi, Paul.
On Sat, Sep 28, 2013 at 09:15:52PM +0200, Paul Pogonyshev wrote:
> > I've committed a fix, revision #114474, to the bzr trunk. Could you try
> > out the change, please, and either confirm it fixes the bug properly, or
> > tell me what hasn't yet been fixed.
> Thank you. The case I initially mentioned works properly now, also with
> multiple implemented interfaces. However, it seems to not know about
> interfaces with generics:
> public enum X implements Y <Z>
> {
> A,
> B;
> }
Here's a better patch than the one from last night, which was
demonstrably buggy. It should apply cleanly to the current trunk.
Please let me know how thoroughly it works.
diff -r d51d11733869 cc-engine.el
--- a/cc-engine.el Sat Sep 28 16:39:26 2013 +0000
+++ b/cc-engine.el Sun Sep 29 14:57:33 2013 +0000
@@ -8506,6 +8506,32 @@
(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.
@@ -8520,22 +8546,9 @@
;; 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 -r d51d11733869 cc-fonts.el
--- a/cc-fonts.el Sat Sep 28 16:39:26 2013 +0000
+++ b/cc-fonts.el Sun Sep 29 14:57:33 2013 +0000
@@ -1438,22 +1438,9 @@
(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)
@@ -1542,22 +1529,9 @@
(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)
> Paul
--
Alan Mackenzie (Nuremberg, Germany).