Make python tree-sitter font-lock support decoration levels

* lisp/progmodes/python.el (python--treesit-settings): Stratify into
three levels.
This commit is contained in:
Yuan Fu 2022-10-09 15:19:36 -07:00
parent c88a1631e3
commit bb8376145a
No known key found for this signature in database
GPG key ID: 56E19BC57664A442

View file

@ -1031,8 +1031,8 @@ Do not fontify the initial f for f-strings."
(defvar python--treesit-settings (defvar python--treesit-settings
(treesit-font-lock-rules (treesit-font-lock-rules
:language 'python :language 'python
:override t :level 1
`(;; Queries for def and class. '(;; Queries for def and class.
(function_definition (function_definition
name: (identifier) @font-lock-function-name-face) name: (identifier) @font-lock-function-name-face)
@ -1045,9 +1045,11 @@ Do not fontify the initial f for f-strings."
(string) @python--treesit-fontify-string (string) @python--treesit-fontify-string
((string) @font-lock-doc-face ((string) @font-lock-doc-face
(:match "^\"\"\"" @font-lock-doc-face)) (:match "^\"\"\"" @font-lock-doc-face))
(interpolation (identifier) @font-lock-variable-name-face) (interpolation (identifier) @font-lock-variable-name-face))
:language 'python
;; Keywords, builtins, and constants. :level 2
:override t
`(;; Keywords, builtins, and constants.
[,@python--treesit-keywords] @font-lock-keyword-face [,@python--treesit-keywords] @font-lock-keyword-face
((identifier) @font-lock-keyword-face ((identifier) @font-lock-keyword-face
@ -1061,12 +1063,11 @@ Do not fontify the initial f for f-strings."
eol)) eol))
@font-lock-builtin-face)) @font-lock-builtin-face))
[(true) (false) (none)] @font-lock-constant-face [(true) (false) (none)] @font-lock-constant-face)
:language 'python
;; Escape sequences :level 3
(escape_sequence) @font-lock-constant-face :override t
`(;; Variable names.
;; Variable names.
(assignment left: (identifier) (assignment left: (identifier)
@font-lock-variable-name-face) @font-lock-variable-name-face)
(assignment left: (attribute (assignment left: (attribute
@ -1088,7 +1089,10 @@ Do not fontify the initial f for f-strings."
`(seq bol (or ,@python--treesit-exceptions) `(seq bol (or ,@python--treesit-exceptions)
eol)) eol))
@font-lock-type-face)) @font-lock-type-face))
(type (identifier) @font-lock-type-face))) (type (identifier) @font-lock-type-face)
;; Escape sequences
(escape_sequence) @font-lock-constant-face))
"Tree-sitter font-lock settings.") "Tree-sitter font-lock settings.")