GNU bug report logs - #79626
30.1; Java programming modes handling of "var" keyword

Previous Next

Package: emacs;

Reported by: Robert Brown <robert.brown <at> gmail.com>

Date: Tue, 14 Oct 2025 18:26:01 UTC

Severity: normal

Found in version 30.1

Done: Yuan Fu <casouri <at> gmail.com>

To reply to this bug, email your comments to 79626 AT debbugs.gnu.org.
There is no need to reopen the bug first.

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#79626; Package emacs. (Tue, 14 Oct 2025 18:26:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Robert Brown <robert.brown <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 14 Oct 2025 18:26:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Robert Brown <robert.brown <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.1; Java programming modes handling of "var" keyword
Date: Tue, 14 Oct 2025 14:25:11 -0400
[Message part 1 (text/plain, inline)]
When fontifying the following Java code:

package mystuff;
import static foo.bar.Struct;
class MyClass {
    void func() {
        var foo = 100;
    }
}

java-mode and java-ts-mode display the "var" Java keyword right before "foo"
using font-lock-type-face.  In comparison, cc-mode fontifies semantically
similar uses of "auto" to omit a type using font-lock-keyword-face.

"var" is a keyword in Java, not a type, just as "auto" is a keyword in C++,
so
it would be better to fontify it using font-lock-keyword-face.


In GNU Emacs 30.1 (build 4, x86_64-pc-linux-gnu) of 2025-02-23 built on
 chuwi
System Description: Ubuntu 24.04.3 LTS

Configured using:
 'configure --without-x
 --prefix=/home/brown/local/software/package/emacs-30.1'

Configured features:
DBUS GMP GNUTLS LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY
INOTIFY PDUMPER SECCOMP SOUND THREADS TREE_SITTER XIM ZLIB

Important settings:
  value of $LC_COLLATE: C
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Completion List

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  buffer-read-only: t
  line-number-mode: t
  cursor-face-highlight-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/brown/local/software/source/slime/slime-tests hides
/home/brown/.emacs.d/elpa/slime-20240323.141/slime-tests
/home/brown/local/software/source/slime/slime-autoloads hides
/home/brown/.emacs.d/elpa/slime-20240323.141/slime-autoloads
/home/brown/local/software/source/slime/slime hides
/home/brown/.emacs.d/elpa/slime-20240323.141/slime
/home/brown/lib/emacs/lisp/yow hides
/home/brown/local/software/package/emacs-30.1/share/emacs/30.1/lisp/obsolete/yow

Features:
(shadow sort mail-extr cl-extra warnings display-line-numbers ebuff-menu
emacsbug message yank-media puny dired dnd dired-loaddefs rfc822 mml
mml-sec epa derived epg rfc6068 epg-config gnus-util
text-property-search time-date mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils mule-util apropos crm thingatpt
help-fns radix-tree help-mode cap-words superword subword cc-mode
cc-fonts cc-guess cc-menus cc-cmds java-ts-mode c-ts-common treesit
term/xterm xterm company-oddmuse company-keywords company-etags etags
fileloop generator xref project ring company-gtags company-dabbrev-code
company-dabbrev company-files company-clang company-capf company-cmake
company-semantic company-template company-bbdb company pcase cc-styles
cc-align cc-engine cc-vars cc-defs regexp-opt rx dash-autoloads
ement-autoloads persist-autoloads plz-autoloads slime-company-autoloads
slime-autoloads macrostep-autoloads svg-lib-autoloads
taxy-magit-section-autoloads taxy-autoloads info tool-bar
magit-section-autoloads llama-autoloads package browse-url url url-proxy
url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs icons password-cache json
subr-x map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs cl-lib
rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 155709 250114) (symbols 48 12179 99) (strings 32 41281 14457)
 (string-bytes 1 1412937) (vectors 16 18140) (vector-slots 8 213127 63218)
 (floats 8 72 88) (intervals 56 827 426) (buffers 992 15))
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79626; Package emacs. (Tue, 14 Oct 2025 19:30:02 GMT) Full text and rfc822 format available.

Message #8 received at 79626 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Robert Brown <robert.brown <at> gmail.com>,
 Theodor Thornhill <theo <at> thornhill.no>, Yuan Fu <casouri <at> gmail.com>
Cc: 79626 <at> debbugs.gnu.org
Subject: Re: bug#79626: 30.1; Java programming modes handling of "var" keyword
Date: Tue, 14 Oct 2025 22:28:47 +0300
> From: Robert Brown <robert.brown <at> gmail.com>
> Date: Tue, 14 Oct 2025 14:25:11 -0400
> 
> When fontifying the following Java code:
> 
> package mystuff;
> import static foo.bar.Struct;
> class MyClass {
>     void func() {
>         var foo = 100;
>     }
> }
> 
> java-mode and java-ts-mode display the "var" Java keyword right before "foo"
> using font-lock-type-face.  In comparison, cc-mode fontifies semantically
> similar uses of "auto" to omit a type using font-lock-keyword-face.
> 
> "var" is a keyword in Java, not a type, just as "auto" is a keyword in C++, so
> it would be better to fontify it using font-lock-keyword-face.

