summaryrefslogtreecommitdiff
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorkobarity <kobarity@gmail.com>2023-06-02 22:52:57 +0900
committerEli Zaretskii <eliz@gnu.org>2023-06-03 10:09:33 +0300
commit6b2c8dc9050c5c0514fa404733ce1d4a37d00e39 (patch)
treefe44b5ae27d89cccbcad97efda16fa063ac5fe1c /lisp/progmodes/python.el
parent348e4504c6d5588443809ec28da3c3c693368e16 (diff)
downloademacs-6b2c8dc9050c5c0514fa404733ce1d4a37d00e39.tar.gz
emacs-6b2c8dc9050c5c0514fa404733ce1d4a37d00e39.tar.bz2
emacs-6b2c8dc9050c5c0514fa404733ce1d4a37d00e39.zip
Revert "Enhance Python font-lock to support multilines"
This reverts commit 4915ca5dd4245a909c046e6691e8d4a1919890c8. We have found that there are performance issues when editing a large file. The issue can be reproduced as follows: 1. emacs -Q 2. Open large Python file (e.g. turtle.py in Python) 3. Near the top of the buffer, enter open paren and some characters. The above commit extends the region to be font-locked using `python-nav-end-of-statement'. However, if there are unbalanced parens, it may move point to the end of the buffer. This causes almost the entire buffer to be font-locked, which is not acceptable for large files.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el49
1 files changed, 15 insertions, 34 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index adaeacc2ec1..974e07c3c6a 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -415,7 +415,6 @@ instead."
"Python mode specialized rx macro.
This variant of `rx' supports common Python named REGEXPS."
`(rx-let ((sp-bsnl (or space (and ?\\ ?\n)))
- (sp-nl (or space (and (? ?\\) ?\n)))
(block-start (seq symbol-start
(or "def" "class" "if" "elif" "else" "try"
"except" "finally" "for" "while" "with"
@@ -650,9 +649,9 @@ the {...} holes that appear within f-strings."
finally return (and result-valid result))))
(defvar python-font-lock-keywords-level-1
- `((,(python-rx symbol-start "def" (1+ sp-bsnl) (group symbol-name))
+ `((,(python-rx symbol-start "def" (1+ space) (group symbol-name))
(1 font-lock-function-name-face))
- (,(python-rx symbol-start "class" (1+ sp-bsnl) (group symbol-name))
+ (,(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.
@@ -792,12 +791,12 @@ sign in chained assignment."
;; [*a] = 5, 6
;; are handled separately below
(,(python-font-lock-assignment-matcher
- (python-rx (? (or "[" "(") (* sp-nl))
- grouped-assignment-target (* sp-nl) ?, (* sp-nl)
- (* assignment-target (* sp-nl) ?, (* sp-nl))
- (? assignment-target (* sp-nl))
- (? ?, (* sp-nl))
- (? (or ")" "]") (* sp-bsnl))
+ (python-rx (? (or "[" "(") (* space))
+ grouped-assignment-target (* space) ?, (* space)
+ (* assignment-target (* space) ?, (* space))
+ (? assignment-target (* space))
+ (? ?, (* space))
+ (? (or ")" "]") (* space))
(group assignment-operator)))
(1 font-lock-variable-name-face)
(2 'font-lock-operator-face)
@@ -813,9 +812,9 @@ sign in chained assignment."
;; c: Collection = {1, 2, 3}
;; d: Mapping[int, str] = {1: 'bar', 2: 'baz'}
(,(python-font-lock-assignment-matcher
- (python-rx (or line-start ?\;) (* sp-bsnl)
- grouped-assignment-target (* sp-bsnl)
- (? ?: (* sp-bsnl) (+ not-simple-operator) (* sp-bsnl))
+ (python-rx (or line-start ?\;) (* space)
+ grouped-assignment-target (* space)
+ (? ?: (* space) (+ not-simple-operator) (* space))
(group assignment-operator)))
(1 font-lock-variable-name-face)
(2 'font-lock-operator-face))
@@ -824,10 +823,10 @@ sign in chained assignment."
;; [a] = 5,
;; [*a] = 5, 6
(,(python-font-lock-assignment-matcher
- (python-rx (or line-start ?\; ?=) (* sp-bsnl)
- (or "[" "(") (* sp-nl)
- grouped-assignment-target (* sp-nl)
- (or ")" "]") (* sp-bsnl)
+ (python-rx (or line-start ?\; ?=) (* space)
+ (or "[" "(") (* space)
+ grouped-assignment-target (* space)
+ (or ")" "]") (* space)
(group assignment-operator)))
(1 font-lock-variable-name-face)
(2 'font-lock-operator-face))
@@ -869,22 +868,6 @@ decorators, exceptions, and assignments.")
Which one will be chosen depends on the value of
`font-lock-maximum-decoration'.")
-(defvar font-lock-beg)
-(defvar font-lock-end)
-(defun python-font-lock-extend-region ()
- "Extend font-lock region to statement boundaries."
- (let ((beg font-lock-beg)
- (end font-lock-end))
- (goto-char beg)
- (python-nav-beginning-of-statement)
- (beginning-of-line)
- (when (< (point) beg)
- (setq font-lock-beg (point)))
- (goto-char end)
- (python-nav-end-of-statement)
- (when (< end (point))
- (setq font-lock-end (point)))
- (or (/= beg font-lock-beg) (/= end font-lock-end))))
(defconst python-syntax-propertize-function
(syntax-propertize-rules
@@ -6709,8 +6692,6 @@ implementations: `python-mode' and `python-ts-mode'."
nil nil nil nil
(font-lock-syntactic-face-function
. python-font-lock-syntactic-face-function)))
- (add-hook 'font-lock-extend-region-functions
- #'python-font-lock-extend-region nil t)
(setq-local syntax-propertize-function
python-syntax-propertize-function)
(setq-local imenu-create-index-function