* bug#15465: CC-mode misaligns enums that implement an interface in Java @ 2013-09-26 8:31 Paul Pogonyshev 2013-09-28 17:33 ` Alan Mackenzie 0 siblings, 1 reply; 11+ messages in thread From: Paul Pogonyshev @ 2013-09-26 8:31 UTC (permalink / raw) To: 15465 [-- Attachment #1: Type: text/plain, Size: 390 bytes --] 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 [-- Attachment #2: Type: text/html, Size: 566 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#15465: CC-mode misaligns enums that implement an interface in Java 2013-09-26 8:31 bug#15465: CC-mode misaligns enums that implement an interface in Java Paul Pogonyshev @ 2013-09-28 17:33 ` Alan Mackenzie 2013-09-28 19:15 ` Paul Pogonyshev 0 siblings, 1 reply; 11+ messages in thread From: Alan Mackenzie @ 2013-09-28 17:33 UTC (permalink / raw) To: Paul Pogonyshev; +Cc: 15465 Hi, Paul. Paul Pogonyshev <pogonyshev@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). ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#15465: CC-mode misaligns enums that implement an interface in Java 2013-09-28 17:33 ` Alan Mackenzie @ 2013-09-28 19:15 ` Paul Pogonyshev 2013-09-28 21:33 ` Alan Mackenzie 2013-09-29 15:03 ` Alan Mackenzie 0 siblings, 2 replies; 11+ messages in thread From: Paul Pogonyshev @ 2013-09-28 19:15 UTC (permalink / raw) To: Alan Mackenzie; +Cc: 15465 [-- Attachment #1: Type: text/plain, Size: 417 bytes --] > 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 [-- Attachment #2: Type: text/html, Size: 553 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#15465: CC-mode misaligns enums that implement an interface in Java 2013-09-28 19:15 ` Paul Pogonyshev @ 2013-09-28 21:33 ` Alan Mackenzie 2013-09-29 15:03 ` Alan Mackenzie 1 sibling, 0 replies; 11+ messages in thread From: Alan Mackenzie @ 2013-09-28 21:33 UTC (permalink / raw) To: Paul Pogonyshev; +Cc: 15465 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). ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#15465: CC-mode misaligns enums that implement an interface in Java 2013-09-28 19:15 ` Paul Pogonyshev 2013-09-28 21:33 ` Alan Mackenzie @ 2013-09-29 15:03 ` Alan Mackenzie 2013-09-30 7:23 ` Paul Pogonyshev 1 sibling, 1 reply; 11+ messages in thread From: Alan Mackenzie @ 2013-09-29 15:03 UTC (permalink / raw) To: Paul Pogonyshev; +Cc: 15465 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). ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#15465: CC-mode misaligns enums that implement an interface in Java 2013-09-29 15:03 ` Alan Mackenzie @ 2013-09-30 7:23 ` Paul Pogonyshev 2013-10-13 21:38 ` Alan Mackenzie 0 siblings, 1 reply; 11+ messages in thread From: Paul Pogonyshev @ 2013-09-30 7:23 UTC (permalink / raw) To: Alan Mackenzie; +Cc: 15465 [-- Attachment #1: Type: text/plain, Size: 5706 bytes --] Sorry, it doesn't apply. Paul On 29 September 2013 17:03, Alan Mackenzie <acm@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). > [-- Attachment #2: Type: text/html, Size: 7588 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#15465: CC-mode misaligns enums that implement an interface in Java 2013-09-30 7:23 ` Paul Pogonyshev @ 2013-10-13 21:38 ` Alan Mackenzie 2013-10-14 9:19 ` Paul Pogonyshev 0 siblings, 1 reply; 11+ messages in thread From: Alan Mackenzie @ 2013-10-13 21:38 UTC (permalink / raw) To: Paul Pogonyshev; +Cc: 15465 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@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. > > > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#15465: CC-mode misaligns enums that implement an interface in Java 2013-10-13 21:38 ` Alan Mackenzie @ 2013-10-14 9:19 ` Paul Pogonyshev 2013-10-20 14:37 ` Alan Mackenzie 0 siblings, 1 reply; 11+ messages in thread From: Paul Pogonyshev @ 2013-10-14 9:19 UTC (permalink / raw) To: Alan Mackenzie; +Cc: 15465 [-- Attachment #1: Type: text/plain, Size: 1710 bytes --] 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@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@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. > > > > > > > [-- Attachment #2: Type: text/html, Size: 2588 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#15465: CC-mode misaligns enums that implement an interface in Java 2013-10-14 9:19 ` Paul Pogonyshev @ 2013-10-20 14:37 ` Alan Mackenzie 2013-10-21 11:00 ` Paul Pogonyshev 0 siblings, 1 reply; 11+ messages in thread From: Alan Mackenzie @ 2013-10-20 14:37 UTC (permalink / raw) To: Paul Pogonyshev; +Cc: 15465 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). ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#15465: CC-mode misaligns enums that implement an interface in Java 2013-10-20 14:37 ` Alan Mackenzie @ 2013-10-21 11:00 ` Paul Pogonyshev 2013-10-25 20:29 ` Alan Mackenzie 0 siblings, 1 reply; 11+ messages in thread From: Paul Pogonyshev @ 2013-10-21 11:00 UTC (permalink / raw) To: Alan Mackenzie; +Cc: 15465 [-- Attachment #1: Type: text/plain, Size: 870 bytes --] Yes, now it works fine on my real code. Thank you. Paul On 20 October 2013 16:37, Alan Mackenzie <acm@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). > [-- Attachment #2: Type: text/html, Size: 1409 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#15465: CC-mode misaligns enums that implement an interface in Java 2013-10-21 11:00 ` Paul Pogonyshev @ 2013-10-25 20:29 ` Alan Mackenzie 0 siblings, 0 replies; 11+ messages in thread From: Alan Mackenzie @ 2013-10-25 20:29 UTC (permalink / raw) To: 15465-done Bug fixed. -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-10-25 20:29 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-09-26 8:31 bug#15465: CC-mode misaligns enums that implement an interface in Java Paul Pogonyshev 2013-09-28 17:33 ` Alan Mackenzie 2013-09-28 19:15 ` Paul Pogonyshev 2013-09-28 21:33 ` Alan Mackenzie 2013-09-29 15:03 ` Alan Mackenzie 2013-09-30 7:23 ` Paul Pogonyshev 2013-10-13 21:38 ` Alan Mackenzie 2013-10-14 9:19 ` Paul Pogonyshev 2013-10-20 14:37 ` Alan Mackenzie 2013-10-21 11:00 ` Paul Pogonyshev 2013-10-25 20:29 ` Alan Mackenzie
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.