From: Jostein Kjønigsen Date: Thu, 20 Mar 2025 09:39:31 +0000 (+0100) Subject: Improve python-ts-mode fontification (bug#78129) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=137d435a70b1067bc539b3fe5035d9399203219f;p=emacs.git 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. (cherry picked from commit 2964d51c9cd9b55e60901069c378d0e8277d60f9) --- diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index e9db1f6af0c..ee014549c7f 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1229,7 +1229,15 @@ fontified." name: (identifier) @font-lock-type-face) (parameters (identifier) @font-lock-variable-name-face) (parameters (typed_parameter (identifier) @font-lock-variable-name-face)) - (parameters (default_parameter name: (identifier) @font-lock-variable-name-face))) + (parameters (default_parameter name: (identifier) @font-lock-variable-name-face)) + (lambda_parameters (identifier) @font-lock-variable-name-face) + (for_in_clause + left: (identifier) @font-lock-variable-name-face) + ((import_from_statement + name: ((dotted_name (identifier) @font-lock-type-face))) + (:match "\\`[A-Z][A-Za-z0-9]+\\'" @font-lock-type-face)) + (import_from_statement + name: ((dotted_name (identifier) @font-lock-variable-name-face)))) :feature 'builtin :language 'python @@ -1258,7 +1266,12 @@ fontified." :feature 'constant :language 'python - '([(true) (false) (none)] @font-lock-constant-face) + '([(true) (false) (none)] @font-lock-constant-face + ((identifier) @font-lock-constant-face + (:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face)) + ((attribute + attribute: (identifier) @font-lock-constant-face) + (:match "\\`[A-Z][A-Z0-9_]+\\'" @font-lock-constant-face))) :feature 'assignment :language 'python @@ -1286,8 +1299,6 @@ fontified." :feature 'type :language 'python - ;; Override built-in faces when dict/list are used for type hints. - :override t `(((identifier) @font-lock-type-face (:match ,(rx-to-string `(seq bol (or ,@python--treesit-exceptions) @@ -1332,7 +1343,9 @@ fontified." ((call function: (identifier) @func-name (argument_list :anchor (_) (binary_operator) @python--treesit-fontify-union-types-strict)) - (:match "^is\\(?:instance\\|subclass\\)$" @func-name))) + (:match "^is\\(?:instance\\|subclass\\)$" @func-name)) + ((identifier) @font-lock-type-face + (:match "\\`[A-Z][A-Za-z0-9]+\\'" @font-lock-type-face))) :feature 'escape-sequence :language 'python