]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix python tree-sitter font-lock
authorYuan Fu <casouri@gmail.com>
Tue, 4 Oct 2022 19:18:53 +0000 (12:18 -0700)
committerYuan Fu <casouri@gmail.com>
Tue, 4 Oct 2022 20:30:56 +0000 (13:30 -0700)
Add fontification for lhs attribute and some operators.

* lisp/progmodes/python.el (python--treesit-keywords): Add operators.
(python--treesit-settings): Add lhs attribute.

lisp/progmodes/python.el

index 5b70c63f7b42ed85a33c3fc56d03acfc67a78bf3..3f85201c107f23f7e54edaf5340ffae06d92bd49 100644 (file)
@@ -915,7 +915,10 @@ It makes underscores and dots word constituent chars.")
   '("as" "assert" "async" "await" "break" "class" "continue" "def"
     "del" "elif" "else" "except" "exec" "finally" "for" "from"
     "global" "if" "import" "lambda" "nonlocal" "pass" "print"
-    "raise" "return" "try" "while" "with" "yield"))
+    "raise" "return" "try" "while" "with" "yield"
+    ;; These are technically operators, but we fontify them as
+    ;; keywords.
+    "and" "in" "is" "not" "or"))
 
 (defvar python--treesit-builtins
   '("abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray"
@@ -934,6 +937,8 @@ It makes underscores and dots word constituent chars.")
     "copyright" "credits" "exit" "license" "quit"))
 
 (defvar python--treesit-operators
+  ;; This is not used. And and, or, not, is, in are fontified as
+  ;; keywords.
   '("-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "%" "%="
     "^" "+" "+=" "<" "<<" "<=" "<>" "=" "==" ">" ">=" ">>" "|" "~"
     "and" "in" "is" "not" "or"))
@@ -1019,6 +1024,9 @@ Do not fontify the initial f for f-strings."
      ;; Variable names.
      (assignment left: (identifier)
                  @font-lock-variable-name-face)
+     (assignment left: (attribute
+                        attribute: (identifier)
+                        @font-lock-variable-name-face))
      (pattern_list (identifier)
                    @font-lock-variable-name-face)
      (tuple_pattern (identifier)