1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 10:31:37 -08:00

Rework tree-sitter font-lock

Remove :toggle and :level, add :feature.

* lisp/progmodes/js.el (js--treesit-settings): Add :feature.
(js--treesit-enable): Set treesit-font-lock-feature-list.
* lisp/progmodes/python.el: Replace :level with :feature.
(python-mode): Set treesit-font-lock-feature-list.
* lisp/treesit.el (treesit-font-lock-feature-list): New variable.
(treesit-font-lock-settings): Change format.
(treesit-font-lock-rules): Remove :toggle and :level, add :feature.
(treesit-font-lock-recompute-features): New function.
(treesit-font-lock-fontify-region): Change to work with the new
format.
(treesit-font-lock-enable): Add call to
treesit-font-lock-recompute-features.  And improve the font-lock-mode
workaround.
This commit is contained in:
Yuan Fu 2022-10-13 14:44:42 -07:00
parent f0e9085a17
commit af288d813b
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
3 changed files with 93 additions and 86 deletions

View file

@ -1032,7 +1032,7 @@ Do not fontify the initial f for f-strings."
(defvar python--treesit-settings
(treesit-font-lock-rules
:language 'python
:level 1
:feature 'basic
'(;; Queries for def and class.
(function_definition
name: (identifier) @font-lock-function-name-face)
@ -1048,7 +1048,7 @@ Do not fontify the initial f for f-strings."
(:match "^\"\"\"" @font-lock-doc-face))
(interpolation (identifier) @font-lock-variable-name-face))
:language 'python
:level 2
:feature 'moderate
:override t
`(;; Keywords, builtins, and constants.
[,@python--treesit-keywords] @font-lock-keyword-face
@ -1066,7 +1066,7 @@ Do not fontify the initial f for f-strings."
[(true) (false) (none)] @font-lock-constant-face)
:language 'python
:level 3
:feature 'elaborate
:override t
`(;; Variable names.
(assignment left: (identifier)
@ -6401,7 +6401,9 @@ Add import for undefined name `%s' (empty to skip): "
(if (and python-use-tree-sitter
(treesit-can-enable-p))
(progn
(setq-local font-lock-defaults '(nil t))
(setq-local font-lock-keywords-only t)
(setq-local treesit-font-lock-feature-list
'((basic) (moderate) (elaborate)))
(setq-local treesit-font-lock-settings
python--treesit-settings)
(treesit-font-lock-enable))