aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorYuan Fu2022-10-13 14:44:42 -0700
committerYuan Fu2022-10-13 14:44:42 -0700
commitaf288d813b3c31a528ddcbdce08f497855a56e94 (patch)
tree3dd300e76e0d249b99812d385e18873f34d1088a /lisp/progmodes/python.el
parentf0e9085a17be8866c123b120e3252c52845ec38e (diff)
downloademacs-af288d813b3c31a528ddcbdce08f497855a56e94.tar.gz
emacs-af288d813b3c31a528ddcbdce08f497855a56e94.zip
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.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el10
1 files changed, 6 insertions, 4 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index a0466707e60..c48f9e95e98 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1032,7 +1032,7 @@ Do not fontify the initial f for f-strings."
1032(defvar python--treesit-settings 1032(defvar python--treesit-settings
1033 (treesit-font-lock-rules 1033 (treesit-font-lock-rules
1034 :language 'python 1034 :language 'python
1035 :level 1 1035 :feature 'basic
1036 '(;; Queries for def and class. 1036 '(;; Queries for def and class.
1037 (function_definition 1037 (function_definition
1038 name: (identifier) @font-lock-function-name-face) 1038 name: (identifier) @font-lock-function-name-face)
@@ -1048,7 +1048,7 @@ Do not fontify the initial f for f-strings."
1048 (:match "^\"\"\"" @font-lock-doc-face)) 1048 (:match "^\"\"\"" @font-lock-doc-face))
1049 (interpolation (identifier) @font-lock-variable-name-face)) 1049 (interpolation (identifier) @font-lock-variable-name-face))
1050 :language 'python 1050 :language 'python
1051 :level 2 1051 :feature 'moderate
1052 :override t 1052 :override t
1053 `(;; Keywords, builtins, and constants. 1053 `(;; Keywords, builtins, and constants.
1054 [,@python--treesit-keywords] @font-lock-keyword-face 1054 [,@python--treesit-keywords] @font-lock-keyword-face
@@ -1066,7 +1066,7 @@ Do not fontify the initial f for f-strings."
1066 1066
1067 [(true) (false) (none)] @font-lock-constant-face) 1067 [(true) (false) (none)] @font-lock-constant-face)
1068 :language 'python 1068 :language 'python
1069 :level 3 1069 :feature 'elaborate
1070 :override t 1070 :override t
1071 `(;; Variable names. 1071 `(;; Variable names.
1072 (assignment left: (identifier) 1072 (assignment left: (identifier)
@@ -6401,7 +6401,9 @@ Add import for undefined name `%s' (empty to skip): "
6401 (if (and python-use-tree-sitter 6401 (if (and python-use-tree-sitter
6402 (treesit-can-enable-p)) 6402 (treesit-can-enable-p))
6403 (progn 6403 (progn
6404 (setq-local font-lock-defaults '(nil t)) 6404 (setq-local font-lock-keywords-only t)
6405 (setq-local treesit-font-lock-feature-list
6406 '((basic) (moderate) (elaborate)))
6405 (setq-local treesit-font-lock-settings 6407 (setq-local treesit-font-lock-settings
6406 python--treesit-settings) 6408 python--treesit-settings)
6407 (treesit-font-lock-enable)) 6409 (treesit-font-lock-enable))