[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 8f68b6497e 7/9: Clean up python-ts-mode font-lock features
From: |
Yuan Fu |
Subject: |
emacs-29 8f68b6497e 7/9: Clean up python-ts-mode font-lock features |
Date: |
Mon, 26 Dec 2022 04:48:08 -0500 (EST) |
branch: emacs-29
commit 8f68b6497ee17791c3a1084ebef164f11cb089c6
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Clean up python-ts-mode font-lock features
* lisp/progmodes/python.el (python--treesit-settings): Remove
unnecessary override flags, add function and variable feature, fix
assignment feature.
(python--treesit-variable-p)
(python--treesit-fontify-variable): New functions.
(python-ts-mode): Add function and variable feature.
---
lisp/progmodes/python.el | 39 ++++++++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 0cd0c6c225..9a6f807f4f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1080,7 +1080,6 @@ fontified."
:feature 'string
:language 'python
- :override t
'((string) @python--treesit-fontify-string)
:feature 'string-interpolation
@@ -1130,7 +1129,7 @@ fontified."
@font-lock-variable-name-face)
(assignment left: (attribute
attribute: (identifier)
- @font-lock-variable-name-face))
+ @font-lock-property-face))
(pattern_list (identifier)
@font-lock-variable-name-face)
(tuple_pattern (identifier)
@@ -1162,12 +1161,10 @@ fontified."
:feature 'number
:language 'python
- :override t
'([(integer) (float)] @font-lock-number-face)
:feature 'property
:language 'python
- :override t
'((attribute
attribute: (identifier) @font-lock-property-face)
(class_definition
@@ -1178,20 +1175,44 @@ fontified."
:feature 'operator
:language 'python
- :override t
`([,@python--treesit-operators] @font-lock-operator-face)
:feature 'bracket
:language 'python
- :override t
'(["(" ")" "[" "]" "{" "}"] @font-lock-bracket-face)
:feature 'delimiter
:language 'python
- :override t
- '(["," "." ":" ";" (ellipsis)] @font-lock-delimiter-face))
+ '(["," "." ":" ";" (ellipsis)] @font-lock-delimiter-face)
+
+ :feature 'variable
+ :language 'python
+ '((identifier) @python--treesit-fontify-variable))
"Tree-sitter font-lock settings.")
+(defun python--treesit-variable-p (node)
+ "Check whether NODE is a variable.
+NODE's type should be \"identifier\"."
+ ;; An identifier can be a function/class name, a property, or a
+ ;; variables. This funtion filters out function/class names and
+ ;; properties.
+ (pcase (treesit-node-type (treesit-node-parent node))
+ ((or "function_definition" "class_definition") nil)
+ ("attribute"
+ (pcase (treesit-node-field-name node)
+ ("object" t)
+ (_ nil)))
+ (_ t)))
+
+(defun python--treesit-fontify-variable (node override start end &rest _)
+ "Fontify an identifier node if it is a variable.
+For NODE, OVERRIDE, START, END, and ARGS, see
+`treesit-font-lock-rules'."
+ (when (python--treesit-variable-p node)
+ (treesit-fontify-with-override
+ (treesit-node-start node) (treesit-node-end node)
+ 'font-lock-variable-name-face override start end)))
+
;;; Indentation
@@ -6646,7 +6667,7 @@ implementations: `python-mode' and `python-ts-mode'."
( keyword string type)
( assignment builtin constant decorator
escape-sequence number property string-interpolation )
- ( function bracket delimiter operator)))
+ ( bracket delimiter function operator variable)))
(setq-local treesit-font-lock-settings python--treesit-settings)
(setq-local imenu-create-index-function
#'python-imenu-treesit-create-index)
- emacs-29 updated (2608e5edcc -> d90d7d15f2), Yuan Fu, 2022/12/26
- emacs-29 2bcd1e9a99 3/9: ; * doc/lispref/parsing.texi (Retrieving Nodes): Add notice., Yuan Fu, 2022/12/26
- emacs-29 7c7950fe00 2/9: Add maintainer stub for tree-sitter files, Yuan Fu, 2022/12/26
- emacs-29 c6b0282645 5/9: ; Remove unused function in c-ts-mode, Yuan Fu, 2022/12/26
- emacs-29 6e52a9fcad 4/9: ; * doc/lispref/modes.texi (Parser-based Font Lock): Minor fixes., Yuan Fu, 2022/12/26
- emacs-29 8f68b6497e 7/9: Clean up python-ts-mode font-lock features,
Yuan Fu <=
- emacs-29 eb26872837 8/9: Fix imenu for c-ts-mode (bug#60296), Yuan Fu, 2022/12/26
- emacs-29 d90d7d15f2 9/9: ; Fix vindexes in parsing.texi, Yuan Fu, 2022/12/26
- emacs-29 cf32776622 1/9: ; * doc/lispref/parsing.texi (Using Parser): Remove deleted function., Yuan Fu, 2022/12/26
- emacs-29 28f26b11a1 6/9: Add comment indent and filling to other tree-sitter major modes, Yuan Fu, 2022/12/26