aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorJostein Kjønigsen2025-03-20 10:39:31 +0100
committerYuan Fu2025-05-01 00:54:33 -0700
commit2964d51c9cd9b55e60901069c378d0e8277d60f9 (patch)
tree8d3777e1657e1ec75f902d54241878e9923f617d /lisp/progmodes/python.el
parent6c35ae082770c1bb875e870f83c3eff4a3197283 (diff)
downloademacs-2964d51c9cd9b55e60901069c378d0e8277d60f9.tar.gz
emacs-2964d51c9cd9b55e60901069c378d0e8277d60f9.zip
Improve python-ts-mode fontification (bug#78129)
Fontification based on selectors & code-conventions: - Lambda parameters: variable declarations - For in statements: variable declarations - Import statements: variable declerations - Constants: All upper case alphanumerical identifiers - Types: CamelCase alphanumerical identifiers - Enums: Enum-values as constants. * lisp/progmodes/python.el: (python--treesit-settings): Improve queries.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el23
1 files changed, 18 insertions, 5 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 32df5846b67..b057e2b24f0 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1235,7 +1235,15 @@ fontified."
1235 name: (identifier) @font-lock-type-face) 1235 name: (identifier) @font-lock-type-face)
1236 (parameters (identifier) @font-lock-variable-name-face) 1236 (parameters (identifier) @font-lock-variable-name-face)
1237 (parameters (typed_parameter (identifier) @font-lock-variable-name-face)) 1237 (parameters (typed_parameter (identifier) @font-lock-variable-name-face))
1238 (parameters (default_parameter name: (identifier) @font-lock-variable-name-face))) 1238 (parameters (default_parameter name: (identifier) @font-lock-variable-name-face))
1239 (lambda_parameters (identifier) @font-lock-variable-name-face)
1240 (for_in_clause
1241 left: (identifier) @font-lock-variable-name-face)
1242 ((import_from_statement
1243 name: ((dotted_name (identifier) @font-lock-type-face)))
1244 (:match "\\`[A-Z][A-Za-z0-9]+\\'" @font-lock-type-face))
1245 (import_from_statement
1246 name: ((dotted_name (identifier) @font-lock-variable-name-face))))
1239 1247
1240 :feature 'builtin 1248 :feature 'builtin
1241 :language 'python 1249 :language 'python
@@ -1264,7 +1272,12 @@ fontified."
1264 1272
1265 :feature 'constant 1273 :feature 'constant
1266 :language 'python 1274 :language 'python
1267 '([(true) (false) (none)] @font-lock-constant-face) 1275 '([(true) (false) (none)] @font-lock-constant-face
1276 ((identifier) @font-lock-constant-face
1277 (:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face))
1278 ((attribute
1279 attribute: (identifier) @font-lock-constant-face)
1280 (:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face)))
1268 1281
1269 :feature 'assignment 1282 :feature 'assignment
1270 :language 'python 1283 :language 'python
@@ -1292,8 +1305,6 @@ fontified."
1292 1305
1293 :feature 'type 1306 :feature 'type
1294 :language 'python 1307 :language 'python
1295 ;; Override built-in faces when dict/list are used for type hints.
1296 :override t
1297 `(((identifier) @font-lock-type-face 1308 `(((identifier) @font-lock-type-face
1298 (:match ,(rx-to-string 1309 (:match ,(rx-to-string
1299 `(seq bol (or ,@python--treesit-exceptions) 1310 `(seq bol (or ,@python--treesit-exceptions)
@@ -1338,7 +1349,9 @@ fontified."
1338 ((call function: (identifier) @func-name 1349 ((call function: (identifier) @func-name
1339 (argument_list :anchor (_) 1350 (argument_list :anchor (_)
1340 (binary_operator) @python--treesit-fontify-union-types-strict)) 1351 (binary_operator) @python--treesit-fontify-union-types-strict))
1341 (:match "^is\\(?:instance\\|subclass\\)$" @func-name))) 1352 (:match "^is\\(?:instance\\|subclass\\)$" @func-name))
1353 ((identifier) @font-lock-type-face
1354 (:match "\\`[A-Z][A-Za-z0-9]+\\'" @font-lock-type-face)))
1342 1355
1343 :feature 'escape-sequence 1356 :feature 'escape-sequence
1344 :language 'python 1357 :language 'python