summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincenzo Pupillo <v.pupillo@gmail.com>2023-07-29 21:10:57 +0200
committerTheodor Thornhill <theo@thornhill.no>2023-07-29 21:10:57 +0200
commit7da1cee56b3cc35fad7ff6f67147bb77cda6bb98 (patch)
tree5d9ae6645f26bc93a9ae29e6278772f6faf632b8
parentc2d95dd00e6cb0abaf4e7550f38c8c2c9ca22f2d (diff)
downloademacs-7da1cee56b3cc35fad7ff6f67147bb77cda6bb98.tar.gz
Update CMake support due to upstream changes (bug#64922)
A recent change in tree-sitter-cmake grammar support for CMake (commit fe9b5e0), now put arguments are wrapped in a new argument_list node. To support the old and new version of the grammar, a new function was added on which string syntax highlighting now depends. * lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode--font-lock-compatibility-fe9b5e0): Indent helper function to handle different tree-sitter-cmake version. * lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode--font-lock-settings): Use the new function to handle the new argument_list node.
-rw-r--r--lisp/progmodes/cmake-ts-mode.el52
1 files changed, 38 insertions, 14 deletions
diff --git a/lisp/progmodes/cmake-ts-mode.el b/lisp/progmodes/cmake-ts-mode.el
index 9d35d8077bd..53d471c381a 100644
--- a/lisp/progmodes/cmake-ts-mode.el
+++ b/lisp/progmodes/cmake-ts-mode.el
@@ -31,6 +31,7 @@
(eval-when-compile (require 'rx))
(declare-function treesit-parser-create "treesit.c")
+(declare-function treesit-query-capture "treesit.c")
(declare-function treesit-induce-sparse-tree "treesit.c")
(declare-function treesit-node-child "treesit.c")
(declare-function treesit-node-start "treesit.c")
@@ -87,6 +88,42 @@
"VERSION_GREATER_EQUAL" "VERSION_LESS" "VERSION_LESS_EQUAL")
"CMake if conditions for tree-sitter font-locking.")
+(defun cmake-ts-mode--font-lock-compatibility-fe9b5e0 ()
+ "Indent rules helper, to handle different releases of tree-sitter-cmake.
+Check if a node type is available, then return the right indent rules."
+ ;; handle commit fe9b5e0
+ (condition-case nil
+ (progn (treesit-query-capture 'cmake '((argument_list) @capture))
+ `(((foreach_command
+ ((argument_list) @font-lock-constant-face
+ (:match ,(rx-to-string
+ `(seq bol
+ (or ,@cmake-ts-mode--foreach-options)
+ eol))
+ @font-lock-constant-face))))
+ ((if_command
+ ((argument_list) @font-lock-constant-face
+ (:match ,(rx-to-string
+ `(seq bol
+ (or ,@cmake-ts-mode--if-conditions)
+ eol))
+ @font-lock-constant-face))))))
+ (error
+ `(((foreach_command
+ ((argument) @font-lock-constant-face
+ (:match ,(rx-to-string
+ `(seq bol
+ (or ,@cmake-ts-mode--foreach-options)
+ eol))
+ @font-lock-constant-face))))
+ ((if_command
+ ((argument) @font-lock-constant-face
+ (:match ,(rx-to-string
+ `(seq bol
+ (or ,@cmake-ts-mode--if-conditions)
+ eol))
+ @font-lock-constant-face))))))))
+
(defvar cmake-ts-mode--font-lock-settings
(treesit-font-lock-rules
:language 'cmake
@@ -95,20 +132,7 @@
:language 'cmake
:feature 'builtin
- `(((foreach_command
- ((argument) @font-lock-constant-face
- (:match ,(rx-to-string
- `(seq bol
- (or ,@cmake-ts-mode--foreach-options)
- eol))
- @font-lock-constant-face))))
- ((if_command
- ((argument) @font-lock-constant-face
- (:match ,(rx-to-string
- `(seq bol
- (or ,@cmake-ts-mode--if-conditions)
- eol))
- @font-lock-constant-face)))))
+ (cmake-ts-mode--font-lock-compatibility-fe9b5e0)
:language 'cmake
:feature 'comment