[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter f6e92035a7 5/8: Allow user to add/remove tree-sitter
From: |
Yuan Fu |
Subject: |
feature/tree-sitter f6e92035a7 5/8: Allow user to add/remove tree-sitter font-lock features |
Date: |
Tue, 1 Nov 2022 16:28:16 -0400 (EDT) |
branch: feature/tree-sitter
commit f6e92035a7c3c29aa980e1bebf9c48f1bb7264d8
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Allow user to add/remove tree-sitter font-lock features
* lisp/treesit.el (treesit-font-lock-recompute-features): Add
ADD-LIST, REMOVE-LIST argument.
---
lisp/treesit.el | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 733d721f10..82eda595b9 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -419,6 +419,9 @@ omitted, default END to BEG."
(defvar-local treesit-font-lock-feature-list nil
"A list of lists of feature symbols.
+End-user should use `treesit-font-lock-recompute-features' and
+`font-lock-maximum-decoration' to configure enabled features.
+
Each sublist represents a decoration level.
`font-lock-maximum-decoration' controls which levels are
activated.
@@ -581,20 +584,31 @@ name, it is ignored.
(defvar treesit--font-lock-verbose nil
"If non-nil, print debug messages when fontifying.")
-(defun treesit-font-lock-recompute-features ()
+(defun treesit-font-lock-recompute-features (&optional add-list remove-list)
"Enable/disable font-lock settings according to decoration level.
-Set the ENABLE flag for each setting in
-`treesit-font-lock-settings', according to
+
+First compute the enabled features according to
`treesit-font-lock-feature-list' and
-`font-lock-maximum-decoration'."
+`font-lock-maximum-decoration', then if ADD-LIST or REMOVE-LIST
+are not omitted, further add and remove features accordingly.
+
+ADD-LIST and REMOVE-LIST are each list of feature symbols. The
+same feature symbol cannot not appear in both lists. Otherwise
+signal `treesit-font-lock-error'."
+ (when-let ((intersection (cl-intersection add-list remove-list)))
+ (signal 'treesit-font-lock-error
+ (list "ADD-LIST and REMOVE-LIST contain the same feature"
+ intersection)))
(let* ((level (font-lock-value-in-major-mode
font-lock-maximum-decoration))
- (features (cl-loop
- for idx = 0 then (1+ idx)
- for features in treesit-font-lock-feature-list
- if (or (eq level t)
- (>= level (1+ idx)))
- append features)))
+ (base-features (cl-loop
+ for idx = 0 then (1+ idx)
+ for features in treesit-font-lock-feature-list
+ if (or (eq level t)
+ (>= level (1+ idx)))
+ append features))
+ (features (cl-set-difference (cl-union base-features add-list)
+ remove-list)))
(cl-loop for idx = 0 then (1+ idx)
for setting in treesit-font-lock-settings
for feature = (nth 2 setting)
- feature/tree-sitter updated (9fab83ed7a -> 50e33639fe), Yuan Fu, 2022/11/01
- feature/tree-sitter b49250ada9 2/8: Use treesit-fontify-with-override in tree-sitter functions, Yuan Fu, 2022/11/01
- feature/tree-sitter a3651d3237 4/8: Query on the root node in tree-sitter font-lock, Yuan Fu, 2022/11/01
- feature/tree-sitter 6d5b34d9de 6/8: ; Tree-sitter font-lock debugging: print node type not language, Yuan Fu, 2022/11/01
- feature/tree-sitter ccd2509ed3 7/8: Don't print buffer when printing tree-sitter node and parser, Yuan Fu, 2022/11/01
- feature/tree-sitter f6e92035a7 5/8: Allow user to add/remove tree-sitter font-lock features,
Yuan Fu <=
- feature/tree-sitter eeeae5e9ee 1/8: Add an argument OVERRIDE to tree-sitter font-lock functions, Yuan Fu, 2022/11/01
- feature/tree-sitter 50e33639fe 8/8: Fix string fontification for tree-sitter python-mode, Yuan Fu, 2022/11/01
- feature/tree-sitter 4ef50ccd3f 3/8: ; Explain the BEG and END argument in treesit-query-capture better, Yuan Fu, 2022/11/01