diff options
| author | Randy Taylor | 2023-04-26 11:15:45 -0400 |
|---|---|---|
| committer | Dmitry Gutov | 2023-05-04 00:56:19 +0300 |
| commit | eaf25b9c6ae4020f76a810b6920b65613ca50e5d (patch) | |
| tree | 8d19f2e6ec5fc33444939102ab6d19ef42905b6b | |
| parent | cc090294d77c5d4047607d3234c304aaa1b0489c (diff) | |
| download | emacs-eaf25b9c6ae4020f76a810b6920b65613ca50e5d.tar.gz emacs-eaf25b9c6ae4020f76a810b6920b65613ca50e5d.zip | |
go-ts-mode: Use iota query only if supported (Bug#63086)
iota query support was added on January 5, 2022. To support older
versions of the tree-sitter-go grammar (like the latest tagged version,
v0.19.1, which was released on March 3, 2021), check if the query is
supported before trying to use it.
* lisp/progmodes/go-ts-mode.el (go-ts-mode--iota-query-supported-p): New
function.
(go-ts-mode--font-lock-settings): Use it.
| -rw-r--r-- | lisp/progmodes/go-ts-mode.el | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el index 77c97ffac11..f32a2d75775 100644 --- a/lisp/progmodes/go-ts-mode.el +++ b/lisp/progmodes/go-ts-mode.el | |||
| @@ -105,6 +105,12 @@ | |||
| 105 | ">>" "%=" ">>=" "--" "!" "..." "&^" "&^=" "~") | 105 | ">>" "%=" ">>=" "--" "!" "..." "&^" "&^=" "~") |
| 106 | "Go operators for tree-sitter font-locking.") | 106 | "Go operators for tree-sitter font-locking.") |
| 107 | 107 | ||
| 108 | (defun go-ts-mode--iota-query-supported-p () | ||
| 109 | "Returns t if the iota query is supported by the current version of | ||
| 110 | the tree-sitter-go grammar." | ||
| 111 | (ignore-errors | ||
| 112 | (or (treesit-query-string "" '((iota) @font-lock-constant-face) 'go) t))) | ||
| 113 | |||
| 108 | (defvar go-ts-mode--font-lock-settings | 114 | (defvar go-ts-mode--font-lock-settings |
| 109 | (treesit-font-lock-rules | 115 | (treesit-font-lock-rules |
| 110 | :language 'go | 116 | :language 'go |
| @@ -117,7 +123,9 @@ | |||
| 117 | 123 | ||
| 118 | :language 'go | 124 | :language 'go |
| 119 | :feature 'constant | 125 | :feature 'constant |
| 120 | '([(false) (iota) (nil) (true)] @font-lock-constant-face | 126 | `([(false) (nil) (true)] @font-lock-constant-face |
| 127 | ,@(when (go-ts-mode--iota-query-supported-p) | ||
| 128 | '((iota) @font-lock-constant-face)) | ||
| 121 | (const_declaration | 129 | (const_declaration |
| 122 | (const_spec name: (identifier) @font-lock-constant-face))) | 130 | (const_spec name: (identifier) @font-lock-constant-face))) |
| 123 | 131 | ||