diff options
| author | Yuan Fu | 2023-09-14 21:32:23 -0700 |
|---|---|---|
| committer | Yuan Fu | 2023-09-15 00:44:23 -0700 |
| commit | 04fd8b173bd4fda5b09ef76c814827cc9fa6edb2 (patch) | |
| tree | a70274e8c4603f20b2ced457c79ebb57ae127f7b | |
| parent | 160b4c295d8975755d4a8cc4ba6b6b75a549ed3c (diff) | |
| download | emacs-04fd8b173bd4fda5b09ef76c814827cc9fa6edb2.tar.gz emacs-04fd8b173bd4fda5b09ef76c814827cc9fa6edb2.zip | |
Allow treesit-font-lock-recompute-features to be language-specific
* lisp/treesit.el:
(treesit-font-lock-recompute-features): Add LANGUAGE parameter.
| -rw-r--r-- | lisp/treesit.el | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 89920ed38f1..78bd149b7e2 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el | |||
| @@ -952,7 +952,8 @@ name, it is ignored." | |||
| 952 | (defvar treesit--font-lock-verbose nil | 952 | (defvar treesit--font-lock-verbose nil |
| 953 | "If non-nil, print debug messages when fontifying.") | 953 | "If non-nil, print debug messages when fontifying.") |
| 954 | 954 | ||
| 955 | (defun treesit-font-lock-recompute-features (&optional add-list remove-list) | 955 | (defun treesit-font-lock-recompute-features |
| 956 | (&optional add-list remove-list language) | ||
| 956 | "Enable/disable font-lock features. | 957 | "Enable/disable font-lock features. |
| 957 | 958 | ||
| 958 | Enable each feature in ADD-LIST, disable each feature in | 959 | Enable each feature in ADD-LIST, disable each feature in |
| @@ -967,7 +968,10 @@ the features are disabled. | |||
| 967 | 968 | ||
| 968 | ADD-LIST and REMOVE-LIST are lists of feature symbols. The | 969 | ADD-LIST and REMOVE-LIST are lists of feature symbols. The |
| 969 | same feature symbol cannot appear in both lists; the function | 970 | same feature symbol cannot appear in both lists; the function |
| 970 | signals the `treesit-font-lock-error' error if that happens." | 971 | signals the `treesit-font-lock-error' error if that happens. |
| 972 | |||
| 973 | If LANGUAGE is non-nil, only compute features for that language, | ||
| 974 | and leave settings for other languages unchanged." | ||
| 971 | (when-let ((intersection (cl-intersection add-list remove-list))) | 975 | (when-let ((intersection (cl-intersection add-list remove-list))) |
| 972 | (signal 'treesit-font-lock-error | 976 | (signal 'treesit-font-lock-error |
| 973 | (list "ADD-LIST and REMOVE-LIST contain the same feature" | 977 | (list "ADD-LIST and REMOVE-LIST contain the same feature" |
| @@ -987,9 +991,13 @@ signals the `treesit-font-lock-error' error if that happens." | |||
| 987 | (additive (or add-list remove-list))) | 991 | (additive (or add-list remove-list))) |
| 988 | (cl-loop for idx = 0 then (1+ idx) | 992 | (cl-loop for idx = 0 then (1+ idx) |
| 989 | for setting in treesit-font-lock-settings | 993 | for setting in treesit-font-lock-settings |
| 994 | for lang = (treesit-query-language (nth 0 setting)) | ||
| 990 | for feature = (nth 2 setting) | 995 | for feature = (nth 2 setting) |
| 991 | for current-value = (nth 1 setting) | 996 | for current-value = (nth 1 setting) |
| 992 | ;; Set the ENABLE flag for the setting. | 997 | ;; Set the ENABLE flag for the setting if its language is |
| 998 | ;; relevant. | ||
| 999 | if (or (null language) | ||
| 1000 | (eq language lang)) | ||
| 993 | do (setf (nth 1 (nth idx treesit-font-lock-settings)) | 1001 | do (setf (nth 1 (nth idx treesit-font-lock-settings)) |
| 994 | (cond | 1002 | (cond |
| 995 | ((not additive) | 1003 | ((not additive) |