diff options
author | Dmitry Gutov <dgutov@yandex.ru> | 2023-02-25 03:15:46 +0200 |
---|---|---|
committer | Dmitry Gutov <dgutov@yandex.ru> | 2023-02-25 03:35:08 +0200 |
commit | a795c51f6053272de61bc1721305e3c15ff424ee (patch) | |
tree | 4dcc2aea937392b95296c4b943059f1d5c454800 /lisp/progmodes/python.el | |
parent | 146bce49321da3b65d0a0e0326bb54cf1e79551c (diff) | |
download | emacs-a795c51f6053272de61bc1721305e3c15ff424ee.tar.gz emacs-a795c51f6053272de61bc1721305e3c15ff424ee.tar.bz2 emacs-a795c51f6053272de61bc1721305e3c15ff424ee.zip |
Add more/finer faces for tree-sitter
* doc/lispref/modes.texi (Faces for Font Lock):
Update the list of faces (bug#61655).
* etc/NEWS: Update the list of new faces.
* lisp/cus-theme.el (custom-theme--listed-faces): Update.
* lisp/font-lock.el (font-lock-function-call-face)
(font-lock-variable-ref-face, font-lock-property-ref-face):
New faces.
(font-lock-property-name-face):
Rename from 'font-lock-property-face'.
* lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings):
Use new faces. More 'enumerator' query to 'definition' feature.
(c-ts-mode--fontify-declarator, c-ts-mode--fontify-variable):
Use new faces.
* lisp/progmodes/cmake-ts-mode.el
(cmake-ts-mode--font-lock-settings): Use new faces.
* lisp/progmodes/csharp-mode.el
(csharp-ts-mode--font-lock-settings): Use new faces.
* lisp/progmodes/go-ts-mode.el (go-ts-mode--font-lock-settings):
Use new faces.
* lisp/progmodes/java-ts-mode.el
(java-ts-mode--font-lock-settings): Use new faces.
* lisp/progmodes/js.el (js--treesit-fontify-assignment-lhs)
(js--treesit-font-lock-settings): Use new faces. Highlight
variable definitions inside array and object destructuring
patterns.
* lisp/progmodes/python.el (python--treesit-variable-p):
Exclude identifiers in parameters.
(python--treesit-settings): Use new faces. Highlight function
parameters. Move 'keyword' up to still highlight 'self' as
keyword.
* lisp/progmodes/ruby-ts-mode.el (ruby-ts--font-lock-settings):
Use new faces.
* lisp/progmodes/rust-ts-mode.el
(rust-ts-mode--font-lock-settings): Use new faces.
* lisp/progmodes/typescript-ts-mode.el
(typescript-ts-mode--font-lock-settings): Use new faces.
* lisp/textmodes/css-mode.el (css--treesit-settings):
Use font-lock-property-ref-face.
* lisp/textmodes/toml-ts-mode.el
(toml-ts-mode--font-lock-settings):
Use font-lock-property-ref-face.
* lisp/textmodes/yaml-ts-mode.el
(yaml-ts-mode--font-lock-settings): Same.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r-- | lisp/progmodes/python.el | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index eab5e70af33..8220e3086fd 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1106,24 +1106,25 @@ fontified." :language 'python '((interpolation) @python--treesit-fontify-string-interpolation) + :feature 'keyword + :language 'python + `([,@python--treesit-keywords] @font-lock-keyword-face + ((identifier) @font-lock-keyword-face + (:match "^self$" @font-lock-keyword-face))) + :feature 'definition :language 'python '((function_definition name: (identifier) @font-lock-function-name-face) (class_definition - name: (identifier) @font-lock-type-face)) + name: (identifier) @font-lock-type-face) + (parameters (identifier) @font-lock-variable-name-face)) :feature 'function :language 'python - '((call function: (identifier) @font-lock-function-name-face) + '((call function: (identifier) @font-lock-function-call-face) (call function: (attribute - attribute: (identifier) @font-lock-function-name-face))) - - :feature 'keyword - :language 'python - `([,@python--treesit-keywords] @font-lock-keyword-face - ((identifier) @font-lock-keyword-face - (:match "^self$" @font-lock-keyword-face))) + attribute: (identifier) @font-lock-function-call-face))) :feature 'builtin :language 'python @@ -1146,7 +1147,7 @@ fontified." @font-lock-variable-name-face) (assignment left: (attribute attribute: (identifier) - @font-lock-property-face)) + @font-lock-property-ref-face)) (pattern_list (identifier) @font-lock-variable-name-face) (tuple_pattern (identifier) @@ -1183,12 +1184,12 @@ fontified." :feature 'property :language 'python '((attribute - attribute: (identifier) @font-lock-property-face) + attribute: (identifier) @font-lock-property-ref-face) (class_definition body: (block (expression_statement (assignment left: - (identifier) @font-lock-property-face))))) + (identifier) @font-lock-property-ref-face))))) :feature 'operator :language 'python @@ -1211,10 +1212,10 @@ fontified." "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 function filters out function/class names and - ;; properties. + ;; variables. This function filters out function/class names, + ;; properties and method parameters. (pcase (treesit-node-type (treesit-node-parent node)) - ((or "function_definition" "class_definition") nil) + ((or "function_definition" "class_definition" "parameters") nil) ("attribute" (pcase (treesit-node-field-name node) ("object" t) |