[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 6e07838051 4/7: treesit-font-lock-recompute-features now has two
From: |
Yuan Fu |
Subject: |
master 6e07838051 4/7: treesit-font-lock-recompute-features now has two modes of operation |
Date: |
Tue, 22 Nov 2022 04:07:11 -0500 (EST) |
branch: master
commit 6e078380512675aabd45ed752f60ebe424efd89d
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
treesit-font-lock-recompute-features now has two modes of operation
1. Set activation of each feature (changes every feature)
2. Add/remove features (only change those explicitly configured by
ADD-LIST and REMOVE-LIST)
This is useful for enabling/disabling certain features for all
modes (without resetting others) by calling this function in
prog-mode-hook
* lisp/treesit.el (treesit-font-lock-recompute-features): See above
description.
---
lisp/treesit.el | 33 +++++++++++++++++++++++++--------
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 015f780078..10c6b09322 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -694,16 +694,23 @@ name, it is ignored."
"If non-nil, print debug messages when fontifying.")
(defun treesit-font-lock-recompute-features (&optional add-list remove-list)
- "Enable/disable font-lock settings according to decoration level.
+ "Enable/disable font-lock features.
-First compute the enabled features according to
-`treesit-font-lock-feature-list' and `font-lock-maximum-decoration',
-then, if ADD-LIST or REMOVE-LIST are not omitted, further add and
-remove features accordingly.
+Enable each feature in ADD-LIST, disable each feature in
+REMOVE-LIST.
+
+If both ADD-LIST and REMOVE-LIST are omitted, recompute each
+feature according to `treesit-font-lock-feature-list' and
+`font-lock-maximum-decoration'. Let N be the value of
+`font-lock-maximum-decoration', features in the first Nth sublist
+of `treesit-font-lock-feature-list' are enabled, and the rest
+features are disabled. If `font-lock-maximum-decoration' is t,
+all features in `treesit-font-lock-feature-list' are enabled, and
+the rest are disabled.
ADD-LIST and REMOVE-LIST are each a list of feature symbols. The
same feature symbol cannot appear in both lists; the function
-signals the `treesit-font-lock-error' error if so."
+signals the `treesit-font-lock-error' error if that happens."
(when-let ((intersection (cl-intersection add-list remove-list)))
(signal 'treesit-font-lock-error
(list "ADD-LIST and REMOVE-LIST contain the same feature"
@@ -717,13 +724,23 @@ signals the `treesit-font-lock-error' error if so."
(>= level (1+ idx)))
append features))
(features (cl-set-difference (cl-union base-features add-list)
- remove-list)))
+ remove-list))
+ ;; If additive non-nil, we are configuring on top of the
+ ;; existing configuration, if nil, we are resetting
+ ;; everything according to `treesit-font-lock-feature-list'.
+ (additive (or add-list remove-list)))
(cl-loop for idx = 0 then (1+ idx)
for setting in treesit-font-lock-settings
for feature = (nth 2 setting)
+ for current-value = (nth 1 setting)
;; Set the ENABLE flag for the setting.
do (setf (nth 1 (nth idx treesit-font-lock-settings))
- (if (memq feature features) t nil)))))
+ (cond
+ ((not additive)
+ (if (memq feature features) t nil))
+ ((memq feature add-list) t)
+ ((memq feature remove-list) nil)
+ (t current-value))))))
(defun treesit-fontify-with-override (start end face override)
"Apply FACE to the region between START and END.
- master updated (b32f50c6d8 -> 1161c96cc9), Yuan Fu, 2022/11/22
- master 74892eefc8 1/7: * lisp/treesit.el (treesit-max-buffer-size): Enlarge value., Yuan Fu, 2022/11/22
- master d6d4adf3bd 5/7: Tweak faces in Java and TypeScript, Yuan Fu, 2022/11/22
- master c7202e7f4a 2/7: ; Fix docstrings in treesit.el, Yuan Fu, 2022/11/22
- master cb60342c01 3/7: Tweak c-ts-mode fontification, Yuan Fu, 2022/11/22
- master 6e07838051 4/7: treesit-font-lock-recompute-features now has two modes of operation,
Yuan Fu <=
- master e494ca4f4d 6/7: Fix treesit_record_change in casify_region, Yuan Fu, 2022/11/22
- master 1161c96cc9 7/7: Separate tree-sitter and non-tree-sitter variant of sh-mode, Yuan Fu, 2022/11/22