aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2022-11-26 14:54:55 -0800
committerYuan Fu2022-11-26 15:40:24 -0800
commit447b9d48d966561f9bf65cd3eb0e2c0e60f69d42 (patch)
tree0e0faa5ee08caa831c5e0729e08ef8543108c5c4
parentcc086f37e89051f62538d5ead1c011580b667598 (diff)
downloademacs-447b9d48d966561f9bf65cd3eb0e2c0e60f69d42.tar.gz
emacs-447b9d48d966561f9bf65cd3eb0e2c0e60f69d42.zip
Add treesit-font-lock-level
This replaces font-lock-maximum-decoration and allows us to disable the busiest fontification level by default. * lisp/treesit.el (treesit-font-lock-level): New variable. (treesit-font-lock-feature-list) (treesit-font-lock-settings): Change docstring. (treesit-font-lock-recompute-features): Use the new variable.
-rw-r--r--lisp/treesit.el40
1 files changed, 27 insertions, 13 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el
index b7da38becc1..ab00b0e8a73 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -520,6 +520,24 @@ omitted, default END to BEG."
520 "Generic tree-sitter font-lock error" 520 "Generic tree-sitter font-lock error"
521 'treesit-error) 521 'treesit-error)
522 522
523(defvar-local treesit-font-lock-level 3
524 "The decoration level used by tree-sitter fontification.
525Major modes categorize their fontification features into levels,
526from 1 being the absolute minimal, to 4 being maximally
527fontified.
528
529Level 1 usually contains only comments and definitions.
530Level 2 usually adds keywords, strings, constants, types, etc.
531Level 3 usually represents a full-blown fontification, including
532assignment, constants, numbers, properties, etc.
533Level 4 fontifies everything that can be fontified: delimiters,
534operators, brackets, all functions and variables, etc.
535
536In addition to the decoration level, individual features can be
537turned on/off by `treesit-font-lock-recompute-features'. Changes
538to this variable also requires calling
539`treesit-font-lock-recompute-features' to have an effect.")
540
523(defvar-local treesit--font-lock-query-expand-range (cons 0 0) 541(defvar-local treesit--font-lock-query-expand-range (cons 0 0)
524 "The amount to expand the start and end of the region when fontifying. 542 "The amount to expand the start and end of the region when fontifying.
525This should be a cons cell (START . END). When fontifying a 543This should be a cons cell (START . END). When fontifying a
@@ -537,11 +555,10 @@ temporarily fix.")
537 "A list of lists of feature symbols. 555 "A list of lists of feature symbols.
538 556
539Use `treesit-font-lock-recompute-features' and 557Use `treesit-font-lock-recompute-features' and
540`font-lock-maximum-decoration' to configure enabled features. 558`treesit-font-lock-level' to configure enabled features.
541 559
542Each sublist represents a decoration level. 560Each sublist represents a decoration level.
543`font-lock-maximum-decoration' controls which levels are 561`treesit-font-lock-level' controls which levels are activated.
544activated.
545 562
546Inside each sublist are feature symbols, which correspond to the 563Inside each sublist are feature symbols, which correspond to the
547:feature value of a query defined in `treesit-font-lock-rules'. 564:feature value of a query defined in `treesit-font-lock-rules'.
@@ -575,8 +592,8 @@ For SETTING to be activated for font-lock, ENABLE must be t. To
575disable this SETTING, set ENABLE to nil. 592disable this SETTING, set ENABLE to nil.
576 593
577FEATURE is the \"feature name\" of the query. Users can control 594FEATURE is the \"feature name\" of the query. Users can control
578which features are enabled with `font-lock-maximum-decoration' 595which features are enabled with `treesit-font-lock-level' and
579and `treesit-font-lock-feature-list'. 596`treesit-font-lock-feature-list'.
580 597
581OVERRIDE is the override flag for this query. Its value can be 598OVERRIDE is the override flag for this query. Its value can be
582t, nil, append, prepend, keep. See more in 599t, nil, append, prepend, keep. See more in
@@ -718,12 +735,10 @@ REMOVE-LIST.
718 735
719If both ADD-LIST and REMOVE-LIST are omitted, recompute each 736If both ADD-LIST and REMOVE-LIST are omitted, recompute each
720feature according to `treesit-font-lock-feature-list' and 737feature according to `treesit-font-lock-feature-list' and
721`font-lock-maximum-decoration'. Let N be the value of 738`treesit-font-lock-level'. Let N be the value of
722`font-lock-maximum-decoration', features in the first Nth sublist 739`treesit-font-lock-level', features in the first N sublists of
723of `treesit-font-lock-feature-list' are enabled, and the rest 740`treesit-font-lock-feature-list' are enabled, and other features
724features are disabled. If `font-lock-maximum-decoration' is t, 741are disabled.
725all features in `treesit-font-lock-feature-list' are enabled, and
726the rest are disabled.
727 742
728ADD-LIST and REMOVE-LIST are each a list of feature symbols. The 743ADD-LIST and REMOVE-LIST are each a list of feature symbols. The
729same feature symbol cannot appear in both lists; the function 744same feature symbol cannot appear in both lists; the function
@@ -732,8 +747,7 @@ signals the `treesit-font-lock-error' error if that happens."
732 (signal 'treesit-font-lock-error 747 (signal 'treesit-font-lock-error
733 (list "ADD-LIST and REMOVE-LIST contain the same feature" 748 (list "ADD-LIST and REMOVE-LIST contain the same feature"
734 intersection))) 749 intersection)))
735 (let* ((level (font-lock-value-in-major-mode 750 (let* ((level treesit-font-lock-level)
736 font-lock-maximum-decoration))
737 (base-features (cl-loop 751 (base-features (cl-loop
738 for idx = 0 then (1+ idx) 752 for idx = 0 then (1+ idx)
739 for features in treesit-font-lock-feature-list 753 for features in treesit-font-lock-feature-list