diff options
| author | Yuan Fu | 2022-11-26 14:54:55 -0800 |
|---|---|---|
| committer | Yuan Fu | 2022-11-26 15:40:24 -0800 |
| commit | 447b9d48d966561f9bf65cd3eb0e2c0e60f69d42 (patch) | |
| tree | 0e0faa5ee08caa831c5e0729e08ef8543108c5c4 | |
| parent | cc086f37e89051f62538d5ead1c011580b667598 (diff) | |
| download | emacs-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.el | 40 |
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. | ||
| 525 | Major modes categorize their fontification features into levels, | ||
| 526 | from 1 being the absolute minimal, to 4 being maximally | ||
| 527 | fontified. | ||
| 528 | |||
| 529 | Level 1 usually contains only comments and definitions. | ||
| 530 | Level 2 usually adds keywords, strings, constants, types, etc. | ||
| 531 | Level 3 usually represents a full-blown fontification, including | ||
| 532 | assignment, constants, numbers, properties, etc. | ||
| 533 | Level 4 fontifies everything that can be fontified: delimiters, | ||
| 534 | operators, brackets, all functions and variables, etc. | ||
| 535 | |||
| 536 | In addition to the decoration level, individual features can be | ||
| 537 | turned on/off by `treesit-font-lock-recompute-features'. Changes | ||
| 538 | to 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. |
| 525 | This should be a cons cell (START . END). When fontifying a | 543 | This 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 | ||
| 539 | Use `treesit-font-lock-recompute-features' and | 557 | Use `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 | ||
| 542 | Each sublist represents a decoration level. | 560 | Each sublist represents a decoration level. |
| 543 | `font-lock-maximum-decoration' controls which levels are | 561 | `treesit-font-lock-level' controls which levels are activated. |
| 544 | activated. | ||
| 545 | 562 | ||
| 546 | Inside each sublist are feature symbols, which correspond to the | 563 | Inside 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 | |||
| 575 | disable this SETTING, set ENABLE to nil. | 592 | disable this SETTING, set ENABLE to nil. |
| 576 | 593 | ||
| 577 | FEATURE is the \"feature name\" of the query. Users can control | 594 | FEATURE is the \"feature name\" of the query. Users can control |
| 578 | which features are enabled with `font-lock-maximum-decoration' | 595 | which features are enabled with `treesit-font-lock-level' and |
| 579 | and `treesit-font-lock-feature-list'. | 596 | `treesit-font-lock-feature-list'. |
| 580 | 597 | ||
| 581 | OVERRIDE is the override flag for this query. Its value can be | 598 | OVERRIDE is the override flag for this query. Its value can be |
| 582 | t, nil, append, prepend, keep. See more in | 599 | t, nil, append, prepend, keep. See more in |
| @@ -718,12 +735,10 @@ REMOVE-LIST. | |||
| 718 | 735 | ||
| 719 | If both ADD-LIST and REMOVE-LIST are omitted, recompute each | 736 | If both ADD-LIST and REMOVE-LIST are omitted, recompute each |
| 720 | feature according to `treesit-font-lock-feature-list' and | 737 | feature 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 |
| 723 | of `treesit-font-lock-feature-list' are enabled, and the rest | 740 | `treesit-font-lock-feature-list' are enabled, and other features |
| 724 | features are disabled. If `font-lock-maximum-decoration' is t, | 741 | are disabled. |
| 725 | all features in `treesit-font-lock-feature-list' are enabled, and | ||
| 726 | the rest are disabled. | ||
| 727 | 742 | ||
| 728 | ADD-LIST and REMOVE-LIST are each a list of feature symbols. The | 743 | ADD-LIST and REMOVE-LIST are each a list of feature symbols. The |
| 729 | same feature symbol cannot appear in both lists; the function | 744 | same 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 |