]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't font-lock invalid invalid class/function names
authorkobarity <kobarity@gmail.com>
Sun, 22 May 2022 16:53:00 +0000 (18:53 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 22 May 2022 16:54:23 +0000 (18:54 +0200)
* lisp/progmodes/python.el (python-font-lock-keywords-level-1):
Don't font-lock invalid invalid class/function names (bug#55573).

lisp/progmodes/python.el
test/lisp/progmodes/python-tests.el

index c1368364a975130b513be582501fc979c834bacf..9adbb82abf4d0fa9d3aa1b80c50ec042089d2622 100644 (file)
@@ -540,9 +540,9 @@ the {...} holes that appear within f-strings."
         (setq ppss (syntax-ppss))))))
 
 (defvar python-font-lock-keywords-level-1
-  `((,(rx symbol-start "def" (1+ space) (group (1+ (or word ?_))))
+  `((,(python-rx symbol-start "def" (1+ space) (group symbol-name))
      (1 font-lock-function-name-face))
-    (,(rx symbol-start "class" (1+ space) (group (1+ (or word ?_))))
+    (,(python-rx symbol-start "class" (1+ space) (group symbol-name))
      (1 font-lock-type-face)))
   "Font lock keywords to use in `python-mode' for level 1 decoration.
 
index a3f778bbbe9db0a7f55f8c00ae87fba18a1e3535..479d68a0623592ae623d0d1a31f48e11aceb3765 100644 (file)
@@ -214,6 +214,18 @@ aliqua."
     (should (string= (buffer-string) "\"\""))
     (should (null (nth 3 (syntax-ppss))))))
 
+(ert-deftest python-font-lock-keywords-level-1-1 ()
+  (python-tests-assert-faces
+   "def func():"
+   '((1 . font-lock-keyword-face) (4)
+     (5 . font-lock-function-name-face) (9))))
+
+(ert-deftest python-font-lock-keywords-level-1-2 ()
+  "Invalid function name should not be font-locked."
+  (python-tests-assert-faces
+   "def 1func():"
+   '((1 . font-lock-keyword-face) (4))))
+
 (ert-deftest python-font-lock-assignment-statement-1 ()
   (python-tests-assert-faces
    "a, b, c = 1, 2, 3"