diff options
| author | Yuan Fu | 2025-11-28 00:10:17 -0800 |
|---|---|---|
| committer | Yuan Fu | 2025-11-28 00:12:28 -0800 |
| commit | 2c19f6087efe466894e1fe47121515d32d6a6d1c (patch) | |
| tree | 848fbf5def2debb8ba324a5250e86b0535f285a9 | |
| parent | 85f2bf2bc7ba0a6557e992601658530f562e00d2 (diff) | |
| download | emacs-2c19f6087efe466894e1fe47121515d32d6a6d1c.tar.gz emacs-2c19f6087efe466894e1fe47121515d32d6a6d1c.zip | |
Remove the cached values in tree-sitter modes (bug#79363)
The cached values are not needed anymore since Emacs now caches
the compiled queries.
* lisp/progmodes/cmake-ts-mode.el:
(cmake-ts-mode--indent-rules-cached): Remove.
(cmake-ts-mode--indent-rules): Return values directly.
(cmake-ts-mode--font-lock-settings-cached): Remove.
(cmake-ts-mode--font-lock-settings): Return values directly.
* lisp/progmodes/php-ts-mode.el:
(php-ts-mode--font-lock-settings-cached): Remove.
(php-ts-mode--font-lock-settings): Return values directly.
(php-ts-mode--custom-html-font-lock-settings-cached): Remove.
(php-ts-mode--custom-html-font-lock-settings): Return values directly.
* lisp/textmodes/mhtml-ts-mode.el:
(mhtml-ts-mode--treesit-font-lock-settings-cached): Remove.
(mhtml-ts-mode--treesit-font-lock-settings): Return values directly.
(mhtml-ts-mode--treesit-indent-rules-cached): Remove.
(mhtml-ts-mode--treesit-indent-rules): Return values directly.
* lisp/progmodes/cmake-ts-mode.el:
(cmake-ts-mode--indent-rules-cached): Remove
(cmake-ts-mode--indent-rules): Return values directly.
(cmake-ts-mode--font-lock-settings-cached): Remove.
(cmake-ts-mode--font-lock-settings): Return values directly.
* lisp/progmodes/csharp-mode.el:
(csharp-ts-mode--font-lock-settings-cached): Remove.
(csharp-ts-mode--font-lock-settings): Return values directly.
| -rw-r--r-- | lisp/progmodes/cmake-ts-mode.el | 178 | ||||
| -rw-r--r-- | lisp/progmodes/csharp-mode.el | 666 | ||||
| -rw-r--r-- | lisp/progmodes/js.el | 424 | ||||
| -rw-r--r-- | lisp/progmodes/php-ts-mode.el | 446 | ||||
| -rw-r--r-- | lisp/textmodes/mhtml-ts-mode.el | 80 |
5 files changed, 861 insertions, 933 deletions
diff --git a/lisp/progmodes/cmake-ts-mode.el b/lisp/progmodes/cmake-ts-mode.el index 60d03f50a12..8930f96a2cf 100644 --- a/lisp/progmodes/cmake-ts-mode.el +++ b/lisp/progmodes/cmake-ts-mode.el | |||
| @@ -61,35 +61,27 @@ | |||
| 61 | table) | 61 | table) |
| 62 | "Syntax table for `cmake-ts-mode'.") | 62 | "Syntax table for `cmake-ts-mode'.") |
| 63 | 63 | ||
| 64 | (defvar cmake-ts-mode--indent-rules-cached nil | ||
| 65 | "Cached tree-sitter indent rules for `cmake-ts-mode'.") | ||
| 66 | |||
| 67 | (defun cmake-ts-mode--indent-rules () | 64 | (defun cmake-ts-mode--indent-rules () |
| 68 | "Return tree-sitter indent rules for `cmake-ts-mode'. | 65 | "Return tree-sitter indent rules for `cmake-ts-mode'." |
| 69 | 66 | `((cmake | |
| 70 | Tree-sitter indent rules are evaluated the first time this function is | 67 | ((node-is ")") parent-bol 0) |
| 71 | called. Subsequent calls return the first evaluated value." | 68 | ((node-is "else_command") parent-bol 0) |
| 72 | (or cmake-ts-mode--indent-rules-cached | 69 | ((node-is "elseif_command") parent-bol 0) |
| 73 | (setq cmake-ts-mode--indent-rules-cached | 70 | ((node-is "endforeach_command") parent-bol 0) |
| 74 | `((cmake | 71 | ((node-is "endfunction_command") parent-bol 0) |
| 75 | ((node-is ")") parent-bol 0) | 72 | ((node-is "endif_command") parent-bol 0) |
| 76 | ((node-is "else_command") parent-bol 0) | 73 | ((parent-is "foreach_loop") parent-bol cmake-ts-mode-indent-offset) |
| 77 | ((node-is "elseif_command") parent-bol 0) | 74 | ((parent-is "function_def") parent-bol cmake-ts-mode-indent-offset) |
| 78 | ((node-is "endforeach_command") parent-bol 0) | 75 | ((parent-is "if_condition") parent-bol cmake-ts-mode-indent-offset) |
| 79 | ((node-is "endfunction_command") parent-bol 0) | 76 | ((parent-is "normal_command") parent-bol cmake-ts-mode-indent-offset) |
| 80 | ((node-is "endif_command") parent-bol 0) | 77 | ;; Release v0.4.0 wraps arguments in an argument_list node. |
| 81 | ((parent-is "foreach_loop") parent-bol cmake-ts-mode-indent-offset) | 78 | ,@(ignore-errors |
| 82 | ((parent-is "function_def") parent-bol cmake-ts-mode-indent-offset) | 79 | (treesit-query-capture 'cmake '((argument_list) @capture)) |
| 83 | ((parent-is "if_condition") parent-bol cmake-ts-mode-indent-offset) | 80 | `(((parent-is "argument_list") grand-parent cmake-ts-mode-indent-offset))) |
| 84 | ((parent-is "normal_command") parent-bol cmake-ts-mode-indent-offset) | 81 | ;; Release v0.3.0 wraps the body of commands into a body node. |
| 85 | ;; Release v0.4.0 wraps arguments in an argument_list node. | 82 | ,@(ignore-errors |
| 86 | ,@(ignore-errors | 83 | (treesit-query-capture 'cmake '((body) @capture)) |
| 87 | (treesit-query-capture 'cmake '((argument_list) @capture)) | 84 | `(((parent-is "body") grand-parent cmake-ts-mode-indent-offset)))))) |
| 88 | `(((parent-is "argument_list") grand-parent cmake-ts-mode-indent-offset))) | ||
| 89 | ;; Release v0.3.0 wraps the body of commands into a body node. | ||
| 90 | ,@(ignore-errors | ||
| 91 | (treesit-query-capture 'cmake '((body) @capture)) | ||
| 92 | `(((parent-is "body") grand-parent cmake-ts-mode-indent-offset)))))))) | ||
| 93 | 85 | ||
| 94 | (defvar cmake-ts-mode--constants | 86 | (defvar cmake-ts-mode--constants |
| 95 | '("ON" "TRUE" "YES" "Y" "OFF" "FALSE" "NO" "N" "IGNORE" "NOTFOUND") | 87 | '("ON" "TRUE" "YES" "Y" "OFF" "FALSE" "NO" "N" "IGNORE" "NOTFOUND") |
| @@ -148,76 +140,68 @@ Check if a node type is available, then return the right font lock rules." | |||
| 148 | eol)) | 140 | eol)) |
| 149 | @font-lock-constant-face)))))))) | 141 | @font-lock-constant-face)))))))) |
| 150 | 142 | ||
| 151 | (defvar cmake-ts-mode--font-lock-settings-cached nil | ||
| 152 | "Cached tree-sitter font-lock settings for `cmake-ts-mode'.") | ||
| 153 | |||
| 154 | (defun cmake-ts-mode--font-lock-settings () | 143 | (defun cmake-ts-mode--font-lock-settings () |
| 155 | "Return tree-sitter font-lock settings for `cmake-ts-mode'. | 144 | "Return tree-sitter font-lock settings for `cmake-ts-mode'." |
| 156 | 145 | (treesit-font-lock-rules | |
| 157 | Tree-sitter font-lock settings are evaluated the first time this | 146 | :language 'cmake |
| 158 | function is called. Subsequent calls return the first evaluated value." | 147 | :feature 'bracket |
| 159 | (or cmake-ts-mode--font-lock-settings-cached | 148 | '((["(" ")"]) @font-lock-bracket-face) |
| 160 | (setq cmake-ts-mode--font-lock-settings-cached | 149 | |
| 161 | (treesit-font-lock-rules | 150 | :language 'cmake |
| 162 | :language 'cmake | 151 | :feature 'builtin |
| 163 | :feature 'bracket | 152 | (cmake-ts-mode--font-lock-compatibility-fe9b5e0) |
| 164 | '((["(" ")"]) @font-lock-bracket-face) | 153 | |
| 165 | 154 | :language 'cmake | |
| 166 | :language 'cmake | 155 | :feature 'comment |
| 167 | :feature 'builtin | 156 | '([(bracket_comment) (line_comment)] @font-lock-comment-face) |
| 168 | (cmake-ts-mode--font-lock-compatibility-fe9b5e0) | 157 | |
| 169 | 158 | :language 'cmake | |
| 170 | :language 'cmake | 159 | :feature 'constant |
| 171 | :feature 'comment | 160 | `(((argument) @font-lock-constant-face |
| 172 | '([(bracket_comment) (line_comment)] @font-lock-comment-face) | 161 | (:match ,(rx-to-string |
| 173 | 162 | `(seq bol | |
| 174 | :language 'cmake | 163 | (or ,@cmake-ts-mode--constants) |
| 175 | :feature 'constant | 164 | eol)) |
| 176 | `(((argument) @font-lock-constant-face | 165 | @font-lock-constant-face))) |
| 177 | (:match ,(rx-to-string | 166 | |
| 178 | `(seq bol | 167 | :language 'cmake |
| 179 | (or ,@cmake-ts-mode--constants) | 168 | :feature 'function |
| 180 | eol)) | 169 | '((normal_command (identifier) @font-lock-function-call-face)) |
| 181 | @font-lock-constant-face))) | 170 | |
| 182 | 171 | :language 'cmake | |
| 183 | :language 'cmake | 172 | :feature 'keyword |
| 184 | :feature 'function | 173 | `([,@cmake-ts-mode--keywords] @font-lock-keyword-face) |
| 185 | '((normal_command (identifier) @font-lock-function-call-face)) | 174 | |
| 186 | 175 | :language 'cmake | |
| 187 | :language 'cmake | 176 | :feature 'number |
| 188 | :feature 'keyword | 177 | '(((unquoted_argument) @font-lock-number-face |
| 189 | `([,@cmake-ts-mode--keywords] @font-lock-keyword-face) | 178 | (:match "\\`-?[[:digit:]]*\\.?[[:digit:]]*\\.?[[:digit:]]+\\'" |
| 190 | 179 | @font-lock-number-face))) | |
| 191 | :language 'cmake | 180 | |
| 192 | :feature 'number | 181 | :language 'cmake |
| 193 | '(((unquoted_argument) @font-lock-number-face | 182 | :feature 'string |
| 194 | (:match "\\`-?[[:digit:]]*\\.?[[:digit:]]*\\.?[[:digit:]]+\\'" | 183 | '([(bracket_argument) (quoted_argument)] @font-lock-string-face) |
| 195 | @font-lock-number-face))) | 184 | |
| 196 | 185 | :language 'cmake | |
| 197 | :language 'cmake | 186 | :feature 'escape-sequence |
| 198 | :feature 'string | 187 | :override t |
| 199 | '([(bracket_argument) (quoted_argument)] @font-lock-string-face) | 188 | '((escape_sequence) @font-lock-escape-face) |
| 200 | 189 | ||
| 201 | :language 'cmake | 190 | :language 'cmake |
| 202 | :feature 'escape-sequence | 191 | :feature 'misc-punctuation |
| 203 | :override t | 192 | ;; Don't override strings. |
| 204 | '((escape_sequence) @font-lock-escape-face) | 193 | :override 'nil |
| 205 | 194 | '((["$" "{" "}"]) @font-lock-misc-punctuation-face) | |
| 206 | :language 'cmake | 195 | |
| 207 | :feature 'misc-punctuation | 196 | :language 'cmake |
| 208 | ;; Don't override strings. | 197 | :feature 'variable |
| 209 | :override 'nil | 198 | :override t |
| 210 | '((["$" "{" "}"]) @font-lock-misc-punctuation-face) | 199 | '((variable) @font-lock-variable-use-face) |
| 211 | 200 | ||
| 212 | :language 'cmake | 201 | :language 'cmake |
| 213 | :feature 'variable | 202 | :feature 'error |
| 214 | :override t | 203 | :override t |
| 215 | '((variable) @font-lock-variable-use-face) | 204 | '((ERROR) @font-lock-warning-face))) |
| 216 | |||
| 217 | :language 'cmake | ||
| 218 | :feature 'error | ||
| 219 | :override t | ||
| 220 | '((ERROR) @font-lock-warning-face))))) | ||
| 221 | 205 | ||
| 222 | (defun cmake-ts-mode--defun-name (node) | 206 | (defun cmake-ts-mode--defun-name (node) |
| 223 | "Return the defun name of NODE. | 207 | "Return the defun name of NODE. |
diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el index 5656b5d00ba..1a31e3f9ab9 100644 --- a/lisp/progmodes/csharp-mode.el +++ b/lisp/progmodes/csharp-mode.el | |||
| @@ -779,345 +779,337 @@ compilation and evaluation time conflicts." | |||
| 779 | (if (csharp-ts-mode--test-method-declaration-type-field) | 779 | (if (csharp-ts-mode--test-method-declaration-type-field) |
| 780 | 'type: 'returns:)) | 780 | 'type: 'returns:)) |
| 781 | 781 | ||
| 782 | (defvar csharp-ts-mode--font-lock-settings-cached nil | ||
| 783 | "Cached tree-sitter font-lock settings for `csharp-ts-mode'.") | ||
| 784 | |||
| 785 | (defun csharp-ts-mode--font-lock-settings () | 782 | (defun csharp-ts-mode--font-lock-settings () |
| 786 | "Return tree-sitter font-lock settings for `csharp-ts-mode'. | 783 | "Return tree-sitter font-lock settings for `csharp-ts-mode'." |
| 787 | 784 | (treesit-font-lock-rules | |
| 788 | Tree-sitter font-lock settings are evaluated the first time this | 785 | :language 'c-sharp |
| 789 | function is called. Subsequent calls return the first evaluated value." | 786 | :feature 'expression |
| 790 | (or csharp-ts-mode--font-lock-settings-cached | 787 | '((conditional_expression (identifier) @font-lock-variable-use-face) |
| 791 | (setq csharp-ts-mode--font-lock-settings-cached | 788 | (postfix_unary_expression (identifier)* @font-lock-variable-use-face) |
| 792 | (treesit-font-lock-rules | 789 | (initializer_expression (assignment_expression left: (identifier) @font-lock-property-use-face)) |
| 793 | :language 'c-sharp | 790 | (anonymous_object_creation_expression |
| 794 | :feature 'expression | 791 | (identifier) @font-lock-property-use-face |
| 795 | '((conditional_expression (identifier) @font-lock-variable-use-face) | 792 | (identifier) @font-lock-variable-use-face) |
| 796 | (postfix_unary_expression (identifier)* @font-lock-variable-use-face) | 793 | (anonymous_object_creation_expression |
| 797 | (initializer_expression (assignment_expression left: (identifier) @font-lock-property-use-face)) | 794 | (identifier) @font-lock-property-use-face |
| 798 | (anonymous_object_creation_expression | 795 | [(object_creation_expression) |
| 799 | (identifier) @font-lock-property-use-face | 796 | (integer_literal) |
| 800 | (identifier) @font-lock-variable-use-face) | 797 | (string_literal) |
| 801 | (anonymous_object_creation_expression | 798 | (binary_expression) |
| 802 | (identifier) @font-lock-property-use-face | 799 | (invocation_expression) |
| 803 | [(object_creation_expression) | 800 | (member_access_expression) |
| 804 | (integer_literal) | 801 | (conditional_expression)]) |
| 805 | (string_literal) | 802 | (interpolated_string_expression |
| 806 | (binary_expression) | 803 | (interpolation |
| 807 | (invocation_expression) | 804 | (identifier) @font-lock-variable-use-face)) |
| 808 | (member_access_expression) | 805 | (interpolated_string_expression |
| 809 | (conditional_expression)]) | 806 | (interpolation |
| 810 | (interpolated_string_expression | 807 | (member_access_expression |
| 811 | (interpolation | 808 | name: (identifier) @font-lock-property-use-face))) |
| 812 | (identifier) @font-lock-variable-use-face)) | 809 | ((interpolated_string_expression |
| 813 | (interpolated_string_expression | 810 | (interpolation |
| 814 | (interpolation | 811 | (member_access_expression |
| 815 | (member_access_expression | 812 | expression: (identifier) @font-lock-variable-use-face))) |
| 816 | name: (identifier) @font-lock-property-use-face))) | 813 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) |
| 817 | ((interpolated_string_expression | 814 | ((element_access_expression (identifier) @font-lock-variable-use-face) |
| 818 | (interpolation | 815 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) |
| 819 | (member_access_expression | 816 | ((element_access_expression (identifier) @font-lock-variable-use-face) |
| 820 | expression: (identifier) @font-lock-variable-use-face))) | 817 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) |
| 821 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | 818 | ((return_statement (identifier) @font-lock-variable-use-face) |
| 822 | ((element_access_expression (identifier) @font-lock-variable-use-face) | 819 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) |
| 823 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | 820 | ((return_statement (member_access_expression |
| 824 | ((element_access_expression (identifier) @font-lock-variable-use-face) | 821 | expression: (identifier) @font-lock-variable-use-face)) |
| 825 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | 822 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) |
| 826 | ((return_statement (identifier) @font-lock-variable-use-face) | 823 | ((is_pattern_expression |
| 827 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | 824 | expression: (identifier) @font-lock-variable-use-face) |
| 828 | ((return_statement (member_access_expression | 825 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) |
| 829 | expression: (identifier) @font-lock-variable-use-face)) | 826 | ((is_pattern_expression |
| 830 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | 827 | expression: (member_access_expression |
| 831 | ((is_pattern_expression | 828 | expression: (identifier) @font-lock-variable-use-face)) |
| 832 | expression: (identifier) @font-lock-variable-use-face) | 829 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) |
| 833 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | 830 | (is_pattern_expression |
| 834 | ((is_pattern_expression | 831 | expression: (member_access_expression |
| 835 | expression: (member_access_expression | 832 | name: (identifier) @font-lock-property-use-face)) |
| 836 | expression: (identifier) @font-lock-variable-use-face)) | 833 | (is_pattern_expression |
| 837 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | 834 | pattern: (constant_pattern (identifier) @font-lock-type-face)) |
| 838 | (is_pattern_expression | 835 | (is_pattern_expression |
| 839 | expression: (member_access_expression | 836 | pattern: (constant_pattern (member_access_expression |
| 840 | name: (identifier) @font-lock-property-use-face)) | 837 | name: (identifier) @font-lock-type-face))) |
| 841 | (is_pattern_expression | 838 | ((binary_expression |
| 842 | pattern: (constant_pattern (identifier) @font-lock-type-face)) | 839 | left: (identifier) @font-lock-variable-use-face) |
| 843 | (is_pattern_expression | 840 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) |
| 844 | pattern: (constant_pattern (member_access_expression | 841 | ((binary_expression |
| 845 | name: (identifier) @font-lock-type-face))) | 842 | right: (identifier) @font-lock-variable-use-face) |
| 846 | ((binary_expression | 843 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) |
| 847 | left: (identifier) @font-lock-variable-use-face) | 844 | (assignment_expression |
| 848 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | 845 | right: (identifier) @font-lock-variable-use-face) |
| 849 | ((binary_expression | 846 | (expression_statement ;; capture parent node to NOT shadow variable_declaration. |
| 850 | right: (identifier) @font-lock-variable-use-face) | 847 | (assignment_expression |
| 851 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | 848 | left: (identifier) @font-lock-variable-use-face)) |
| 852 | (assignment_expression | 849 | (if_statement condition: (identifier) @font-lock-variable-use-face) |
| 853 | right: (identifier) @font-lock-variable-use-face) | 850 | |
| 854 | (expression_statement ;; capture parent node to NOT shadow variable_declaration. | 851 | ;; handle more specific matchers before generalized variable-use fallback. |
| 855 | (assignment_expression | 852 | (invocation_expression |
| 856 | left: (identifier) @font-lock-variable-use-face)) | 853 | function: (member_access_expression |
| 857 | (if_statement condition: (identifier) @font-lock-variable-use-face) | 854 | name: (identifier) @font-lock-function-call-face)) |
| 858 | 855 | (invocation_expression | |
| 859 | ;; handle more specific matchers before generalized variable-use fallback. | 856 | function: (member_access_expression |
| 860 | (invocation_expression | 857 | name: (generic_name (identifier) @font-lock-function-call-face))) |
| 861 | function: (member_access_expression | 858 | (member_access_expression |
| 862 | name: (identifier) @font-lock-function-call-face)) | 859 | expression: (identifier) @font-lock-variable-use-face |
| 863 | (invocation_expression | 860 | name: (identifier) @font-lock-property-use-face)) |
| 864 | function: (member_access_expression | 861 | |
| 865 | name: (generic_name (identifier) @font-lock-function-call-face))) | 862 | :language 'c-sharp |
| 866 | (member_access_expression | 863 | :feature 'bracket |
| 867 | expression: (identifier) @font-lock-variable-use-face | 864 | '((["(" ")" "[" "]" "{" "}" (interpolation_brace)]) @font-lock-bracket-face) |
| 865 | |||
| 866 | :language 'c-sharp | ||
| 867 | :feature 'delimiter | ||
| 868 | '((["," ":" ";"]) @font-lock-delimiter-face) | ||
| 869 | |||
| 870 | :language 'c-sharp | ||
| 871 | :feature 'error | ||
| 872 | '((ERROR) @font-lock-warning-face) | ||
| 873 | |||
| 874 | :language 'c-sharp | ||
| 875 | :override t | ||
| 876 | :feature 'comment | ||
| 877 | '((comment) @font-lock-comment-face) | ||
| 878 | |||
| 879 | :language 'c-sharp | ||
| 880 | :override t | ||
| 881 | :feature 'keyword | ||
| 882 | `([,@csharp-ts-mode--keywords] @font-lock-keyword-face | ||
| 883 | (modifier) @font-lock-keyword-face | ||
| 884 | ,@(if (csharp-ts-mode--test-this-expression) | ||
| 885 | '((this_expression) @font-lock-keyword-face) | ||
| 886 | '("this" @font-lock-keyword-face)) | ||
| 887 | |||
| 888 | ;; avoid fontifying indentifiers with a keyword-values as identifiers. | ||
| 889 | ((identifier) @font-lock-keyword-face | ||
| 890 | (:match ,(concat "\\`" (regexp-opt csharp-ts-mode--keywords t) "\\'") @font-lock-keyword-face))) | ||
| 891 | |||
| 892 | :language 'c-sharp | ||
| 893 | :override t | ||
| 894 | :feature 'attribute | ||
| 895 | `((attribute_list | ||
| 896 | "[" @csharp-ts-mode-attribute-face | ||
| 897 | (attribute name: (identifier) @csharp-ts-mode-attribute-face) | ||
| 898 | "]" @csharp-ts-mode-attribute-face)) | ||
| 899 | |||
| 900 | :language 'c-sharp | ||
| 901 | :override t | ||
| 902 | :feature 'escape-sequence | ||
| 903 | '((escape_sequence) @font-lock-escape-face) | ||
| 904 | |||
| 905 | :language 'c-sharp | ||
| 906 | :override t | ||
| 907 | :feature 'literal | ||
| 908 | `((integer_literal) @font-lock-number-face | ||
| 909 | (real_literal) @font-lock-number-face | ||
| 910 | (null_literal) @font-lock-constant-face | ||
| 911 | (boolean_literal) @font-lock-constant-face) | ||
| 912 | |||
| 913 | :language 'c-sharp | ||
| 914 | :feature 'string | ||
| 915 | `([(string_literal) | ||
| 916 | (verbatim_string_literal) | ||
| 917 | ,@ (when (csharp-ts-mode--test-string-content) | ||
| 918 | '((string_content) | ||
| 919 | "\"")) | ||
| 920 | ,@(if (csharp-ts-mode--test-interpolated-string-text) | ||
| 921 | '((interpolated_string_text) | ||
| 922 | (interpolated_verbatim_string_text) | ||
| 923 | (character_literal) | ||
| 924 | "\"" | ||
| 925 | "$\"" | ||
| 926 | "@$\"" | ||
| 927 | "$@\"") | ||
| 928 | '((interpolation_start) | ||
| 929 | (interpolation_quote)))] | ||
| 930 | @font-lock-string-face) | ||
| 931 | |||
| 932 | :language 'c-sharp | ||
| 933 | :feature 'type | ||
| 934 | `((predefined_type) @font-lock-type-face | ||
| 935 | (implicit_type) @font-lock-type-face | ||
| 936 | (nullable_type) @font-lock-type-face | ||
| 937 | (type_parameter | ||
| 938 | (identifier) @font-lock-type-face) | ||
| 939 | (type_argument_list | ||
| 940 | (identifier) @font-lock-type-face) | ||
| 941 | (type_argument_list | ||
| 942 | (generic_name | ||
| 943 | (identifier) @font-lock-type-face)) | ||
| 944 | (base_list | ||
| 945 | (generic_name | ||
| 946 | (identifier) @font-lock-type-face)) | ||
| 947 | (array_type | ||
| 948 | (identifier) @font-lock-type-face) | ||
| 949 | (qualified_name | ||
| 950 | name: (generic_name (identifier) @font-lock-type-face)) | ||
| 951 | (cast_expression (identifier) @font-lock-type-face) | ||
| 952 | (cast_expression (generic_name (identifier) @font-lock-type-face)) | ||
| 953 | ["operator"] @font-lock-type-face | ||
| 954 | (type_parameter_constraints_clause | ||
| 955 | (identifier) @font-lock-type-face) | ||
| 956 | ,@(if (csharp-ts-mode--test-type-constraint) | ||
| 957 | '((type_constraint type: (identifier) @font-lock-type-face) | ||
| 958 | (type_constraint type: (generic_name (identifier) @font-lock-type-face))) | ||
| 959 | '((type_parameter_constraint (type type: (identifier) @font-lock-type-face)) | ||
| 960 | (type_parameter_constraint (type type: (generic_name (identifier) @font-lock-type-face))))) | ||
| 961 | |||
| 962 | ,@(when (csharp-ts-mode--test-type-of-expression) | ||
| 963 | '((type_of_expression (identifier) @font-lock-type-face))) | ||
| 964 | |||
| 965 | ,@(when (csharp-ts-mode--test-typeof-expression) | ||
| 966 | '((typeof_expression (identifier) @font-lock-type-face))) | ||
| 967 | |||
| 968 | (object_creation_expression | ||
| 969 | type: (identifier) @font-lock-type-face) | ||
| 970 | (object_creation_expression | ||
| 971 | type: (generic_name (identifier) @font-lock-type-face)) | ||
| 972 | (as_expression right: (identifier) @font-lock-type-face) | ||
| 973 | (as_expression right: (generic_name (identifier) @font-lock-type-face))) | ||
| 974 | |||
| 975 | :language 'c-sharp | ||
| 976 | :feature 'definition | ||
| 977 | `((qualified_name (identifier) @font-lock-type-face) | ||
| 978 | (using_directive (identifier) @font-lock-type-face) | ||
| 979 | ,@(when (csharp-ts-mode--test-name-equals) | ||
| 980 | '((using_directive (name_equals | ||
| 981 | (identifier) @font-lock-type-face)))) | ||
| 982 | |||
| 983 | (enum_declaration (identifier) @font-lock-type-face) | ||
| 984 | (enum_member_declaration (identifier) @font-lock-variable-name-face) | ||
| 985 | (field_declaration (variable_declaration (variable_declarator | ||
| 986 | name: (identifier) @font-lock-variable-name-face))) | ||
| 987 | |||
| 988 | (interface_declaration (identifier) @font-lock-type-face) | ||
| 989 | |||
| 990 | (struct_declaration (identifier) @font-lock-type-face) | ||
| 991 | |||
| 992 | (record_declaration (identifier) @font-lock-type-face) | ||
| 993 | (namespace_declaration (identifier) @font-lock-type-face) | ||
| 994 | (base_list (identifier) @font-lock-type-face) | ||
| 995 | (property_declaration | ||
| 996 | type: (nullable_type) @font-lock-type-face | ||
| 997 | name: (identifier) @font-lock-variable-name-face) | ||
| 998 | (property_declaration | ||
| 999 | type: (predefined_type) @font-lock-type-face | ||
| 1000 | name: (identifier) @font-lock-variable-name-face) | ||
| 1001 | (property_declaration | ||
| 1002 | type: (identifier) @font-lock-type-face | ||
| 1003 | name: (identifier) @font-lock-variable-name-face) | ||
| 1004 | (class_declaration (identifier) @font-lock-type-face) | ||
| 1005 | |||
| 1006 | (constructor_declaration name: (_) @font-lock-type-face) | ||
| 1007 | ;; Handle different releases of tree-sitter-c-sharp. | ||
| 1008 | ;; Check if keyword void_keyword is available, then return the correct rule." | ||
| 1009 | ,@(condition-case nil | ||
| 1010 | (progn (treesit-query-capture 'csharp '((void_keyword) @capture)) | ||
| 1011 | `((method_declaration ,csharp-ts-mode--type-field [(identifier) (void_keyword)] @font-lock-type-face))) | ||
| 1012 | (error | ||
| 1013 | `((method_declaration ,csharp-ts-mode--type-field [(identifier) (predefined_type)] @font-lock-type-face)))) | ||
| 1014 | (method_declaration ,csharp-ts-mode--type-field (generic_name (identifier) @font-lock-type-face)) | ||
| 1015 | (method_declaration name: (_) @font-lock-function-name-face) | ||
| 1016 | |||
| 1017 | ;; only fontify known expression-types, to avoid the need to use :override | ||
| 1018 | ;; for lambda-expressions in 'function below. | ||
| 1019 | (variable_declarator | ||
| 1020 | name: (identifier) @font-lock-variable-name-face | ||
| 1021 | [(object_creation_expression) | ||
| 1022 | (integer_literal) | ||
| 1023 | (string_literal) | ||
| 1024 | (binary_expression) | ||
| 1025 | (invocation_expression) | ||
| 1026 | (await_expression) | ||
| 1027 | (member_access_expression) | ||
| 1028 | (conditional_expression)]) | ||
| 1029 | |||
| 1030 | (catch_declaration | ||
| 1031 | ((identifier) @font-lock-type-face)) | ||
| 1032 | (catch_declaration | ||
| 1033 | ((identifier) @font-lock-type-face | ||
| 1034 | (identifier) @font-lock-variable-name-face)) | ||
| 1035 | |||
| 1036 | (variable_declaration (identifier) @font-lock-type-face) | ||
| 1037 | (variable_declaration (qualified_name | ||
| 1038 | name: (generic_name (identifier) @font-lock-type-face))) | ||
| 1039 | (variable_declaration (generic_name (identifier) @font-lock-type-face)) | ||
| 1040 | |||
| 1041 | (parameter type: (identifier) @font-lock-type-face) | ||
| 1042 | (parameter type: (generic_name (identifier) @font-lock-type-face)) | ||
| 1043 | (parameter name: (identifier) @font-lock-variable-name-face) | ||
| 1044 | |||
| 1045 | (lambda_expression (identifier) @font-lock-variable-name-face) | ||
| 1046 | (lambda_expression | ||
| 1047 | parameters: (implicit_parameter) @font-lock-variable-name-face) | ||
| 1048 | |||
| 1049 | (declaration_expression type: (identifier) @font-lock-type-face) | ||
| 1050 | (declaration_expression name: (identifier) @font-lock-variable-name-face)) | ||
| 1051 | |||
| 1052 | :language 'c-sharp | ||
| 1053 | :feature 'function | ||
| 1054 | '((invocation_expression | ||
| 1055 | function: (identifier) @font-lock-function-call-face) | ||
| 1056 | ((invocation_expression | ||
| 1057 | function: (member_access_expression | ||
| 1058 | expression: (identifier) @font-lock-variable-use-face)) | ||
| 1059 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | ||
| 1060 | (argument (identifier) @font-lock-variable-use-face) | ||
| 1061 | ((argument (member_access_expression | ||
| 1062 | expression: (identifier) @font-lock-variable-use-face)) | ||
| 1063 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | ||
| 1064 | (argument (member_access_expression | ||
| 868 | name: (identifier) @font-lock-property-use-face)) | 1065 | name: (identifier) @font-lock-property-use-face)) |
| 869 | 1066 | ;; only highlight as function if variable contains lambda expression | |
| 870 | :language 'c-sharp | 1067 | (variable_declarator |
| 871 | :feature 'bracket | 1068 | name: (identifier) @font-lock-function-name-face |
| 872 | '((["(" ")" "[" "]" "{" "}" (interpolation_brace)]) @font-lock-bracket-face) | 1069 | (lambda_expression))) |
| 873 | 1070 | ||
| 874 | :language 'c-sharp | 1071 | :language 'c-sharp |
| 875 | :feature 'delimiter | 1072 | :feature 'directives |
| 876 | '((["," ":" ";"]) @font-lock-delimiter-face) | 1073 | :override t |
| 877 | 1074 | (if (csharp-ts-mode--test-if-directive) | |
| 878 | :language 'c-sharp | 1075 | '((if_directive |
| 879 | :feature 'error | 1076 | "if" @font-lock-preprocessor-face |
| 880 | '((ERROR) @font-lock-warning-face) | 1077 | (identifier) @font-lock-variable-use-face) |
| 881 | 1078 | (elif_directive | |
| 882 | :language 'c-sharp | 1079 | "elif" @font-lock-preprocessor-face |
| 883 | :override t | 1080 | (identifier) @font-lock-variable-use-face) |
| 884 | :feature 'comment | 1081 | (else_directive) @font-lock-preprocessor-face |
| 885 | '((comment) @font-lock-comment-face) | 1082 | (endif_directive) @font-lock-preprocessor-face |
| 886 | 1083 | (define_directive | |
| 887 | :language 'c-sharp | 1084 | "define" @font-lock-preprocessor-face |
| 888 | :override t | 1085 | (identifier) @font-lock-variable-use-face) |
| 889 | :feature 'keyword | 1086 | (nullable_directive) @font-lock-preprocessor-face |
| 890 | `([,@csharp-ts-mode--keywords] @font-lock-keyword-face | 1087 | (pragma_directive) @font-lock-preprocessor-face |
| 891 | (modifier) @font-lock-keyword-face | 1088 | (region_directive) @font-lock-preprocessor-face |
| 892 | ,@(if (csharp-ts-mode--test-this-expression) | 1089 | (endregion_directive) @font-lock-preprocessor-face |
| 893 | '((this_expression) @font-lock-keyword-face) | 1090 | (region_directive |
| 894 | '("this" @font-lock-keyword-face)) | 1091 | (preproc_message) @font-lock-variable-use-face) |
| 895 | 1092 | (endregion_directive | |
| 896 | ;; avoid fontifying indentifiers with a keyword-values as identifiers. | 1093 | (preproc_message) @font-lock-variable-use-face)) |
| 897 | ((identifier) @font-lock-keyword-face | 1094 | '((preproc_if |
| 898 | (:match ,(concat "\\`" (regexp-opt csharp-ts-mode--keywords t) "\\'") @font-lock-keyword-face))) | 1095 | "#if" @font-lock-preprocessor-face |
| 899 | 1096 | (identifier) @font-lock-variable-use-face) | |
| 900 | :language 'c-sharp | 1097 | (preproc_elif |
| 901 | :override t | 1098 | "#elif" @font-lock-preprocessor-face |
| 902 | :feature 'attribute | 1099 | (identifier) @font-lock-variable-use-face) |
| 903 | `((attribute_list | 1100 | (preproc_else) @font-lock-preprocessor-face |
| 904 | "[" @csharp-ts-mode-attribute-face | 1101 | "#endif" @font-lock-preprocessor-face |
| 905 | (attribute name: (identifier) @csharp-ts-mode-attribute-face) | 1102 | (preproc_define |
| 906 | "]" @csharp-ts-mode-attribute-face)) | 1103 | "#define" @font-lock-preprocessor-face |
| 907 | 1104 | (preproc_arg) @font-lock-variable-use-face) | |
| 908 | :language 'c-sharp | 1105 | (preproc_nullable) @font-lock-preprocessor-face |
| 909 | :override t | 1106 | (preproc_pragma) @font-lock-preprocessor-face |
| 910 | :feature 'escape-sequence | 1107 | (preproc_region) @font-lock-preprocessor-face |
| 911 | '((escape_sequence) @font-lock-escape-face) | 1108 | (preproc_endregion) @font-lock-preprocessor-face |
| 912 | 1109 | (preproc_region | |
| 913 | :language 'c-sharp | 1110 | (preproc_arg) @font-lock-variable-use-face) |
| 914 | :override t | 1111 | (preproc_endregion |
| 915 | :feature 'literal | 1112 | (preproc_arg) @font-lock-variable-use-face))))) |
| 916 | `((integer_literal) @font-lock-number-face | ||
| 917 | (real_literal) @font-lock-number-face | ||
| 918 | (null_literal) @font-lock-constant-face | ||
| 919 | (boolean_literal) @font-lock-constant-face) | ||
| 920 | |||
| 921 | :language 'c-sharp | ||
| 922 | :feature 'string | ||
| 923 | `([(string_literal) | ||
| 924 | (verbatim_string_literal) | ||
| 925 | ,@ (when (csharp-ts-mode--test-string-content) | ||
| 926 | '((string_content) | ||
| 927 | "\"")) | ||
| 928 | ,@(if (csharp-ts-mode--test-interpolated-string-text) | ||
| 929 | '((interpolated_string_text) | ||
| 930 | (interpolated_verbatim_string_text) | ||
| 931 | (character_literal) | ||
| 932 | "\"" | ||
| 933 | "$\"" | ||
| 934 | "@$\"" | ||
| 935 | "$@\"") | ||
| 936 | '((interpolation_start) | ||
| 937 | (interpolation_quote)))] | ||
| 938 | @font-lock-string-face) | ||
| 939 | |||
| 940 | :language 'c-sharp | ||
| 941 | :feature 'type | ||
| 942 | `((predefined_type) @font-lock-type-face | ||
| 943 | (implicit_type) @font-lock-type-face | ||
| 944 | (nullable_type) @font-lock-type-face | ||
| 945 | (type_parameter | ||
| 946 | (identifier) @font-lock-type-face) | ||
| 947 | (type_argument_list | ||
| 948 | (identifier) @font-lock-type-face) | ||
| 949 | (type_argument_list | ||
| 950 | (generic_name | ||
| 951 | (identifier) @font-lock-type-face)) | ||
| 952 | (base_list | ||
| 953 | (generic_name | ||
| 954 | (identifier) @font-lock-type-face)) | ||
| 955 | (array_type | ||
| 956 | (identifier) @font-lock-type-face) | ||
| 957 | (qualified_name | ||
| 958 | name: (generic_name (identifier) @font-lock-type-face)) | ||
| 959 | (cast_expression (identifier) @font-lock-type-face) | ||
| 960 | (cast_expression (generic_name (identifier) @font-lock-type-face)) | ||
| 961 | ["operator"] @font-lock-type-face | ||
| 962 | (type_parameter_constraints_clause | ||
| 963 | (identifier) @font-lock-type-face) | ||
| 964 | ,@(if (csharp-ts-mode--test-type-constraint) | ||
| 965 | '((type_constraint type: (identifier) @font-lock-type-face) | ||
| 966 | (type_constraint type: (generic_name (identifier) @font-lock-type-face))) | ||
| 967 | '((type_parameter_constraint (type type: (identifier) @font-lock-type-face)) | ||
| 968 | (type_parameter_constraint (type type: (generic_name (identifier) @font-lock-type-face))))) | ||
| 969 | |||
| 970 | ,@(when (csharp-ts-mode--test-type-of-expression) | ||
| 971 | '((type_of_expression (identifier) @font-lock-type-face))) | ||
| 972 | |||
| 973 | ,@(when (csharp-ts-mode--test-typeof-expression) | ||
| 974 | '((typeof_expression (identifier) @font-lock-type-face))) | ||
| 975 | |||
| 976 | (object_creation_expression | ||
| 977 | type: (identifier) @font-lock-type-face) | ||
| 978 | (object_creation_expression | ||
| 979 | type: (generic_name (identifier) @font-lock-type-face)) | ||
| 980 | (as_expression right: (identifier) @font-lock-type-face) | ||
| 981 | (as_expression right: (generic_name (identifier) @font-lock-type-face))) | ||
| 982 | |||
| 983 | :language 'c-sharp | ||
| 984 | :feature 'definition | ||
| 985 | `((qualified_name (identifier) @font-lock-type-face) | ||
| 986 | (using_directive (identifier) @font-lock-type-face) | ||
| 987 | ,@(when (csharp-ts-mode--test-name-equals) | ||
| 988 | '((using_directive (name_equals | ||
| 989 | (identifier) @font-lock-type-face)))) | ||
| 990 | |||
| 991 | (enum_declaration (identifier) @font-lock-type-face) | ||
| 992 | (enum_member_declaration (identifier) @font-lock-variable-name-face) | ||
| 993 | (field_declaration (variable_declaration (variable_declarator | ||
| 994 | name: (identifier) @font-lock-variable-name-face))) | ||
| 995 | |||
| 996 | (interface_declaration (identifier) @font-lock-type-face) | ||
| 997 | |||
| 998 | (struct_declaration (identifier) @font-lock-type-face) | ||
| 999 | |||
| 1000 | (record_declaration (identifier) @font-lock-type-face) | ||
| 1001 | (namespace_declaration (identifier) @font-lock-type-face) | ||
| 1002 | (base_list (identifier) @font-lock-type-face) | ||
| 1003 | (property_declaration | ||
| 1004 | type: (nullable_type) @font-lock-type-face | ||
| 1005 | name: (identifier) @font-lock-variable-name-face) | ||
| 1006 | (property_declaration | ||
| 1007 | type: (predefined_type) @font-lock-type-face | ||
| 1008 | name: (identifier) @font-lock-variable-name-face) | ||
| 1009 | (property_declaration | ||
| 1010 | type: (identifier) @font-lock-type-face | ||
| 1011 | name: (identifier) @font-lock-variable-name-face) | ||
| 1012 | (class_declaration (identifier) @font-lock-type-face) | ||
| 1013 | |||
| 1014 | (constructor_declaration name: (_) @font-lock-type-face) | ||
| 1015 | ;; Handle different releases of tree-sitter-c-sharp. | ||
| 1016 | ;; Check if keyword void_keyword is available, then return the correct rule." | ||
| 1017 | ,@(condition-case nil | ||
| 1018 | (progn (treesit-query-capture 'csharp '((void_keyword) @capture)) | ||
| 1019 | `((method_declaration ,csharp-ts-mode--type-field [(identifier) (void_keyword)] @font-lock-type-face))) | ||
| 1020 | (error | ||
| 1021 | `((method_declaration ,csharp-ts-mode--type-field [(identifier) (predefined_type)] @font-lock-type-face)))) | ||
| 1022 | (method_declaration ,csharp-ts-mode--type-field (generic_name (identifier) @font-lock-type-face)) | ||
| 1023 | (method_declaration name: (_) @font-lock-function-name-face) | ||
| 1024 | |||
| 1025 | ;; only fontify known expression-types, to avoid the need to use :override | ||
| 1026 | ;; for lambda-expressions in 'function below. | ||
| 1027 | (variable_declarator | ||
| 1028 | name: (identifier) @font-lock-variable-name-face | ||
| 1029 | [(object_creation_expression) | ||
| 1030 | (integer_literal) | ||
| 1031 | (string_literal) | ||
| 1032 | (binary_expression) | ||
| 1033 | (invocation_expression) | ||
| 1034 | (await_expression) | ||
| 1035 | (member_access_expression) | ||
| 1036 | (conditional_expression)]) | ||
| 1037 | |||
| 1038 | (catch_declaration | ||
| 1039 | ((identifier) @font-lock-type-face)) | ||
| 1040 | (catch_declaration | ||
| 1041 | ((identifier) @font-lock-type-face | ||
| 1042 | (identifier) @font-lock-variable-name-face)) | ||
| 1043 | |||
| 1044 | (variable_declaration (identifier) @font-lock-type-face) | ||
| 1045 | (variable_declaration (qualified_name | ||
| 1046 | name: (generic_name (identifier) @font-lock-type-face))) | ||
| 1047 | (variable_declaration (generic_name (identifier) @font-lock-type-face)) | ||
| 1048 | |||
| 1049 | (parameter type: (identifier) @font-lock-type-face) | ||
| 1050 | (parameter type: (generic_name (identifier) @font-lock-type-face)) | ||
| 1051 | (parameter name: (identifier) @font-lock-variable-name-face) | ||
| 1052 | |||
| 1053 | (lambda_expression (identifier) @font-lock-variable-name-face) | ||
| 1054 | (lambda_expression | ||
| 1055 | parameters: (implicit_parameter) @font-lock-variable-name-face) | ||
| 1056 | |||
| 1057 | (declaration_expression type: (identifier) @font-lock-type-face) | ||
| 1058 | (declaration_expression name: (identifier) @font-lock-variable-name-face)) | ||
| 1059 | |||
| 1060 | :language 'c-sharp | ||
| 1061 | :feature 'function | ||
| 1062 | '((invocation_expression | ||
| 1063 | function: (identifier) @font-lock-function-call-face) | ||
| 1064 | ((invocation_expression | ||
| 1065 | function: (member_access_expression | ||
| 1066 | expression: (identifier) @font-lock-variable-use-face)) | ||
| 1067 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | ||
| 1068 | (argument (identifier) @font-lock-variable-use-face) | ||
| 1069 | ((argument (member_access_expression | ||
| 1070 | expression: (identifier) @font-lock-variable-use-face)) | ||
| 1071 | (:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face)) | ||
| 1072 | (argument (member_access_expression | ||
| 1073 | name: (identifier) @font-lock-property-use-face)) | ||
| 1074 | ;; only highlight as function if variable contains lambda expression | ||
| 1075 | (variable_declarator | ||
| 1076 | name: (identifier) @font-lock-function-name-face | ||
| 1077 | (lambda_expression))) | ||
| 1078 | |||
| 1079 | :language 'c-sharp | ||
| 1080 | :feature 'directives | ||
| 1081 | :override t | ||
| 1082 | (if (csharp-ts-mode--test-if-directive) | ||
| 1083 | '((if_directive | ||
| 1084 | "if" @font-lock-preprocessor-face | ||
| 1085 | (identifier) @font-lock-variable-use-face) | ||
| 1086 | (elif_directive | ||
| 1087 | "elif" @font-lock-preprocessor-face | ||
| 1088 | (identifier) @font-lock-variable-use-face) | ||
| 1089 | (else_directive) @font-lock-preprocessor-face | ||
| 1090 | (endif_directive) @font-lock-preprocessor-face | ||
| 1091 | (define_directive | ||
| 1092 | "define" @font-lock-preprocessor-face | ||
| 1093 | (identifier) @font-lock-variable-use-face) | ||
| 1094 | (nullable_directive) @font-lock-preprocessor-face | ||
| 1095 | (pragma_directive) @font-lock-preprocessor-face | ||
| 1096 | (region_directive) @font-lock-preprocessor-face | ||
| 1097 | (endregion_directive) @font-lock-preprocessor-face | ||
| 1098 | (region_directive | ||
| 1099 | (preproc_message) @font-lock-variable-use-face) | ||
| 1100 | (endregion_directive | ||
| 1101 | (preproc_message) @font-lock-variable-use-face)) | ||
| 1102 | '((preproc_if | ||
| 1103 | "#if" @font-lock-preprocessor-face | ||
| 1104 | (identifier) @font-lock-variable-use-face) | ||
| 1105 | (preproc_elif | ||
| 1106 | "#elif" @font-lock-preprocessor-face | ||
| 1107 | (identifier) @font-lock-variable-use-face) | ||
| 1108 | (preproc_else) @font-lock-preprocessor-face | ||
| 1109 | "#endif" @font-lock-preprocessor-face | ||
| 1110 | (preproc_define | ||
| 1111 | "#define" @font-lock-preprocessor-face | ||
| 1112 | (preproc_arg) @font-lock-variable-use-face) | ||
| 1113 | (preproc_nullable) @font-lock-preprocessor-face | ||
| 1114 | (preproc_pragma) @font-lock-preprocessor-face | ||
| 1115 | (preproc_region) @font-lock-preprocessor-face | ||
| 1116 | (preproc_endregion) @font-lock-preprocessor-face | ||
| 1117 | (preproc_region | ||
| 1118 | (preproc_arg) @font-lock-variable-use-face) | ||
| 1119 | (preproc_endregion | ||
| 1120 | (preproc_arg) @font-lock-variable-use-face))))))) | ||
| 1121 | 1113 | ||
| 1122 | ;;;###autoload | 1114 | ;;;###autoload |
| 1123 | (add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-mode)) | 1115 | (add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-mode)) |
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 15304486a5b..8d37bb53988 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el | |||
| @@ -3513,72 +3513,64 @@ characters of the current line." | |||
| 3513 | node parent bol args) | 3513 | node parent bol args) |
| 3514 | js-indent-level))) | 3514 | js-indent-level))) |
| 3515 | 3515 | ||
| 3516 | (defvar js--treesit-indent-rules-cached nil | ||
| 3517 | "Cached tree-sitter indent rules for `js-ts-mode'.") | ||
| 3518 | |||
| 3519 | (defun js--treesit-indent-rules () | 3516 | (defun js--treesit-indent-rules () |
| 3520 | "Return tree-sitter indent rules for `js-ts-mode'. | 3517 | "Return tree-sitter indent rules for `js-ts-mode'." |
| 3521 | 3518 | `((javascript | |
| 3522 | Tree-sitter indent rules are evaluated the first time this function is | 3519 | ((parent-is "program") parent-bol 0) |
| 3523 | called. Subsequent calls return the first evaluated value." | 3520 | ((node-is "}") standalone-parent 0) |
| 3524 | (or js--treesit-indent-rules-cached | 3521 | ((node-is ")") parent-bol 0) |
| 3525 | (setq js--treesit-indent-rules-cached | 3522 | ((node-is "]") parent-bol 0) |
| 3526 | `((javascript | 3523 | ((node-is ">") parent-bol 0) |
| 3527 | ((parent-is "program") parent-bol 0) | 3524 | ((and (parent-is "comment") c-ts-common-looking-at-star) |
| 3528 | ((node-is "}") standalone-parent 0) | 3525 | c-ts-common-comment-start-after-first-star -1) |
| 3529 | ((node-is ")") parent-bol 0) | 3526 | ((parent-is "comment") prev-adaptive-prefix 0) |
| 3530 | ((node-is "]") parent-bol 0) | 3527 | ((n-p-gp "identifier" "ternary_expression" "parenthesized_expression") |
| 3531 | ((node-is ">") parent-bol 0) | 3528 | parent 0) |
| 3532 | ((and (parent-is "comment") c-ts-common-looking-at-star) | 3529 | ((parent-is "ternary_expression") parent-bol js-indent-level) |
| 3533 | c-ts-common-comment-start-after-first-star -1) | 3530 | ((parent-is "sequence_expression") parent 0) |
| 3534 | ((parent-is "comment") prev-adaptive-prefix 0) | 3531 | ((parent-is "member_expression") js--treesit-member-chained-expression-helper 0) |
| 3535 | ((n-p-gp "identifier" "ternary_expression" "parenthesized_expression") | 3532 | ((parent-is "named_imports") parent-bol js-indent-level) |
| 3536 | parent 0) | 3533 | ((parent-is "statement_block") standalone-parent js-indent-level) |
| 3537 | ((parent-is "ternary_expression") parent-bol js-indent-level) | 3534 | ((parent-is "variable_declarator") parent 0) |
| 3538 | ((parent-is "sequence_expression") parent 0) | 3535 | ((parent-is "arguments") parent-bol js-indent-level) |
| 3539 | ((parent-is "member_expression") js--treesit-member-chained-expression-helper 0) | 3536 | ((parent-is "array") parent-bol js-indent-level) |
| 3540 | ((parent-is "named_imports") parent-bol js-indent-level) | 3537 | ((parent-is "formal_parameters") parent-bol js-indent-level) |
| 3541 | ((parent-is "statement_block") standalone-parent js-indent-level) | 3538 | ((parent-is "template_string") no-indent) ; Don't indent the string contents. |
| 3542 | ((parent-is "variable_declarator") parent 0) | 3539 | ((parent-is "template_substitution") parent-bol js-indent-level) |
| 3543 | ((parent-is "arguments") parent-bol js-indent-level) | 3540 | ((parent-is "object_pattern") parent-bol js-indent-level) |
| 3544 | ((parent-is "array") parent-bol js-indent-level) | 3541 | ((parent-is "object") parent-bol js-indent-level) |
| 3545 | ((parent-is "formal_parameters") parent-bol js-indent-level) | 3542 | ((parent-is "pair") parent-bol js-indent-level) |
| 3546 | ((parent-is "template_string") no-indent) ; Don't indent the string contents. | 3543 | ((parent-is "arrow_function") js--treesit-arrow-function-helper 0) |
| 3547 | ((parent-is "template_substitution") parent-bol js-indent-level) | 3544 | ((parent-is "parenthesized_expression") parent-bol js-indent-level) |
| 3548 | ((parent-is "object_pattern") parent-bol js-indent-level) | 3545 | ((parent-is "binary_expression") parent-bol js-indent-level) |
| 3549 | ((parent-is "object") parent-bol js-indent-level) | 3546 | ((parent-is "assignment_expression") parent-bol js-indent-level) |
| 3550 | ((parent-is "pair") parent-bol js-indent-level) | 3547 | ((parent-is "class_body") parent-bol js-indent-level) |
| 3551 | ((parent-is "arrow_function") js--treesit-arrow-function-helper 0) | 3548 | ;; "{" on the newline, should stay here. |
| 3552 | ((parent-is "parenthesized_expression") parent-bol js-indent-level) | 3549 | ((node-is "statement_block") parent-bol 0) |
| 3553 | ((parent-is "binary_expression") parent-bol js-indent-level) | 3550 | ((parent-is "switch_statement") parent-bol 0) |
| 3554 | ((parent-is "assignment_expression") parent-bol js-indent-level) | 3551 | ((parent-is "switch_body") js--treesit-switch-body-helper 0) |
| 3555 | ((parent-is "class_body") parent-bol js-indent-level) | 3552 | ((parent-is ,(rx "switch_" (or "case" "default"))) parent-bol js-indent-level) |
| 3556 | ;; "{" on the newline, should stay here. | 3553 | ((match "while" "do_statement") parent-bol 0) |
| 3557 | ((node-is "statement_block") parent-bol 0) | 3554 | ((match "else" "if_statement") parent-bol 0) |
| 3558 | ((parent-is "switch_statement") parent-bol 0) | 3555 | ((parent-is ,(rx (or (seq (or "if" "for" "for_in" "while" "do") "_statement") |
| 3559 | ((parent-is "switch_body") js--treesit-switch-body-helper 0) | 3556 | "else_clause"))) |
| 3560 | ((parent-is ,(rx "switch_" (or "case" "default"))) parent-bol js-indent-level) | 3557 | parent-bol js-indent-level) |
| 3561 | ((match "while" "do_statement") parent-bol 0) | 3558 | |
| 3562 | ((match "else" "if_statement") parent-bol 0) | 3559 | ;; JSX |
| 3563 | ((parent-is ,(rx (or (seq (or "if" "for" "for_in" "while" "do") "_statement") | 3560 | ,@(js-jsx--treesit-indent-compatibility-bb1f97b) |
| 3564 | "else_clause"))) | 3561 | ((node-is "jsx_closing_element") parent 0) |
| 3565 | parent-bol js-indent-level) | 3562 | ((match "jsx_element" "statement") parent js-indent-level) |
| 3566 | 3563 | ((parent-is "jsx_element") parent js-indent-level) | |
| 3567 | ;; JSX | 3564 | ((parent-is "jsx_text") parent-bol js-indent-level) |
| 3568 | ,@(js-jsx--treesit-indent-compatibility-bb1f97b) | 3565 | ((parent-is "jsx_opening_element") parent js-indent-level) |
| 3569 | ((node-is "jsx_closing_element") parent 0) | 3566 | ((parent-is "jsx_expression") parent-bol js-indent-level) |
| 3570 | ((match "jsx_element" "statement") parent js-indent-level) | 3567 | ((match "/" "jsx_self_closing_element") parent 0) |
| 3571 | ((parent-is "jsx_element") parent js-indent-level) | 3568 | ((parent-is "jsx_self_closing_element") parent js-indent-level) |
| 3572 | ((parent-is "jsx_text") parent-bol js-indent-level) | 3569 | ;; FIXME(Theo): This no-node catch-all should be removed. When is it needed? |
| 3573 | ((parent-is "jsx_opening_element") parent js-indent-level) | 3570 | (no-node parent-bol 0)) |
| 3574 | ((parent-is "jsx_expression") parent-bol js-indent-level) | 3571 | (jsdoc |
| 3575 | ((match "/" "jsx_self_closing_element") parent 0) | 3572 | ((and (parent-is "document") c-ts-common-looking-at-star) |
| 3576 | ((parent-is "jsx_self_closing_element") parent js-indent-level) | 3573 | c-ts-common-comment-start-after-first-star -1)))) |
| 3577 | ;; FIXME(Theo): This no-node catch-all should be removed. When is it needed? | ||
| 3578 | (no-node parent-bol 0)) | ||
| 3579 | (jsdoc | ||
| 3580 | ((and (parent-is "document") c-ts-common-looking-at-star) | ||
| 3581 | c-ts-common-comment-start-after-first-star -1)))))) | ||
| 3582 | 3574 | ||
| 3583 | (defvar js--treesit-keywords | 3575 | (defvar js--treesit-keywords |
| 3584 | '("as" "async" "await" "break" "case" "catch" "class" "const" "continue" | 3576 | '("as" "async" "await" "break" "case" "catch" "class" "const" "continue" |
| @@ -3595,162 +3587,154 @@ called. Subsequent calls return the first evaluated value." | |||
| 3595 | "&&" "||" "!") | 3587 | "&&" "||" "!") |
| 3596 | "JavaScript operators for tree-sitter font-locking.") | 3588 | "JavaScript operators for tree-sitter font-locking.") |
| 3597 | 3589 | ||
| 3598 | (defvar js--treesit-font-lock-settings-cached nil | ||
| 3599 | "Cached tree-sitter font-lock settings for `js-ts-mode'.") | ||
| 3600 | |||
| 3601 | (defun js--treesit-font-lock-settings () | 3590 | (defun js--treesit-font-lock-settings () |
| 3602 | "Return tree-sitter font-lock settings for `js-ts-mode'. | 3591 | "Return tree-sitter font-lock settings for `js-ts-mode'." |
| 3603 | 3592 | (treesit-font-lock-rules | |
| 3604 | Tree-sitter font-lock settings are evaluated the first time this | 3593 | |
| 3605 | function is called. Subsequent calls return the first evaluated value." | 3594 | :language 'javascript |
| 3606 | (or js--treesit-font-lock-settings-cached | 3595 | :feature 'comment |
| 3607 | (setq js--treesit-font-lock-settings-cached | 3596 | '([(comment) (hash_bang_line)] @font-lock-comment-face) |
| 3608 | (treesit-font-lock-rules | 3597 | |
| 3609 | 3598 | :language 'javascript | |
| 3610 | :language 'javascript | 3599 | :feature 'constant |
| 3611 | :feature 'comment | 3600 | '(((identifier) @font-lock-constant-face |
| 3612 | '([(comment) (hash_bang_line)] @font-lock-comment-face) | 3601 | (:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face)) |
| 3613 | 3602 | ||
| 3614 | :language 'javascript | 3603 | [(true) (false) (null)] @font-lock-constant-face) |
| 3615 | :feature 'constant | 3604 | |
| 3616 | '(((identifier) @font-lock-constant-face | 3605 | :language 'javascript |
| 3617 | (:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face)) | 3606 | :feature 'keyword |
| 3618 | 3607 | `([,@js--treesit-keywords] @font-lock-keyword-face | |
| 3619 | [(true) (false) (null)] @font-lock-constant-face) | 3608 | [(this) (super)] @font-lock-keyword-face) |
| 3620 | 3609 | ||
| 3621 | :language 'javascript | 3610 | :language 'javascript |
| 3622 | :feature 'keyword | 3611 | :feature 'string |
| 3623 | `([,@js--treesit-keywords] @font-lock-keyword-face | 3612 | '((regex pattern: (regex_pattern)) @font-lock-regexp-face |
| 3624 | [(this) (super)] @font-lock-keyword-face) | 3613 | (string) @font-lock-string-face) |
| 3625 | 3614 | ||
| 3626 | :language 'javascript | 3615 | :language 'javascript |
| 3627 | :feature 'string | 3616 | :feature 'string-interpolation |
| 3628 | '((regex pattern: (regex_pattern)) @font-lock-regexp-face | 3617 | :override t |
| 3629 | (string) @font-lock-string-face) | 3618 | '((template_string) @js--fontify-template-string |
| 3630 | 3619 | (template_substitution ["${" "}"] @font-lock-misc-punctuation-face)) | |
| 3631 | :language 'javascript | 3620 | |
| 3632 | :feature 'string-interpolation | 3621 | :language 'javascript |
| 3633 | :override t | 3622 | :feature 'definition |
| 3634 | '((template_string) @js--fontify-template-string | 3623 | `(,@(js--treesit-font-lock-compatibility-definition-feature) |
| 3635 | (template_substitution ["${" "}"] @font-lock-misc-punctuation-face)) | 3624 | |
| 3636 | 3625 | (class | |
| 3637 | :language 'javascript | 3626 | name: (identifier) @font-lock-type-face) |
| 3638 | :feature 'definition | 3627 | |
| 3639 | `(,@(js--treesit-font-lock-compatibility-definition-feature) | 3628 | (class_declaration |
| 3640 | 3629 | name: (identifier) @font-lock-type-face) | |
| 3641 | (class | 3630 | |
| 3642 | name: (identifier) @font-lock-type-face) | 3631 | (function_declaration |
| 3643 | 3632 | name: (identifier) @font-lock-function-name-face) | |
| 3644 | (class_declaration | 3633 | |
| 3645 | name: (identifier) @font-lock-type-face) | 3634 | (method_definition |
| 3646 | 3635 | name: (property_identifier) @font-lock-function-name-face) | |
| 3647 | (function_declaration | 3636 | |
| 3648 | name: (identifier) @font-lock-function-name-face) | 3637 | (formal_parameters |
| 3649 | 3638 | [(identifier) @font-lock-variable-name-face | |
| 3650 | (method_definition | 3639 | (array_pattern (identifier) @font-lock-variable-name-face) |
| 3651 | name: (property_identifier) @font-lock-function-name-face) | 3640 | (object_pattern (shorthand_property_identifier_pattern) @font-lock-variable-name-face)]) |
| 3652 | 3641 | ||
| 3653 | (formal_parameters | 3642 | (variable_declarator |
| 3654 | [(identifier) @font-lock-variable-name-face | 3643 | name: (identifier) @font-lock-variable-name-face) |
| 3655 | (array_pattern (identifier) @font-lock-variable-name-face) | 3644 | |
| 3656 | (object_pattern (shorthand_property_identifier_pattern) @font-lock-variable-name-face)]) | 3645 | (variable_declarator |
| 3657 | 3646 | name: [(array_pattern (identifier) @font-lock-variable-name-face) | |
| 3658 | (variable_declarator | 3647 | (object_pattern |
| 3659 | name: (identifier) @font-lock-variable-name-face) | 3648 | (shorthand_property_identifier_pattern) @font-lock-variable-name-face)]) |
| 3660 | 3649 | ||
| 3661 | (variable_declarator | 3650 | ;; full module imports |
| 3662 | name: [(array_pattern (identifier) @font-lock-variable-name-face) | 3651 | (import_clause (identifier) @font-lock-variable-name-face) |
| 3663 | (object_pattern | 3652 | ;; named imports with aliasing |
| 3664 | (shorthand_property_identifier_pattern) @font-lock-variable-name-face)]) | 3653 | (import_clause (named_imports (import_specifier |
| 3665 | 3654 | alias: (identifier) @font-lock-variable-name-face))) | |
| 3666 | ;; full module imports | 3655 | ;; named imports without aliasing |
| 3667 | (import_clause (identifier) @font-lock-variable-name-face) | 3656 | (import_clause (named_imports (import_specifier |
| 3668 | ;; named imports with aliasing | 3657 | !alias |
| 3669 | (import_clause (named_imports (import_specifier | 3658 | name: (identifier) @font-lock-variable-name-face))) |
| 3670 | alias: (identifier) @font-lock-variable-name-face))) | 3659 | |
| 3671 | ;; named imports without aliasing | 3660 | ;; full namespace import (* as alias) |
| 3672 | (import_clause (named_imports (import_specifier | 3661 | (import_clause (namespace_import (identifier) @font-lock-variable-name-face))) |
| 3673 | !alias | 3662 | |
| 3674 | name: (identifier) @font-lock-variable-name-face))) | 3663 | :language 'javascript |
| 3675 | 3664 | :feature 'assignment | |
| 3676 | ;; full namespace import (* as alias) | 3665 | '((assignment_expression |
| 3677 | (import_clause (namespace_import (identifier) @font-lock-variable-name-face))) | 3666 | left: (_) @js--treesit-fontify-assignment-lhs)) |
| 3678 | 3667 | ||
| 3679 | :language 'javascript | 3668 | :language 'javascript |
| 3680 | :feature 'assignment | 3669 | :feature 'function |
| 3681 | '((assignment_expression | 3670 | '((call_expression |
| 3682 | left: (_) @js--treesit-fontify-assignment-lhs)) | 3671 | function: [(identifier) @font-lock-function-call-face |
| 3683 | 3672 | (member_expression | |
| 3684 | :language 'javascript | 3673 | property: |
| 3685 | :feature 'function | 3674 | (property_identifier) @font-lock-function-call-face)])) |
| 3686 | '((call_expression | 3675 | |
| 3687 | function: [(identifier) @font-lock-function-call-face | 3676 | :language 'javascript |
| 3688 | (member_expression | 3677 | :feature 'jsx |
| 3689 | property: | 3678 | '((jsx_opening_element name: (_) @font-lock-function-call-face) |
| 3690 | (property_identifier) @font-lock-function-call-face)])) | 3679 | (jsx_closing_element name: (_) @font-lock-function-call-face) |
| 3691 | 3680 | (jsx_self_closing_element name: (_) @font-lock-function-call-face) | |
| 3692 | :language 'javascript | 3681 | (jsx_attribute (property_identifier) @font-lock-constant-face)) |
| 3693 | :feature 'jsx | 3682 | |
| 3694 | '((jsx_opening_element name: (_) @font-lock-function-call-face) | 3683 | :language 'javascript |
| 3695 | (jsx_closing_element name: (_) @font-lock-function-call-face) | 3684 | :feature 'property |
| 3696 | (jsx_self_closing_element name: (_) @font-lock-function-call-face) | 3685 | '(((property_identifier) @font-lock-property-use-face) |
| 3697 | (jsx_attribute (property_identifier) @font-lock-constant-face)) | 3686 | (pair value: (identifier) @font-lock-variable-use-face) |
| 3698 | 3687 | ((shorthand_property_identifier) @font-lock-property-use-face)) | |
| 3699 | :language 'javascript | 3688 | |
| 3700 | :feature 'property | 3689 | :language 'javascript |
| 3701 | '(((property_identifier) @font-lock-property-use-face) | 3690 | :feature 'number |
| 3702 | (pair value: (identifier) @font-lock-variable-use-face) | 3691 | '((number) @font-lock-number-face |
| 3703 | ((shorthand_property_identifier) @font-lock-property-use-face)) | 3692 | ((identifier) @font-lock-number-face |
| 3704 | 3693 | (:match "\\`\\(?:NaN\\|Infinity\\)\\'" @font-lock-number-face))) | |
| 3705 | :language 'javascript | 3694 | |
| 3706 | :feature 'number | 3695 | :language 'javascript |
| 3707 | '((number) @font-lock-number-face | 3696 | :feature 'operator |
| 3708 | ((identifier) @font-lock-number-face | 3697 | `([,@js--treesit-operators] @font-lock-operator-face |
| 3709 | (:match "\\`\\(?:NaN\\|Infinity\\)\\'" @font-lock-number-face))) | 3698 | (ternary_expression ["?" ":"] @font-lock-operator-face)) |
| 3710 | 3699 | ||
| 3711 | :language 'javascript | 3700 | :language 'javascript |
| 3712 | :feature 'operator | 3701 | :feature 'bracket |
| 3713 | `([,@js--treesit-operators] @font-lock-operator-face | 3702 | '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face) |
| 3714 | (ternary_expression ["?" ":"] @font-lock-operator-face)) | 3703 | |
| 3715 | 3704 | :language 'javascript | |
| 3716 | :language 'javascript | 3705 | :feature 'delimiter |
| 3717 | :feature 'bracket | 3706 | '((["," "." ";" ":"]) @font-lock-delimiter-face) |
| 3718 | '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face) | 3707 | |
| 3719 | 3708 | :language 'javascript | |
| 3720 | :language 'javascript | 3709 | :feature 'escape-sequence |
| 3721 | :feature 'delimiter | 3710 | :override t |
| 3722 | '((["," "." ";" ":"]) @font-lock-delimiter-face) | 3711 | '((escape_sequence) @font-lock-escape-face) |
| 3723 | 3712 | ||
| 3724 | :language 'javascript | 3713 | ;; "document" should be first, to avoid overlap. |
| 3725 | :feature 'escape-sequence | 3714 | :language 'jsdoc |
| 3726 | :override t | 3715 | :override t |
| 3727 | '((escape_sequence) @font-lock-escape-face) | 3716 | :feature 'document |
| 3728 | 3717 | '((document) @font-lock-doc-face) | |
| 3729 | ;; "document" should be first, to avoid overlap. | 3718 | |
| 3730 | :language 'jsdoc | 3719 | :language 'jsdoc |
| 3731 | :override t | 3720 | :override t |
| 3732 | :feature 'document | 3721 | :feature 'keyword |
| 3733 | '((document) @font-lock-doc-face) | 3722 | '((tag_name) @font-lock-doc-markup-face) |
| 3734 | 3723 | ||
| 3735 | :language 'jsdoc | 3724 | :language 'jsdoc |
| 3736 | :override t | 3725 | :override t |
| 3737 | :feature 'keyword | 3726 | :feature 'bracket |
| 3738 | '((tag_name) @font-lock-doc-markup-face) | 3727 | '((["{" "}"]) @font-lock-bracket-face) |
| 3739 | 3728 | ||
| 3740 | :language 'jsdoc | 3729 | :language 'jsdoc |
| 3741 | :override t | 3730 | :override t |
| 3742 | :feature 'bracket | 3731 | :feature 'property |
| 3743 | '((["{" "}"]) @font-lock-bracket-face) | 3732 | '((type) @font-lock-type-face) |
| 3744 | 3733 | ||
| 3745 | :language 'jsdoc | 3734 | :language 'jsdoc |
| 3746 | :override t | 3735 | :override t |
| 3747 | :feature 'property | 3736 | :feature 'definition |
| 3748 | '((type) @font-lock-type-face) | 3737 | '((identifier) @font-lock-variable-name-face))) |
| 3749 | |||
| 3750 | :language 'jsdoc | ||
| 3751 | :override t | ||
| 3752 | :feature 'definition | ||
| 3753 | '((identifier) @font-lock-variable-name-face))))) | ||
| 3754 | 3738 | ||
| 3755 | (defun js--fontify-template-string (node override start end &rest _) | 3739 | (defun js--fontify-template-string (node override start end &rest _) |
| 3756 | "Fontify template string but not substitution inside it. | 3740 | "Fontify template string but not substitution inside it. |
diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el index ea06c3f9dc9..953c115e69e 100644 --- a/lisp/progmodes/php-ts-mode.el +++ b/lisp/progmodes/php-ts-mode.el | |||
| @@ -955,244 +955,228 @@ characters of the current line." | |||
| 955 | ("::" . ?∷)) | 955 | ("::" . ?∷)) |
| 956 | "Value for `prettify-symbols-alist' in `php-ts-mode'.") | 956 | "Value for `prettify-symbols-alist' in `php-ts-mode'.") |
| 957 | 957 | ||
| 958 | (defvar php-ts-mode--font-lock-settings-cached nil | ||
| 959 | "Cached tree-sitter font-lock settings for `php-ts-mode'.") | ||
| 960 | |||
| 961 | (defun php-ts-mode--font-lock-settings () | 958 | (defun php-ts-mode--font-lock-settings () |
| 962 | "Return tree-sitter font-lock settings for `php-ts-mode'. | 959 | "Return tree-sitter font-lock settings for `php-ts-mode'." |
| 963 | 960 | (treesit-font-lock-rules | |
| 964 | Tree-sitter font-lock settings are evaluated the first time this | 961 | |
| 965 | function is called. Subsequent calls return the first evaluated value." | 962 | :language 'php |
| 966 | (or php-ts-mode--font-lock-settings-cached | 963 | :feature 'keyword |
| 967 | (setq php-ts-mode--font-lock-settings-cached | 964 | :override t |
| 968 | (treesit-font-lock-rules | 965 | `([,@(php-ts-mode--keywords)] @font-lock-keyword-face |
| 969 | 966 | ,@(when (php-ts-mode--test-visibility-modifier-operation-p) | |
| 970 | :language 'php | 967 | '((visibility_modifier (operation) @font-lock-builtin-face))) |
| 971 | :feature 'keyword | 968 | (var_modifier) @font-lock-builtin-face) |
| 972 | :override t | 969 | |
| 973 | `([,@(php-ts-mode--keywords)] @font-lock-keyword-face | 970 | :language 'php |
| 974 | ,@(when (php-ts-mode--test-visibility-modifier-operation-p) | 971 | :feature 'comment |
| 975 | '((visibility_modifier (operation) @font-lock-builtin-face))) | 972 | :override t |
| 976 | (var_modifier) @font-lock-builtin-face) | 973 | '((comment) @font-lock-comment-face) |
| 977 | 974 | ||
| 978 | :language 'php | 975 | :language 'php |
| 979 | :feature 'comment | 976 | :feature 'constant |
| 980 | :override t | 977 | `((boolean) @font-lock-constant-face |
| 981 | '((comment) @font-lock-comment-face) | 978 | (null) @font-lock-constant-face |
| 982 | 979 | ;; predefined constant or built in constant (part of PHP core) | |
| 983 | :language 'php | 980 | ((name) @font-lock-builtin-face |
| 984 | :feature 'constant | 981 | (:match ,(rx-to-string |
| 985 | `((boolean) @font-lock-constant-face | 982 | `(: bos (or ,@php-ts-mode--predefined-constant) eos)) |
| 986 | (null) @font-lock-constant-face | 983 | @font-lock-builtin-face)) |
| 987 | ;; predefined constant or built in constant (part of PHP core) | 984 | ;; user defined constant |
| 988 | ((name) @font-lock-builtin-face | 985 | ((name) @font-lock-constant-face |
| 989 | (:match ,(rx-to-string | 986 | (:match "\\`_*[A-Z][0-9A-Z_]+\\'" @font-lock-constant-face)) |
| 990 | `(: bos (or ,@php-ts-mode--predefined-constant) eos)) | 987 | (const_declaration |
| 991 | @font-lock-builtin-face)) | 988 | (const_element (name) @font-lock-constant-face)) |
| 992 | ;; user defined constant | 989 | ;; declare directive |
| 993 | ((name) @font-lock-constant-face | 990 | (declare_directive ["strict_types" "encoding" "ticks"] @font-lock-constant-face)) |
| 994 | (:match "\\`_*[A-Z][0-9A-Z_]+\\'" @font-lock-constant-face)) | 991 | |
| 995 | (const_declaration | 992 | :language 'php |
| 996 | (const_element (name) @font-lock-constant-face)) | 993 | :feature 'name |
| 997 | ;; declare directive | 994 | '((goto_statement (name) @font-lock-constant-face) |
| 998 | (declare_directive ["strict_types" "encoding" "ticks"] @font-lock-constant-face)) | 995 | (named_label_statement (name) @font-lock-constant-face)) |
| 999 | 996 | ||
| 1000 | :language 'php | 997 | :language 'php |
| 1001 | :feature 'name | 998 | :feature 'delimiter |
| 1002 | '((goto_statement (name) @font-lock-constant-face) | 999 | `((["," ":" ";" "\\"]) @font-lock-delimiter-face) |
| 1003 | (named_label_statement (name) @font-lock-constant-face)) | 1000 | |
| 1004 | 1001 | :language 'php | |
| 1005 | :language 'php | 1002 | :feature 'operator |
| 1006 | :feature 'delimiter | 1003 | `((error_suppression_expression "@" @font-lock-keyword-face) |
| 1007 | `((["," ":" ";" "\\"]) @font-lock-delimiter-face) | 1004 | [,@(php-ts-mode--operators)] @font-lock-operator-face) |
| 1008 | 1005 | ||
| 1009 | :language 'php | 1006 | :language 'php |
| 1010 | :feature 'operator | 1007 | :feature 'variable-name |
| 1011 | `((error_suppression_expression "@" @font-lock-keyword-face) | 1008 | :override t |
| 1012 | [,@(php-ts-mode--operators)] @font-lock-operator-face) | 1009 | '(((name) @font-lock-keyword-face (:equal "this" @font-lock-keyword-face)) |
| 1013 | 1010 | (variable_name (name) @font-lock-variable-name-face) | |
| 1014 | :language 'php | 1011 | (relative_scope ["parent" "self" "static"] @font-lock-builtin-face) |
| 1015 | :feature 'variable-name | 1012 | (relative_scope) @font-lock-constant-face |
| 1016 | :override t | 1013 | (dynamic_variable_name (name) @font-lock-variable-name-face) |
| 1017 | '(((name) @font-lock-keyword-face (:equal "this" @font-lock-keyword-face)) | 1014 | (member_access_expression |
| 1018 | (variable_name (name) @font-lock-variable-name-face) | 1015 | name: (_) @font-lock-variable-name-face) |
| 1019 | (relative_scope ["parent" "self" "static"] @font-lock-builtin-face) | 1016 | (scoped_property_access_expression |
| 1020 | (relative_scope) @font-lock-constant-face | 1017 | scope: (name) @font-lock-constant-face) |
| 1021 | (dynamic_variable_name (name) @font-lock-variable-name-face) | 1018 | (nullsafe_member_access_expression (name) @font-lock-variable-name-face) |
| 1022 | (member_access_expression | 1019 | (error_suppression_expression (name) @font-lock-property-name-face)) |
| 1023 | name: (_) @font-lock-variable-name-face) | 1020 | |
| 1024 | (scoped_property_access_expression | 1021 | :language 'php |
| 1025 | scope: (name) @font-lock-constant-face) | 1022 | :feature 'string |
| 1026 | (nullsafe_member_access_expression (name) @font-lock-variable-name-face) | 1023 | `(("\"") @font-lock-string-face |
| 1027 | (error_suppression_expression (name) @font-lock-property-name-face)) | 1024 | (encapsed_string) @font-lock-string-face |
| 1028 | 1025 | (string_content) @font-lock-string-face | |
| 1029 | :language 'php | 1026 | (string) @font-lock-string-face) |
| 1030 | :feature 'string | 1027 | |
| 1031 | `(("\"") @font-lock-string-face | 1028 | :language 'php |
| 1032 | (encapsed_string) @font-lock-string-face | 1029 | :feature 'literal |
| 1033 | (string_content) @font-lock-string-face | 1030 | '((integer) @font-lock-number-face |
| 1034 | (string) @font-lock-string-face) | 1031 | (float) @font-lock-number-face |
| 1035 | 1032 | (heredoc identifier: (heredoc_start) @font-lock-constant-face) | |
| 1036 | :language 'php | 1033 | (heredoc_body (string_content) @font-lock-string-face) |
| 1037 | :feature 'literal | 1034 | (heredoc end_tag: (heredoc_end) @font-lock-constant-face) |
| 1038 | '((integer) @font-lock-number-face | 1035 | (nowdoc identifier: (heredoc_start) @font-lock-constant-face) |
| 1039 | (float) @font-lock-number-face | 1036 | (nowdoc_body (nowdoc_string) @font-lock-string-face) |
| 1040 | (heredoc identifier: (heredoc_start) @font-lock-constant-face) | 1037 | (nowdoc end_tag: (heredoc_end) @font-lock-constant-face) |
| 1041 | (heredoc_body (string_content) @font-lock-string-face) | 1038 | (shell_command_expression) @font-lock-string-face) |
| 1042 | (heredoc end_tag: (heredoc_end) @font-lock-constant-face) | 1039 | |
| 1043 | (nowdoc identifier: (heredoc_start) @font-lock-constant-face) | 1040 | :language 'php |
| 1044 | (nowdoc_body (nowdoc_string) @font-lock-string-face) | 1041 | :feature 'type |
| 1045 | (nowdoc end_tag: (heredoc_end) @font-lock-constant-face) | 1042 | :override t |
| 1046 | (shell_command_expression) @font-lock-string-face) | 1043 | '((union_type "|" @font-lock-operator-face) |
| 1047 | 1044 | (union_type) @font-lock-type-face | |
| 1048 | :language 'php | 1045 | (bottom_type) @font-lock-type-face |
| 1049 | :feature 'type | 1046 | (primitive_type) @font-lock-type-face |
| 1050 | :override t | 1047 | ((primitive_type) @font-lock-keyword-face |
| 1051 | '((union_type "|" @font-lock-operator-face) | 1048 | (:equal "callable" @font-lock-keyword-face)) |
| 1052 | (union_type) @font-lock-type-face | 1049 | (cast_type) @font-lock-type-face |
| 1053 | (bottom_type) @font-lock-type-face | 1050 | (named_type) @font-lock-type-face |
| 1054 | (primitive_type) @font-lock-type-face | 1051 | (optional_type) @font-lock-type-face) |
| 1055 | ((primitive_type) @font-lock-keyword-face | 1052 | |
| 1056 | (:equal "callable" @font-lock-keyword-face)) | 1053 | :language 'php |
| 1057 | (cast_type) @font-lock-type-face | 1054 | :feature 'definition |
| 1058 | (named_type) @font-lock-type-face | 1055 | :override t |
| 1059 | (optional_type) @font-lock-type-face) | 1056 | `((php_tag) @font-lock-preprocessor-face |
| 1060 | 1057 | ,@(if (php-ts-mode--test-php-end-tag-p) | |
| 1061 | :language 'php | 1058 | '((php_end_tag) @font-lock-preprocessor-face) |
| 1062 | :feature 'definition | 1059 | '(("?>") @font-lock-preprocessor-face)) |
| 1063 | :override t | 1060 | ;; Highlights identifiers in declarations. |
| 1064 | `((php_tag) @font-lock-preprocessor-face | 1061 | (class_declaration |
| 1065 | ,@(if (php-ts-mode--test-php-end-tag-p) | 1062 | name: (_) @font-lock-type-face) |
| 1066 | '((php_end_tag) @font-lock-preprocessor-face) | 1063 | (class_interface_clause (name) @font-lock-type-face) |
| 1067 | '(("?>") @font-lock-preprocessor-face)) | 1064 | (interface_declaration |
| 1068 | ;; Highlights identifiers in declarations. | 1065 | name: (_) @font-lock-type-face) |
| 1069 | (class_declaration | 1066 | (trait_declaration |
| 1070 | name: (_) @font-lock-type-face) | 1067 | name: (_) @font-lock-type-face) |
| 1071 | (class_interface_clause (name) @font-lock-type-face) | 1068 | (enum_declaration |
| 1072 | (interface_declaration | 1069 | name: (_) @font-lock-type-face) |
| 1073 | name: (_) @font-lock-type-face) | 1070 | (function_definition |
| 1074 | (trait_declaration | 1071 | name: (_) @font-lock-function-name-face) |
| 1075 | name: (_) @font-lock-type-face) | 1072 | ,@(when (php-ts-mode--test-property-hook-p) |
| 1076 | (enum_declaration | 1073 | '((property_hook (name) @font-lock-function-name-face))) |
| 1077 | name: (_) @font-lock-type-face) | 1074 | (method_declaration |
| 1078 | (function_definition | 1075 | name: (_) @font-lock-function-name-face) |
| 1079 | name: (_) @font-lock-function-name-face) | 1076 | (method_declaration |
| 1080 | ,@(when (php-ts-mode--test-property-hook-p) | 1077 | name: (name) @font-lock-builtin-face |
| 1081 | '((property_hook (name) @font-lock-function-name-face))) | 1078 | (:match ,(rx-to-string |
| 1082 | (method_declaration | 1079 | `(: bos (or ,@php-ts-mode--class-magic-methods) eos)) |
| 1083 | name: (_) @font-lock-function-name-face) | 1080 | @font-lock-builtin-face)) |
| 1084 | (method_declaration | 1081 | ("=>") @font-lock-keyword-face |
| 1085 | name: (name) @font-lock-builtin-face | 1082 | (object_creation_expression |
| 1086 | (:match ,(rx-to-string | 1083 | (name) @font-lock-type-face) |
| 1087 | `(: bos (or ,@php-ts-mode--class-magic-methods) eos)) | 1084 | ,@(when (php-ts-mode--test-namespace-name-as-prefix-p) |
| 1088 | @font-lock-builtin-face)) | 1085 | '((namespace_name_as_prefix "\\" @font-lock-delimiter-face) |
| 1089 | ("=>") @font-lock-keyword-face | 1086 | (namespace_name_as_prefix |
| 1090 | (object_creation_expression | 1087 | (namespace_name (name)) @font-lock-type-face))) |
| 1091 | (name) @font-lock-type-face) | 1088 | ,@(if (php-ts-mode--test-namespace-aliasing-clause-p) |
| 1092 | ,@(when (php-ts-mode--test-namespace-name-as-prefix-p) | 1089 | '((namespace_aliasing_clause (name) @font-lock-type-face)) |
| 1093 | '((namespace_name_as_prefix "\\" @font-lock-delimiter-face) | 1090 | '((namespace_use_clause alias: (name) @font-lock-type-face))) |
| 1094 | (namespace_name_as_prefix | 1091 | ,@(when (not (php-ts-mode--test-namespace-use-group-clause-p)) |
| 1095 | (namespace_name (name)) @font-lock-type-face))) | 1092 | '((namespace_use_group |
| 1096 | ,@(if (php-ts-mode--test-namespace-aliasing-clause-p) | 1093 | (namespace_use_clause (name) @font-lock-type-face)))) |
| 1097 | '((namespace_aliasing_clause (name) @font-lock-type-face)) | 1094 | (namespace_use_clause (name) @font-lock-type-face) |
| 1098 | '((namespace_use_clause alias: (name) @font-lock-type-face))) | 1095 | (namespace_name "\\" @font-lock-delimiter-face) |
| 1099 | ,@(when (not (php-ts-mode--test-namespace-use-group-clause-p)) | 1096 | (namespace_name (name) @font-lock-type-face) |
| 1100 | '((namespace_use_group | 1097 | (use_declaration (name) @font-lock-property-use-face) |
| 1101 | (namespace_use_clause (name) @font-lock-type-face)))) | 1098 | (use_instead_of_clause (name) @font-lock-type-face) |
| 1102 | (namespace_use_clause (name) @font-lock-type-face) | 1099 | (binary_expression |
| 1103 | (namespace_name "\\" @font-lock-delimiter-face) | 1100 | operator: "instanceof" |
| 1104 | (namespace_name (name) @font-lock-type-face) | 1101 | right: (name) @font-lock-type-face)) |
| 1105 | (use_declaration (name) @font-lock-property-use-face) | 1102 | |
| 1106 | (use_instead_of_clause (name) @font-lock-type-face) | 1103 | :language 'php |
| 1107 | (binary_expression | 1104 | :feature 'function-scope |
| 1108 | operator: "instanceof" | 1105 | :override t |
| 1109 | right: (name) @font-lock-type-face)) | 1106 | '((scoped_call_expression |
| 1110 | 1107 | scope: (name) @font-lock-constant-face) | |
| 1111 | :language 'php | 1108 | (class_constant_access_expression (name) @font-lock-constant-face)) |
| 1112 | :feature 'function-scope | 1109 | |
| 1113 | :override t | 1110 | :language 'php |
| 1114 | '((scoped_call_expression | 1111 | :feature 'function-call |
| 1115 | scope: (name) @font-lock-constant-face) | 1112 | :override t |
| 1116 | (class_constant_access_expression (name) @font-lock-constant-face)) | 1113 | '((function_call_expression |
| 1117 | 1114 | function: (name) @font-lock-function-call-face) | |
| 1118 | :language 'php | 1115 | (scoped_call_expression |
| 1119 | :feature 'function-call | 1116 | name: (name) @font-lock-function-call-face) |
| 1120 | :override t | 1117 | (member_call_expression |
| 1121 | '((function_call_expression | 1118 | name: (name) @font-lock-function-call-face) |
| 1122 | function: (name) @font-lock-function-call-face) | 1119 | (nullsafe_member_call_expression |
| 1123 | (scoped_call_expression | 1120 | name: (_) @font-lock-function-call-face)) |
| 1124 | name: (name) @font-lock-function-call-face) | 1121 | |
| 1125 | (member_call_expression | 1122 | :language 'php |
| 1126 | name: (name) @font-lock-function-call-face) | 1123 | :feature 'argument |
| 1127 | (nullsafe_member_call_expression | 1124 | '((argument |
| 1128 | name: (_) @font-lock-function-call-face)) | 1125 | name: (_) @font-lock-constant-face)) |
| 1129 | 1126 | ||
| 1130 | :language 'php | 1127 | :language 'php |
| 1131 | :feature 'argument | 1128 | :feature 'escape-sequence |
| 1132 | '((argument | 1129 | :override t |
| 1133 | name: (_) @font-lock-constant-face)) | 1130 | '((string (escape_sequence) @font-lock-escape-face) |
| 1134 | 1131 | (encapsed_string (escape_sequence) @font-lock-escape-face) | |
| 1135 | :language 'php | 1132 | (heredoc_body (escape_sequence) @font-lock-escape-face)) |
| 1136 | :feature 'escape-sequence | 1133 | |
| 1137 | :override t | 1134 | :language 'php |
| 1138 | '((string (escape_sequence) @font-lock-escape-face) | 1135 | :feature 'base-clause |
| 1139 | (encapsed_string (escape_sequence) @font-lock-escape-face) | 1136 | :override t |
| 1140 | (heredoc_body (escape_sequence) @font-lock-escape-face)) | 1137 | `((base_clause (name) @font-lock-type-face) |
| 1141 | 1138 | (use_as_clause (name) @font-lock-property-use-face) | |
| 1142 | :language 'php | 1139 | ,@(when (not (php-ts-mode--test-namespace-name-as-prefix-p)) |
| 1143 | :feature 'base-clause | 1140 | '((qualified_name prefix: "\\" @font-lock-delimiter-face))) |
| 1144 | :override t | 1141 | (qualified_name (name) @font-lock-constant-face) |
| 1145 | `((base_clause (name) @font-lock-type-face) | 1142 | ,@(when (php-ts-mode--test-relative-name-p) |
| 1146 | (use_as_clause (name) @font-lock-property-use-face) | 1143 | '((relative_name (name) @font-lock-constant-face)))) |
| 1147 | ,@(when (not (php-ts-mode--test-namespace-name-as-prefix-p)) | 1144 | |
| 1148 | '((qualified_name prefix: "\\" @font-lock-delimiter-face))) | 1145 | :language 'php |
| 1149 | (qualified_name (name) @font-lock-constant-face) | 1146 | :feature 'property |
| 1150 | ,@(when (php-ts-mode--test-relative-name-p) | 1147 | '((enum_case |
| 1151 | '((relative_name (name) @font-lock-constant-face)))) | 1148 | name: (_) @font-lock-type-face)) |
| 1152 | 1149 | ||
| 1153 | :language 'php | 1150 | :language 'php |
| 1154 | :feature 'property | 1151 | :feature 'attribute |
| 1155 | '((enum_case | 1152 | '((((attribute (_) @attribute_name) @font-lock-preprocessor-face) |
| 1156 | name: (_) @font-lock-type-face)) | 1153 | (:equal "Deprecated" @attribute_name)) |
| 1157 | 1154 | (attribute_group (attribute (name) @font-lock-constant-face))) | |
| 1158 | :language 'php | 1155 | |
| 1159 | :feature 'attribute | 1156 | :language 'php |
| 1160 | '((((attribute (_) @attribute_name) @font-lock-preprocessor-face) | 1157 | :feature 'bracket |
| 1161 | (:equal "Deprecated" @attribute_name)) | 1158 | '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face) |
| 1162 | (attribute_group (attribute (name) @font-lock-constant-face))) | 1159 | |
| 1163 | 1160 | :language 'php | |
| 1164 | :language 'php | 1161 | :feature 'error |
| 1165 | :feature 'bracket | 1162 | :override t |
| 1166 | '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face) | 1163 | '((ERROR) @php-ts-mode--fontify-error))) |
| 1167 | |||
| 1168 | :language 'php | ||
| 1169 | :feature 'error | ||
| 1170 | :override t | ||
| 1171 | '((ERROR) @php-ts-mode--fontify-error))))) | ||
| 1172 | 1164 | ||
| 1173 | 1165 | ||
| 1174 | ;;; Font-lock helpers | 1166 | ;;; Font-lock helpers |
| 1175 | 1167 | ||
| 1176 | (defvar php-ts-mode--custom-html-font-lock-settings-cached nil | ||
| 1177 | "Cached tree-sitter font-lock settings for HTML when embedded in PHP.") | ||
| 1178 | |||
| 1179 | (defun php-ts-mode--custom-html-font-lock-settings () | 1168 | (defun php-ts-mode--custom-html-font-lock-settings () |
| 1180 | "Tree-sitter Font-lock settings for HTML when embedded in PHP. | 1169 | "Tree-sitter Font-lock settings for HTML when embedded in PHP. |
| 1181 | Like `mhtml-ts-mode--font-lock-settings' but adapted for `php-ts-mode'. | 1170 | Like `mhtml-ts-mode--font-lock-settings' but adapted for `php-ts-mode'." |
| 1182 | 1171 | (treesit-replace-font-lock-feature-settings | |
| 1183 | Tree-sitter font-lock settings are evaluated the first time this | 1172 | (treesit-font-lock-rules |
| 1184 | function is called. Subsequent calls return the first evaluated value." | 1173 | :language 'html |
| 1185 | (or php-ts-mode--custom-html-font-lock-settings-cached | 1174 | :override t |
| 1186 | (setq php-ts-mode--custom-html-font-lock-settings-cached | 1175 | :feature 'comment |
| 1187 | (treesit-replace-font-lock-feature-settings | 1176 | '((comment) @font-lock-comment-face |
| 1188 | (treesit-font-lock-rules | 1177 | ;; handle shebang path and others type of comment |
| 1189 | :language 'html | 1178 | (document (text) @font-lock-comment-face))) |
| 1190 | :override t | 1179 | (mhtml-ts-mode--treesit-font-lock-settings))) |
| 1191 | :feature 'comment | ||
| 1192 | '((comment) @font-lock-comment-face | ||
| 1193 | ;; handle shebang path and others type of comment | ||
| 1194 | (document (text) @font-lock-comment-face))) | ||
| 1195 | (mhtml-ts-mode--treesit-font-lock-settings))))) | ||
| 1196 | 1180 | ||
| 1197 | (defvar php-ts-mode--phpdoc-font-lock-settings | 1181 | (defvar php-ts-mode--phpdoc-font-lock-settings |
| 1198 | (treesit-font-lock-rules | 1182 | (treesit-font-lock-rules |
diff --git a/lisp/textmodes/mhtml-ts-mode.el b/lisp/textmodes/mhtml-ts-mode.el index b97555de2fc..fe68f17a6da 100644 --- a/lisp/textmodes/mhtml-ts-mode.el +++ b/lisp/textmodes/mhtml-ts-mode.el | |||
| @@ -259,28 +259,20 @@ NODE and PARENT are ignored." | |||
| 259 | css--treesit-font-lock-feature-list)) | 259 | css--treesit-font-lock-feature-list)) |
| 260 | "Settings for `treesit-font-lock-feature-list'.") | 260 | "Settings for `treesit-font-lock-feature-list'.") |
| 261 | 261 | ||
| 262 | (defvar mhtml-ts-mode--treesit-font-lock-settings-cached nil | ||
| 263 | "Cached tree-sitter font-lock settings for `mhtml-ts-mode'.") | ||
| 264 | |||
| 265 | (defun mhtml-ts-mode--treesit-font-lock-settings () | 262 | (defun mhtml-ts-mode--treesit-font-lock-settings () |
| 266 | "Return tree-sitter font-lock settings for `mhtml-ts-mode'. | 263 | "Return tree-sitter font-lock settings for `mhtml-ts-mode'." |
| 267 | 264 | (append html-ts-mode--font-lock-settings | |
| 268 | Tree-sitter font-lock settings are evaluated the first time this | 265 | (js--treesit-font-lock-settings) |
| 269 | function is called. Subsequent calls return the first evaluated value." | 266 | ;; Let's replace a css rule with a new one that adds |
| 270 | (or mhtml-ts-mode--treesit-font-lock-settings-cached | 267 | ;; color to the css value. |
| 271 | (setq mhtml-ts-mode--treesit-font-lock-settings-cached | 268 | (treesit-replace-font-lock-feature-settings |
| 272 | (append html-ts-mode--font-lock-settings | 269 | (treesit-font-lock-rules |
| 273 | (js--treesit-font-lock-settings) | 270 | :language 'css |
| 274 | ;; Let's replace a css rule with a new one that adds | 271 | :override t |
| 275 | ;; color to the css value. | 272 | :feature 'variable |
| 276 | (treesit-replace-font-lock-feature-settings | 273 | '((plain_value) @mhtml-ts-mode--colorize-css-value |
| 277 | (treesit-font-lock-rules | 274 | (color_value) @mhtml-ts-mode--colorize-css-value)) |
| 278 | :language 'css | 275 | css--treesit-settings))) |
| 279 | :override t | ||
| 280 | :feature 'variable | ||
| 281 | '((plain_value) @mhtml-ts-mode--colorize-css-value | ||
| 282 | (color_value) @mhtml-ts-mode--colorize-css-value)) | ||
| 283 | css--treesit-settings))))) | ||
| 284 | 276 | ||
| 285 | (defvar mhtml-ts-mode--treesit-thing-settings | 277 | (defvar mhtml-ts-mode--treesit-thing-settings |
| 286 | ;; In addition to putting together the various definitions, we need to | 278 | ;; In addition to putting together the various definitions, we need to |
| @@ -300,34 +292,26 @@ function is called. Subsequent calls return the first evaluated value." | |||
| 300 | `((defun ,css--treesit-defun-type-regexp)))) | 292 | `((defun ,css--treesit-defun-type-regexp)))) |
| 301 | "Settings for `treesit-thing-settings'.") | 293 | "Settings for `treesit-thing-settings'.") |
| 302 | 294 | ||
| 303 | (defvar mhtml-ts-mode--treesit-indent-rules-cached nil | ||
| 304 | "Cached tree-sitter indent rules for `mhtml-ts-mode'.") | ||
| 305 | |||
| 306 | (defun mhtml-ts-mode--treesit-indent-rules () | 295 | (defun mhtml-ts-mode--treesit-indent-rules () |
| 307 | "Return tree-sitter indent rules for `mhtml-ts-mode'. | 296 | "Return tree-sitter indent rules for `mhtml-ts-mode'." |
| 308 | 297 | (treesit--indent-rules-optimize | |
| 309 | Tree-sitter indent rules are evaluated the first time this function | 298 | (append html-ts-mode--indent-rules |
| 310 | is called. Subsequent calls return the first evaluated value." | 299 | ;; Extended rules for js and css, to indent |
| 311 | (or mhtml-ts-mode--treesit-indent-rules-cached | 300 | ;; appropriately when injected into html |
| 312 | (setq mhtml-ts-mode--treesit-indent-rules-cached | 301 | (treesit-simple-indent-modify-rules |
| 313 | (treesit--indent-rules-optimize | 302 | 'javascript |
| 314 | (append html-ts-mode--indent-rules | 303 | `((javascript ((parent-is "program") |
| 315 | ;; Extended rules for js and css, to indent | 304 | mhtml-ts-mode--js-css-tag-bol |
| 316 | ;; appropriately when injected into html | 305 | mhtml-ts-mode--js-css-indent-offset))) |
| 317 | (treesit-simple-indent-modify-rules | 306 | (js--treesit-indent-rules) |
| 318 | 'javascript | 307 | :replace) |
| 319 | `((javascript ((parent-is "program") | 308 | (treesit-simple-indent-modify-rules |
| 320 | mhtml-ts-mode--js-css-tag-bol | 309 | 'css |
| 321 | mhtml-ts-mode--js-css-indent-offset))) | 310 | `((css ((parent-is "stylesheet") |
| 322 | (js--treesit-indent-rules) | 311 | mhtml-ts-mode--js-css-tag-bol |
| 323 | :replace) | 312 | mhtml-ts-mode--js-css-indent-offset))) |
| 324 | (treesit-simple-indent-modify-rules | 313 | css--treesit-indent-rules |
| 325 | 'css | 314 | :prepend)))) |
| 326 | `((css ((parent-is "stylesheet") | ||
| 327 | mhtml-ts-mode--js-css-tag-bol | ||
| 328 | mhtml-ts-mode--js-css-indent-offset))) | ||
| 329 | css--treesit-indent-rules | ||
| 330 | :prepend)))))) | ||
| 331 | 315 | ||
| 332 | (defvar mhtml-ts-mode--treesit-aggregated-simple-imenu-settings | 316 | (defvar mhtml-ts-mode--treesit-aggregated-simple-imenu-settings |
| 333 | `((html ,@html-ts-mode--treesit-simple-imenu-settings) | 317 | `((html ,@html-ts-mode--treesit-simple-imenu-settings) |