GNU bug report logs - #79797
[PATCH] CC Mode : allow white spaces in Java annotation.

Previous Next

Package: emacs;

Reported by: ana <at> kigoth.pink

Date: Sun, 9 Nov 2025 09:59:02 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 79797 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


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):

From: ana <at> kigoth.pink
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: [PATCH] CC Mode : allow white spaces in Java annotation.
Date: Sun, 09 Nov 2025 09:57:35 +0000
[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):

From: Eli Zaretskii <eliz <at> gnu.org>
To: ana <at> kigoth.pink, Alan Mackenzie <acm <at> muc.de>
Cc: 79797 <at> debbugs.gnu.org
Subject: Re: bug#79797: [PATCH] CC Mode : allow white spaces in Java
 annotation.
Date: Sun, 09 Nov 2025 12:25:53 +0200
> 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.