GNU bug report logs -
#79797
[PATCH] CC Mode : allow white spaces in Java annotation.
Previous Next
To reply to this bug, email your comments to 79797 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79797; Package
emacs.
(Sun, 09 Nov 2025 09:59:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
ana <at> kigoth.pink:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org.
(Sun, 09 Nov 2025 09:59:02 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)]
Heya, as per the Java language specification, white spaces can be inserted inside annotation, right after the '@'.
This means that '@ Override' should have the '@' and the 'Override' in 'c-annotation-face'; this is currently not the case as both take the default face instead.
In Java, a white space matches [ \t\f\n\r] or \n\r; but several
instances were only scanning for [ \t\n\r].
As such I added the \f that were missing and tried to implement the change for annotation.
Emphasis on "tried" : While my change works for usual annotations; there is a special java construct '@interface' that is both an annotation and a class keyword, a bit weird yes, but it means it needs to take the same face as 'class' and 'interface' (regular one, which isn't the same as '@interface' btw).
They are defined in lisp/progmodes/cc-langs.el (c-class-decl-kwds)
The following, intuitive, yet incorrect, change makes '@interface' take 'c-annotation-face' rather than the expected 'font-lock-keyword-face' :
- java '("class" "@interface" "interface")
+ java '("class" "@[ \t\f\n\r]*interface" "interface")
If anyone has an idea as to how '@interface' could work with my proposed changes, do note that in order to verify the change is correct, the '@' of '@ interface' also needs to be in 'font-lock-keyword-face' rather than default, it's easy to miss because 'interface' in itself is a keyword.
Relevant Java doc :
- Annotation : https://docs.oracle.com/javase/specs/jls/se25/html/jls-9.html#jls-9.7.1
- White Space : https://docs.oracle.com/javase/specs/jls/se25/html/jls-3.html#jls-3.6
[0001-CC-Mode-allow-white-spaces-in-Java-annotation.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79797; Package
emacs.
(Sun, 09 Nov 2025 10:27:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 79797 <at> debbugs.gnu.org (full text, mbox):
> Date: Sun, 09 Nov 2025 09:57:35 +0000
> From: ana--- via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
> Heya, as per the Java language specification, white spaces can be inserted inside annotation, right after the '@'.
>
> This means that '@ Override' should have the '@' and the 'Override' in 'c-annotation-face'; this is currently not the case as both take the default face instead.
>
> In Java, a white space matches [ \t\f\n\r] or \n\r; but several
> instances were only scanning for [ \t\n\r].
>
> As such I added the \f that were missing and tried to implement the change for annotation.
>
> Emphasis on "tried" : While my change works for usual annotations; there is a special java construct '@interface' that is both an annotation and a class keyword, a bit weird yes, but it means it needs to take the same face as 'class' and 'interface' (regular one, which isn't the same as '@interface' btw).
> They are defined in lisp/progmodes/cc-langs.el (c-class-decl-kwds)
>
> The following, intuitive, yet incorrect, change makes '@interface' take 'c-annotation-face' rather than the expected 'font-lock-keyword-face' :
> - java '("class" "@interface" "interface")
> + java '("class" "@[ \t\f\n\r]*interface" "interface")
>
> If anyone has an idea as to how '@interface' could work with my proposed changes, do note that in order to verify the change is correct, the '@' of '@ interface' also needs to be in 'font-lock-keyword-face' rather than default, it's easy to miss because 'interface' in itself is a keyword.
>
> Relevant Java doc :
> - Annotation : https://docs.oracle.com/javase/specs/jls/se25/html/jls-9.html#jls-9.7.1
>
> - White Space : https://docs.oracle.com/javase/specs/jls/se25/html/jls-3.html#jls-3.6
Thanks, I've CC'ed Alan who maintains the Java mode.
This bug report was last modified 2 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.