aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2022-10-09 15:19:36 -0700
committerYuan Fu2022-10-09 17:20:40 -0700
commitbb8376145abadd901b0d8f7f586bef658e2b333c (patch)
tree30427803f75c14ed3bdf6c8369860c9519fbff84
parentc88a1631e3f76926bf0fed49fa1b704d6eaf2155 (diff)
downloademacs-bb8376145abadd901b0d8f7f586bef658e2b333c.tar.gz
emacs-bb8376145abadd901b0d8f7f586bef658e2b333c.zip
Make python tree-sitter font-lock support decoration levels
* lisp/progmodes/python.el (python--treesit-settings): Stratify into three levels.
-rw-r--r--lisp/progmodes/python.el28
1 files changed, 16 insertions, 12 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 801432cd188..d87789fd773 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1031,8 +1031,8 @@ Do not fontify the initial f for f-strings."
1031(defvar python--treesit-settings 1031(defvar python--treesit-settings
1032 (treesit-font-lock-rules 1032 (treesit-font-lock-rules
1033 :language 'python 1033 :language 'python
1034 :override t 1034 :level 1
1035 `(;; Queries for def and class. 1035 '(;; Queries for def and class.
1036 (function_definition 1036 (function_definition
1037 name: (identifier) @font-lock-function-name-face) 1037 name: (identifier) @font-lock-function-name-face)
1038 1038
@@ -1045,9 +1045,11 @@ Do not fontify the initial f for f-strings."
1045 (string) @python--treesit-fontify-string 1045 (string) @python--treesit-fontify-string
1046 ((string) @font-lock-doc-face 1046 ((string) @font-lock-doc-face
1047 (:match "^\"\"\"" @font-lock-doc-face)) 1047 (:match "^\"\"\"" @font-lock-doc-face))
1048 (interpolation (identifier) @font-lock-variable-name-face) 1048 (interpolation (identifier) @font-lock-variable-name-face))
1049 1049 :language 'python
1050 ;; Keywords, builtins, and constants. 1050 :level 2
1051 :override t
1052 `(;; Keywords, builtins, and constants.
1051 [,@python--treesit-keywords] @font-lock-keyword-face 1053 [,@python--treesit-keywords] @font-lock-keyword-face
1052 1054
1053 ((identifier) @font-lock-keyword-face 1055 ((identifier) @font-lock-keyword-face
@@ -1061,12 +1063,11 @@ Do not fontify the initial f for f-strings."
1061 eol)) 1063 eol))
1062 @font-lock-builtin-face)) 1064 @font-lock-builtin-face))
1063 1065
1064 [(true) (false) (none)] @font-lock-constant-face 1066 [(true) (false) (none)] @font-lock-constant-face)
1065 1067 :language 'python
1066 ;; Escape sequences 1068 :level 3
1067 (escape_sequence) @font-lock-constant-face 1069 :override t
1068 1070 `(;; Variable names.
1069 ;; Variable names.
1070 (assignment left: (identifier) 1071 (assignment left: (identifier)
1071 @font-lock-variable-name-face) 1072 @font-lock-variable-name-face)
1072 (assignment left: (attribute 1073 (assignment left: (attribute
@@ -1088,7 +1089,10 @@ Do not fontify the initial f for f-strings."
1088 `(seq bol (or ,@python--treesit-exceptions) 1089 `(seq bol (or ,@python--treesit-exceptions)
1089 eol)) 1090 eol))
1090 @font-lock-type-face)) 1091 @font-lock-type-face))
1091 (type (identifier) @font-lock-type-face))) 1092 (type (identifier) @font-lock-type-face)
1093
1094 ;; Escape sequences
1095 (escape_sequence) @font-lock-constant-face))
1092 "Tree-sitter font-lock settings.") 1096 "Tree-sitter font-lock settings.")
1093 1097
1094 1098