[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 255eeee0e06 1/2: java-ts-mode: detect if text_block is supporte
From: |
Eli Zaretskii |
Subject: |
emacs-29 255eeee0e06 1/2: java-ts-mode: detect if text_block is supported. |
Date: |
Thu, 9 Mar 2023 05:23:35 -0500 (EST) |
branch: emacs-29
commit 255eeee0e06abd5c395b136867e6a9a440916eea
Author: Vincenzo Pupillo <v.pupillo@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>
java-ts-mode: detect if text_block is supported.
A recent commit in tree-sitter-java (issue #141) removed support for
the text_block node type from the grammar. To support the old released
version and the new one, a helper function was added on which the
string syntax highlighting now depends. (bug#61913)
* lisp/progmodes/java-ts-mode.el
(java-ts-mode--string-highlight-helper): New helper function that
return the right query string
(java-ts-mode--font-lock-settings): Use it
Copyright-paperwork-exempt: yes
---
lisp/progmodes/java-ts-mode.el | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index 5cd4acd301d..fb1081a5f2e 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -145,6 +145,16 @@
"|=" "~" ">>" ">>>" "<<" "::" "?" "&=")
"Java operators for tree-sitter font-locking.")
+(defun java-ts-mode--string-highlight-helper ()
+"Returns, for strings, a query based on what is supported by
+the available version of Tree-sitter for java."
+ (condition-case nil
+ (progn (treesit-query-capture 'java '((text_block)
@font-lock-string-face))
+ `((string_literal) @font-lock-string-face
+ (text_block) @font-lock-string-face))
+ (error
+ `((string_literal) @font-lock-string-face))))
+
(defvar java-ts-mode--font-lock-settings
(treesit-font-lock-rules
:language 'java
@@ -182,8 +192,7 @@
:language 'java
:override t
:feature 'string
- `((string_literal) @font-lock-string-face
- (text_block) @font-lock-string-face)
+ (java-ts-mode--string-highlight-helper)
:language 'java
:override t
:feature 'literal