diff options
| author | kobarity | 2022-05-22 18:53:00 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-05-22 18:54:23 +0200 |
| commit | 45694a25948146e860738cb4e01de7e7e9aa91b0 (patch) | |
| tree | 39b33e2398583882f3791f7c9926eccc3da34105 | |
| parent | 91bc24c46768aab4a851c87edaea05c7476ff779 (diff) | |
| download | emacs-45694a25948146e860738cb4e01de7e7e9aa91b0.tar.gz emacs-45694a25948146e860738cb4e01de7e7e9aa91b0.zip | |
Don't font-lock invalid invalid class/function names
* lisp/progmodes/python.el (python-font-lock-keywords-level-1):
Don't font-lock invalid invalid class/function names (bug#55573).
| -rw-r--r-- | lisp/progmodes/python.el | 4 | ||||
| -rw-r--r-- | test/lisp/progmodes/python-tests.el | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index c1368364a97..9adbb82abf4 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -540,9 +540,9 @@ the {...} holes that appear within f-strings." | |||
| 540 | (setq ppss (syntax-ppss)))))) | 540 | (setq ppss (syntax-ppss)))))) |
| 541 | 541 | ||
| 542 | (defvar python-font-lock-keywords-level-1 | 542 | (defvar python-font-lock-keywords-level-1 |
| 543 | `((,(rx symbol-start "def" (1+ space) (group (1+ (or word ?_)))) | 543 | `((,(python-rx symbol-start "def" (1+ space) (group symbol-name)) |
| 544 | (1 font-lock-function-name-face)) | 544 | (1 font-lock-function-name-face)) |
| 545 | (,(rx symbol-start "class" (1+ space) (group (1+ (or word ?_)))) | 545 | (,(python-rx symbol-start "class" (1+ space) (group symbol-name)) |
| 546 | (1 font-lock-type-face))) | 546 | (1 font-lock-type-face))) |
| 547 | "Font lock keywords to use in `python-mode' for level 1 decoration. | 547 | "Font lock keywords to use in `python-mode' for level 1 decoration. |
| 548 | 548 | ||
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index a3f778bbbe9..479d68a0623 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el | |||
| @@ -214,6 +214,18 @@ aliqua." | |||
| 214 | (should (string= (buffer-string) "\"\"")) | 214 | (should (string= (buffer-string) "\"\"")) |
| 215 | (should (null (nth 3 (syntax-ppss)))))) | 215 | (should (null (nth 3 (syntax-ppss)))))) |
| 216 | 216 | ||
| 217 | (ert-deftest python-font-lock-keywords-level-1-1 () | ||
| 218 | (python-tests-assert-faces | ||
| 219 | "def func():" | ||
| 220 | '((1 . font-lock-keyword-face) (4) | ||
| 221 | (5 . font-lock-function-name-face) (9)))) | ||
| 222 | |||
| 223 | (ert-deftest python-font-lock-keywords-level-1-2 () | ||
| 224 | "Invalid function name should not be font-locked." | ||
| 225 | (python-tests-assert-faces | ||
| 226 | "def 1func():" | ||
| 227 | '((1 . font-lock-keyword-face) (4)))) | ||
| 228 | |||
| 217 | (ert-deftest python-font-lock-assignment-statement-1 () | 229 | (ert-deftest python-font-lock-assignment-statement-1 () |
| 218 | (python-tests-assert-faces | 230 | (python-tests-assert-faces |
| 219 | "a, b, c = 1, 2, 3" | 231 | "a, b, c = 1, 2, 3" |