Thanks.

If you enable treesit-explore-mode, you will see that the Javae
tree-sitter grammar identifies 'var' as 'type_identifier' node.  So
maybe the the problem is in the grammar library, not in Emacs?  Or
maybe we should add "var" to java-ts-mode--keywords?  Theodor and
Yuan, WDYT?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79626; Package emacs. (Sat, 01 Nov 2025 09:01:02 GMT) Full text and rfc822 format available.

Message #11 received at 79626 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>, theo <at> thornhill.no
Cc: robert.brown <at> gmail.com, 79626 <at> debbugs.gnu.org
Subject: Re: bug#79626: 30.1; Java programming modes handling of "var" keyword
Date: Sat, 01 Nov 2025 11:00:22 +0200
Ping!  Yuan and Theo, could you please chime in on this issue?

> Cc: 79626 <at> debbugs.gnu.org
> Date: Tue, 14 Oct 2025 22:28:47 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
> 
> > From: Robert Brown <robert.brown <at> gmail.com>
> > Date: Tue, 14 Oct 2025 14:25:11 -0400
> > 
> > When fontifying the following Java code:
> > 
> > package mystuff;
> > import static foo.bar.Struct;
> > class MyClass {
> >     void func() {
> >         var foo = 100;
> >     }
> > }
> > 
> > java-mode and java-ts-mode display the "var" Java keyword right before "foo"
> > using font-lock-type-face.  In comparison, cc-mode fontifies semantically
> > similar uses of "auto" to omit a type using font-lock-keyword-face.
> > 
> > "var" is a keyword in Java, not a type, just as "auto" is a keyword in C++, so
> > it would be better to fontify it using font-lock-keyword-face.
> 
> Thanks.
> 
> If you enable treesit-explore-mode, you will see that the Javae
> tree-sitter grammar identifies 'var' as 'type_identifier' node.  So
> maybe the the problem is in the grammar library, not in Emacs?  Or
> maybe we should add "var" to java-ts-mode--keywords?  Theodor and
> Yuan, WDYT?
> 
> 
> 
> 




Reply sent to Yuan Fu <casouri <at> gmail.com>:
You have taken responsibility. (Sun, 02 Nov 2025 22:34:02 GMT) Full text and rfc822 format available.

Notification sent to Robert Brown <robert.brown <at> gmail.com>:
bug acknowledged by developer. (Sun, 02 Nov 2025 22:34:02 GMT) Full text and rfc822 format available.

Message #16 received at 79626-done <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: robert.brown <at> gmail.com, theo <at> thornhill.no, 79626-done <at> debbugs.gnu.org
Subject: Re: bug#79626: 30.1; Java programming modes handling of "var" keyword
Date: Sun, 2 Nov 2025 14:33:25 -0800

> On Nov 1, 2025, at 2:00 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
> Ping!  Yuan and Theo, could you please chime in on this issue?
> 
>> Cc: 79626 <at> debbugs.gnu.org
>> Date: Tue, 14 Oct 2025 22:28:47 +0300
>> From: Eli Zaretskii <eliz <at> gnu.org>
>> 
>>> From: Robert Brown <robert.brown <at> gmail.com>
>>> Date: Tue, 14 Oct 2025 14:25:11 -0400
>>> 
>>> When fontifying the following Java code:
>>> 
>>> package mystuff;
>>> import static foo.bar.Struct;
>>> class MyClass {
>>>    void func() {
>>>        var foo = 100;
>>>    }
>>> }
>>> 
>>> java-mode and java-ts-mode display the "var" Java keyword right before "foo"
>>> using font-lock-type-face.  In comparison, cc-mode fontifies semantically
>>> similar uses of "auto" to omit a type using font-lock-keyword-face.
>>> 
>>> "var" is a keyword in Java, not a type, just as "auto" is a keyword in C++, so
>>> it would be better to fontify it using font-lock-keyword-face.
>> 
>> Thanks.
>> 
>> If you enable treesit-explore-mode, you will see that the Javae
>> tree-sitter grammar identifies 'var' as 'type_identifier' node.  So
>> maybe the the problem is in the grammar library, not in Emacs?  Or
>> maybe we should add "var" to java-ts-mode--keywords?  Theodor and
>> Yuan, WDYT?

Thanks for the ping. I thought there’s only one report on java-ts-mode. So the java grammar is correct, Java treats the var syntax as a type, rather than a keyword. It’s a special non-determined type that will be figured out by the compiler. I added a special rule to fontify it.

Yuan






This bug report was last modified 3 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.