emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 04fd8b173bd 1/2: Allow treesit-font-lock-recompute-features to be


From: Yuan Fu
Subject: master 04fd8b173bd 1/2: Allow treesit-font-lock-recompute-features to be language-specific
Date: Fri, 15 Sep 2023 03:44:34 -0400 (EDT)

branch: master
commit 04fd8b173bd4fda5b09ef76c814827cc9fa6edb2
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Allow treesit-font-lock-recompute-features to be language-specific
    
    * lisp/treesit.el:
    (treesit-font-lock-recompute-features): Add LANGUAGE parameter.
---
 lisp/treesit.el | 14 +++++++++++---
 1 file 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."
 (defvar treesit--font-lock-verbose nil
   "If non-nil, print debug messages when fontifying.")
 
-(defun treesit-font-lock-recompute-features (&optional add-list remove-list)
+(defun treesit-font-lock-recompute-features
+    (&optional add-list remove-list language)
   "Enable/disable font-lock features.
 
 Enable each feature in ADD-LIST, disable each feature in
@@ -967,7 +968,10 @@ the features are disabled.
 
 ADD-LIST and REMOVE-LIST are lists of feature symbols.  The
 same feature symbol cannot appear in both lists; the function
-signals the `treesit-font-lock-error' error if that happens."
+signals the `treesit-font-lock-error' error if that happens.
+
+If LANGUAGE is non-nil, only compute features for that language,
+and leave settings for other languages unchanged."
   (when-let ((intersection (cl-intersection add-list remove-list)))
     (signal 'treesit-font-lock-error
             (list "ADD-LIST and REMOVE-LIST contain the same feature"
@@ -987,9 +991,13 @@ signals the `treesit-font-lock-error' error if that 
happens."
          (additive (or add-list remove-list)))
     (cl-loop for idx = 0 then (1+ idx)
              for setting in treesit-font-lock-settings
+             for lang = (treesit-query-language (nth 0 setting))
              for feature = (nth 2 setting)
              for current-value = (nth 1 setting)
-             ;; Set the ENABLE flag for the setting.
+             ;; Set the ENABLE flag for the setting if its language is
+             ;; relevant.
+             if (or (null language)
+                    (eq language lang))
              do (setf (nth 1 (nth idx treesit-font-lock-settings))
                       (cond
                        ((not additive)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]