diff options
| author | Vincenzo Pupillo | 2023-07-29 21:10:57 +0200 |
|---|---|---|
| committer | Theodor Thornhill | 2023-07-29 21:10:57 +0200 |
| commit | 7da1cee56b3cc35fad7ff6f67147bb77cda6bb98 (patch) | |
| tree | 5d9ae6645f26bc93a9ae29e6278772f6faf632b8 | |
| parent | c2d95dd00e6cb0abaf4e7550f38c8c2c9ca22f2d (diff) | |
| download | emacs-7da1cee56b3cc35fad7ff6f67147bb77cda6bb98.tar.gz emacs-7da1cee56b3cc35fad7ff6f67147bb77cda6bb98.zip | |
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.el | 52 |
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 @@ | |||
| 31 | (eval-when-compile (require 'rx)) | 31 | (eval-when-compile (require 'rx)) |
| 32 | 32 | ||
| 33 | (declare-function treesit-parser-create "treesit.c") | 33 | (declare-function treesit-parser-create "treesit.c") |
| 34 | (declare-function treesit-query-capture "treesit.c") | ||
| 34 | (declare-function treesit-induce-sparse-tree "treesit.c") | 35 | (declare-function treesit-induce-sparse-tree "treesit.c") |
| 35 | (declare-function treesit-node-child "treesit.c") | 36 | (declare-function treesit-node-child "treesit.c") |
| 36 | (declare-function treesit-node-start "treesit.c") | 37 | (declare-function treesit-node-start "treesit.c") |
| @@ -87,6 +88,42 @@ | |||
| 87 | "VERSION_GREATER_EQUAL" "VERSION_LESS" "VERSION_LESS_EQUAL") | 88 | "VERSION_GREATER_EQUAL" "VERSION_LESS" "VERSION_LESS_EQUAL") |
| 88 | "CMake if conditions for tree-sitter font-locking.") | 89 | "CMake if conditions for tree-sitter font-locking.") |
| 89 | 90 | ||
| 91 | (defun cmake-ts-mode--font-lock-compatibility-fe9b5e0 () | ||
| 92 | "Indent rules helper, to handle different releases of tree-sitter-cmake. | ||
| 93 | Check if a node type is available, then return the right indent rules." | ||
| 94 | ;; handle commit fe9b5e0 | ||
| 95 | (condition-case nil | ||
| 96 | (progn (treesit-query-capture 'cmake '((argument_list) @capture)) | ||
| 97 | `(((foreach_command | ||
| 98 | ((argument_list) @font-lock-constant-face | ||
| 99 | (:match ,(rx-to-string | ||
| 100 | `(seq bol | ||
| 101 | (or ,@cmake-ts-mode--foreach-options) | ||
| 102 | eol)) | ||
| 103 | @font-lock-constant-face)))) | ||
| 104 | ((if_command | ||
| 105 | ((argument_list) @font-lock-constant-face | ||
| 106 | (:match ,(rx-to-string | ||
| 107 | `(seq bol | ||
| 108 | (or ,@cmake-ts-mode--if-conditions) | ||
| 109 | eol)) | ||
| 110 | @font-lock-constant-face)))))) | ||
| 111 | (error | ||
| 112 | `(((foreach_command | ||
| 113 | ((argument) @font-lock-constant-face | ||
| 114 | (:match ,(rx-to-string | ||
| 115 | `(seq bol | ||
| 116 | (or ,@cmake-ts-mode--foreach-options) | ||
| 117 | eol)) | ||
| 118 | @font-lock-constant-face)))) | ||
| 119 | ((if_command | ||
| 120 | ((argument) @font-lock-constant-face | ||
| 121 | (:match ,(rx-to-string | ||
| 122 | `(seq bol | ||
| 123 | (or ,@cmake-ts-mode--if-conditions) | ||
| 124 | eol)) | ||
| 125 | @font-lock-constant-face)))))))) | ||
| 126 | |||
| 90 | (defvar cmake-ts-mode--font-lock-settings | 127 | (defvar cmake-ts-mode--font-lock-settings |
| 91 | (treesit-font-lock-rules | 128 | (treesit-font-lock-rules |
| 92 | :language 'cmake | 129 | :language 'cmake |
| @@ -95,20 +132,7 @@ | |||
| 95 | 132 | ||
| 96 | :language 'cmake | 133 | :language 'cmake |
| 97 | :feature 'builtin | 134 | :feature 'builtin |
| 98 | `(((foreach_command | 135 | (cmake-ts-mode--font-lock-compatibility-fe9b5e0) |
| 99 | ((argument) @font-lock-constant-face | ||
| 100 | (:match ,(rx-to-string | ||
| 101 | `(seq bol | ||
| 102 | (or ,@cmake-ts-mode--foreach-options) | ||
| 103 | eol)) | ||
| 104 | @font-lock-constant-face)))) | ||
| 105 | ((if_command | ||
| 106 | ((argument) @font-lock-constant-face | ||
| 107 | (:match ,(rx-to-string | ||
| 108 | `(seq bol | ||
| 109 | (or ,@cmake-ts-mode--if-conditions) | ||
| 110 | eol)) | ||
| 111 | @font-lock-constant-face))))) | ||
| 112 | 136 | ||
| 113 | :language 'cmake | 137 | :language 'cmake |
| 114 | :feature 'comment | 138 | :feature 'comment |