aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorDmitry Gutov2023-02-25 03:15:46 +0200
committerDmitry Gutov2023-02-25 03:35:08 +0200
commita795c51f6053272de61bc1721305e3c15ff424ee (patch)
tree4dcc2aea937392b95296c4b943059f1d5c454800 /lisp/progmodes/python.el
parent146bce49321da3b65d0a0e0326bb54cf1e79551c (diff)
downloademacs-a795c51f6053272de61bc1721305e3c15ff424ee.tar.gz
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.el31
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."
1106 :language 'python 1106 :language 'python
1107 '((interpolation) @python--treesit-fontify-string-interpolation) 1107 '((interpolation) @python--treesit-fontify-string-interpolation)
1108 1108
1109 :feature 'keyword
1110 :language 'python
1111 `([,@python--treesit-keywords] @font-lock-keyword-face
1112 ((identifier) @font-lock-keyword-face
1113 (:match "^self$" @font-lock-keyword-face)))
1114
1109 :feature 'definition 1115 :feature 'definition
1110 :language 'python 1116 :language 'python
1111 '((function_definition 1117 '((function_definition
1112 name: (identifier) @font-lock-function-name-face) 1118 name: (identifier) @font-lock-function-name-face)
1113 (class_definition 1119 (class_definition
1114 name: (identifier) @font-lock-type-face)) 1120 name: (identifier) @font-lock-type-face)
1121 (parameters (identifier) @font-lock-variable-name-face))
1115 1122
1116 :feature 'function 1123 :feature 'function
1117 :language 'python 1124 :language 'python
1118 '((call function: (identifier) @font-lock-function-name-face) 1125 '((call function: (identifier) @font-lock-function-call-face)
1119 (call function: (attribute 1126 (call function: (attribute
1120 attribute: (identifier) @font-lock-function-name-face))) 1127 attribute: (identifier) @font-lock-function-call-face)))
1121
1122 :feature 'keyword
1123 :language 'python
1124 `([,@python--treesit-keywords] @font-lock-keyword-face
1125 ((identifier) @font-lock-keyword-face
1126 (:match "^self$" @font-lock-keyword-face)))
1127 1128
1128 :feature 'builtin 1129 :feature 'builtin
1129 :language 'python 1130 :language 'python
@@ -1146,7 +1147,7 @@ fontified."
1146 @font-lock-variable-name-face) 1147 @font-lock-variable-name-face)
1147 (assignment left: (attribute 1148 (assignment left: (attribute
1148 attribute: (identifier) 1149 attribute: (identifier)
1149 @font-lock-property-face)) 1150 @font-lock-property-ref-face))
1150 (pattern_list (identifier) 1151 (pattern_list (identifier)
1151 @font-lock-variable-name-face) 1152 @font-lock-variable-name-face)
1152 (tuple_pattern (identifier) 1153 (tuple_pattern (identifier)
@@ -1183,12 +1184,12 @@ fontified."
1183 :feature 'property 1184 :feature 'property
1184 :language 'python 1185 :language 'python
1185 '((attribute 1186 '((attribute
1186 attribute: (identifier) @font-lock-property-face) 1187 attribute: (identifier) @font-lock-property-ref-face)
1187 (class_definition 1188 (class_definition
1188 body: (block 1189 body: (block
1189 (expression_statement 1190 (expression_statement
1190 (assignment left: 1191 (assignment left:
1191 (identifier) @font-lock-property-face))))) 1192 (identifier) @font-lock-property-ref-face)))))
1192 1193
1193 :feature 'operator 1194 :feature 'operator
1194 :language 'python 1195 :language 'python
@@ -1211,10 +1212,10 @@ fontified."
1211 "Check whether NODE is a variable. 1212 "Check whether NODE is a variable.
1212NODE's type should be \"identifier\"." 1213NODE's type should be \"identifier\"."
1213 ;; An identifier can be a function/class name, a property, or a 1214 ;; An identifier can be a function/class name, a property, or a
1214 ;; variables. This function filters out function/class names and 1215 ;; variables. This function filters out function/class names,
1215 ;; properties. 1216 ;; properties and method parameters.
1216 (pcase (treesit-node-type (treesit-node-parent node)) 1217 (pcase (treesit-node-type (treesit-node-parent node))
1217 ((or "function_definition" "class_definition") nil) 1218 ((or "function_definition" "class_definition" "parameters") nil)
1218 ("attribute" 1219 ("attribute"
1219 (pcase (treesit-node-field-name node) 1220 (pcase (treesit-node-field-name node)
1220 ("object" t) 1221 ("object" t)