Constant highlighting no longer captures Java annotations
* lisp/progmodes/java-ts-mode.el (java-ts-mode--fontify-constant): New function. (java-ts-mode--font-lock-settings): Use it.
This commit is contained in:
committed by
Stefan Kangas
parent
e15dcb2db5
commit
563b6f9451
@@ -164,6 +164,23 @@ the available version of Tree-sitter for Java."
|
|||||||
(error
|
(error
|
||||||
`((string_literal) @font-lock-string-face))))
|
`((string_literal) @font-lock-string-face))))
|
||||||
|
|
||||||
|
(defun java-ts-mode--fontify-constant (node override start end &rest _)
|
||||||
|
"Fontify a Java constant.
|
||||||
|
In Java the names of variables declared class constants and of ANSI
|
||||||
|
constants should be all uppercase with words separated by underscores.
|
||||||
|
This function also prevents annotations from being highlighted as if
|
||||||
|
they were constants.
|
||||||
|
For NODE, OVERRIDE, START, and END, see `treesit-font-lock-rules'."
|
||||||
|
(let ((node-start (treesit-node-start node))
|
||||||
|
(case-fold-search nil))
|
||||||
|
(when (and
|
||||||
|
(not (equal (char-before node-start) ?@)) ;; skip annotations
|
||||||
|
(string-match "\\`[A-Z_][0-9A-Z_]*\\'" (treesit-node-text node)))
|
||||||
|
(treesit-fontify-with-override
|
||||||
|
node-start (treesit-node-end node)
|
||||||
|
'font-lock-constant-face override
|
||||||
|
start end))))
|
||||||
|
|
||||||
(defvar java-ts-mode--font-lock-settings
|
(defvar java-ts-mode--font-lock-settings
|
||||||
(treesit-font-lock-rules
|
(treesit-font-lock-rules
|
||||||
:language 'java
|
:language 'java
|
||||||
@@ -174,8 +191,7 @@ the available version of Tree-sitter for Java."
|
|||||||
:language 'java
|
:language 'java
|
||||||
:override t
|
:override t
|
||||||
:feature 'constant
|
:feature 'constant
|
||||||
`(((identifier) @font-lock-constant-face
|
`((identifier) @java-ts-mode--fontify-constant
|
||||||
(:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face))
|
|
||||||
[(true) (false)] @font-lock-constant-face)
|
[(true) (false)] @font-lock-constant-face)
|
||||||
:language 'java
|
:language 'java
|
||||||
:override t
|
:override t
|
||||||
|
|||||||
Reference in New Issue
Block a user