aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2023-09-14 21:32:23 -0700
committerYuan Fu2023-09-15 00:44:23 -0700
commit04fd8b173bd4fda5b09ef76c814827cc9fa6edb2 (patch)
treea70274e8c4603f20b2ced457c79ebb57ae127f7b
parent160b4c295d8975755d4a8cc4ba6b6b75a549ed3c (diff)
downloademacs-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.el14
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
958Enable each feature in ADD-LIST, disable each feature in 959Enable each feature in ADD-LIST, disable each feature in
@@ -967,7 +968,10 @@ the features are disabled.
967 968
968ADD-LIST and REMOVE-LIST are lists of feature symbols. The 969ADD-LIST and REMOVE-LIST are lists of feature symbols. The
969same feature symbol cannot appear in both lists; the function 970same feature symbol cannot appear in both lists; the function
970signals the `treesit-font-lock-error' error if that happens." 971signals the `treesit-font-lock-error' error if that happens.
972
973If LANGUAGE is non-nil, only compute features for that language,
974and 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)