GNU bug report logs -
#15465
CC-mode misaligns enums that implement an interface in Java
Previous Next
Reported by: Paul Pogonyshev <pogonyshev <at> gmail.com>
Date: Thu, 26 Sep 2013 08:32:02 UTC
Severity: normal
Fixed in version 24.4
Done: Glenn Morris <rgm <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15465 in the body.
You can then email your comments to 15465 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#15465
; Package
emacs
.
(Thu, 26 Sep 2013 08:32:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Paul Pogonyshev <pogonyshev <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Thu, 26 Sep 2013 08:32:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Since Java mode finally got some improvements recently, maybe someone can
solve this too. In Java, enumerations can implement interfaces. However,
CC-mode doesn't handle that well. Compare this indentation, for example:
public enum X
{
A,
B;
}
vs.
public enum X implements Y
{
A,
B;
}
Fontification of 'A' and 'B' also changes when I add 'implements' keyword.
Paul
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#15465
; Package
emacs
.
(Sat, 28 Sep 2013 17:36:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 15465 <at> debbugs.gnu.org (full text, mbox):
Hi, Paul.
Paul Pogonyshev <pogonyshev <at> gmail.com>, wrote:
> Since Java mode finally got some improvements recently, maybe someone
> can solve this too. In Java, enumerations can implement interfaces.
> However, CC-mode doesn't handle that well. Compare this indentation,
> for example:
> public enum X
> {
> A,
> B;
> }
> vs.
> public enum X implements Y
> {
> A,
> B;
> }
Yes, that is a bug. It happens because the code that checks for being
inside an "enum" body only searches a maximum of two tokens backwards from
the "{" for the "enum" keyword.
> Fontification of 'A' and 'B' also changes when I add 'implements'
> keyword.
This was happening on any buffer change near the "{" for basically the
same reason.
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.
Thanks for taking the trouble to report this, and thanks even more that
the report was so crisp, concise and to the point.
Paul
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#15465
; Package
emacs
.
(Sat, 28 Sep 2013 19:16:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 15465 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> 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;
}
Paul
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#15465
; Package
emacs
.
(Sat, 28 Sep 2013 21:35:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 15465 <at> debbugs.gnu.org (full text, mbox):
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;
> }
OK!
I think the following enhancement should help out here:
diff -r d51d11733869 cc-engine.el
--- a/cc-engine.el Sat Sep 28 16:39:26 2013 +0000
+++ b/cc-engine.el Sat Sep 28 21:27:53 2013 +0000
@@ -8534,6 +8534,10 @@
(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))))
(looking-at c-brace-list-key))))
;; this will pick up array/aggregate init lists, even if they are nested.
diff -r d51d11733869 cc-fonts.el
--- a/cc-fonts.el Sat Sep 28 16:39:26 2013 +0000
+++ b/cc-fonts.el Sat Sep 28 21:27:53 2013 +0000
@@ -1452,6 +1452,10 @@
(setq before-identifier nil)
t)
((looking-at c-brace-list-key) nil) ; "enum"
+ ((and c-recognize-<>-arglists
+ (eq (char-after) ?<)
+ (looking-at "\\s("))
+ t)
(t nil))))
(looking-at c-brace-list-key)))))))
(c-forward-token-2)
@@ -1556,6 +1560,10 @@
(setq before-identifier nil)
t)
((looking-at c-brace-list-key) nil) ; "enum"
+ ((and c-recognize-<>-arglists
+ (eq (char-after) ?<)
+ (looking-at "\\s("))
+ t)
(t nil))))
(looking-at c-brace-list-key)))))
(c-syntactic-skip-backward "^{," nil t)
> Paul
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#15465
; Package
emacs
.
(Sun, 29 Sep 2013 15:06:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 15465 <at> debbugs.gnu.org (full text, mbox):
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).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#15465
; Package
emacs
.
(Mon, 30 Sep 2013 07:24:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 15465 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Sorry, it doesn't apply.
Paul
On 29 September 2013 17:03, Alan Mackenzie <acm <at> muc.de> wrote:
> 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).
>
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#15465
; Package
emacs,cc-mode
.
(Sun, 13 Oct 2013 21:41:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 15465 <at> debbugs.gnu.org (full text, mbox):
Hello, Paul.
On Mon, Sep 30, 2013 at 09:23:53AM +0200, Paul Pogonyshev wrote:
> Sorry, it doesn't apply.
I don't understand what's gone wrong here. Anyway, I've just committed
that patch to the Emacs trunk (revision #114650). Perhaps you could try
out this latest fix too, and let me know if there are any more problems
in this area. Thanks!
> Paul
--
Alan Mackenzie (Nuremberg, Germany).
> On 29 September 2013 17:03, Alan Mackenzie <acm <at> muc.de> wrote:
>
> > 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.
> >
> >
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#15465
; Package
emacs,cc-mode
.
(Mon, 14 Oct 2013 09:20:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 15465 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Um, it seems to be worse than before. I guess your first patch worked
better, at least for my cases.
E.g. now I have:
public enum X implements Y, Z
{
A,
B;
}
On a side note, enum methods (and constructors --- yes, enums can
optionally have those) are fontified as variable names, though that is of
course less important than indentation.
Paul
On 13 October 2013 23:38, Alan Mackenzie <acm <at> muc.de> wrote:
> Hello, Paul.
>
> On Mon, Sep 30, 2013 at 09:23:53AM +0200, Paul Pogonyshev wrote:
> > Sorry, it doesn't apply.
>
> I don't understand what's gone wrong here. Anyway, I've just committed
> that patch to the Emacs trunk (revision #114650). Perhaps you could try
> out this latest fix too, and let me know if there are any more problems
> in this area. Thanks!
>
> > Paul
>
> --
> Alan Mackenzie (Nuremberg, Germany).
>
>
> > On 29 September 2013 17:03, Alan Mackenzie <acm <at> muc.de> wrote:
> >
> > > 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.
> > >
> > >
>
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#15465
; Package
emacs,cc-mode
.
(Sun, 20 Oct 2013 14:40:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 15465 <at> debbugs.gnu.org (full text, mbox):
Hello, Paul.
On Mon, Oct 14, 2013 at 11:19:39AM +0200, Paul Pogonyshev wrote:
> Um, it seems to be worse than before. I guess your first patch worked
> better, at least for my cases.
> E.g. now I have:
> public enum X implements Y, Z
> {
> A,
> B;
> }
Ah, yes, comma separated lists. I've committed another fix, revision
#114729, that perhaps gets it right now. Would you please do the usual.
> On a side note, enum methods (and constructors --- yes, enums can
> optionally have those) are fontified as variable names, though that is of
> course less important than indentation.
It still needs to be fixed. Thanks for the pointer.
> Paul
--
Alan Mackenzie (Nuremberg, Germany).
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#15465
; Package
emacs,cc-mode
.
(Mon, 21 Oct 2013 11:01:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 15465 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Yes, now it works fine on my real code. Thank you.
Paul
On 20 October 2013 16:37, Alan Mackenzie <acm <at> muc.de> wrote:
> Hello, Paul.
>
> On Mon, Oct 14, 2013 at 11:19:39AM +0200, Paul Pogonyshev wrote:
> > Um, it seems to be worse than before. I guess your first patch worked
> > better, at least for my cases.
>
> > E.g. now I have:
>
> > public enum X implements Y, Z
> > {
> > A,
> > B;
> > }
>
> Ah, yes, comma separated lists. I've committed another fix, revision
> #114729, that perhaps gets it right now. Would you please do the usual.
>
> > On a side note, enum methods (and constructors --- yes, enums can
> > optionally have those) are fontified as variable names, though that is of
> > course less important than indentation.
>
> It still needs to be fixed. Thanks for the pointer.
>
> > Paul
>
> --
> Alan Mackenzie (Nuremberg, Germany).
>
[Message part 2 (text/html, inline)]
bug marked as fixed in version 24.4, send any further explanations to
15465 <at> debbugs.gnu.org and Paul Pogonyshev <pogonyshev <at> gmail.com>
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Mon, 21 Oct 2013 22:06:01 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org
:
bug#15465
; Package
emacs,cc-mode
.
(Fri, 25 Oct 2013 20:32:01 GMT)
Full text and
rfc822 format available.
Message #37 received at 15465-done <at> debbugs.gnu.org (full text, mbox):
Bug fixed.
--
Alan Mackenzie (Nuremberg, Germany).
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 23 Nov 2013 12:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 11 years and 253 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.