diff options
| author | kobarity | 2023-06-02 22:52:57 +0900 |
|---|---|---|
| committer | Eli Zaretskii | 2023-06-03 10:09:33 +0300 |
| commit | 6b2c8dc9050c5c0514fa404733ce1d4a37d00e39 (patch) | |
| tree | fe44b5ae27d89cccbcad97efda16fa063ac5fe1c /lisp/progmodes/python.el | |
| parent | 348e4504c6d5588443809ec28da3c3c693368e16 (diff) | |
| download | emacs-6b2c8dc9050c5c0514fa404733ce1d4a37d00e39.tar.gz 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.el | 49 |
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." | |||
| 415 | "Python mode specialized rx macro. | 415 | "Python mode specialized rx macro. |
| 416 | This variant of `rx' supports common Python named REGEXPS." | 416 | This variant of `rx' supports common Python named REGEXPS." |
| 417 | `(rx-let ((sp-bsnl (or space (and ?\\ ?\n))) | 417 | `(rx-let ((sp-bsnl (or space (and ?\\ ?\n))) |
| 418 | (sp-nl (or space (and (? ?\\) ?\n))) | ||
| 419 | (block-start (seq symbol-start | 418 | (block-start (seq symbol-start |
| 420 | (or "def" "class" "if" "elif" "else" "try" | 419 | (or "def" "class" "if" "elif" "else" "try" |
| 421 | "except" "finally" "for" "while" "with" | 420 | "except" "finally" "for" "while" "with" |
| @@ -650,9 +649,9 @@ the {...} holes that appear within f-strings." | |||
| 650 | finally return (and result-valid result)))) | 649 | finally return (and result-valid result)))) |
| 651 | 650 | ||
| 652 | (defvar python-font-lock-keywords-level-1 | 651 | (defvar python-font-lock-keywords-level-1 |
| 653 | `((,(python-rx symbol-start "def" (1+ sp-bsnl) (group symbol-name)) | 652 | `((,(python-rx symbol-start "def" (1+ space) (group symbol-name)) |
| 654 | (1 font-lock-function-name-face)) | 653 | (1 font-lock-function-name-face)) |
| 655 | (,(python-rx symbol-start "class" (1+ sp-bsnl) (group symbol-name)) | 654 | (,(python-rx symbol-start "class" (1+ space) (group symbol-name)) |
| 656 | (1 font-lock-type-face))) | 655 | (1 font-lock-type-face))) |
| 657 | "Font lock keywords to use in `python-mode' for level 1 decoration. | 656 | "Font lock keywords to use in `python-mode' for level 1 decoration. |
| 658 | 657 | ||
| @@ -792,12 +791,12 @@ sign in chained assignment." | |||
| 792 | ;; [*a] = 5, 6 | 791 | ;; [*a] = 5, 6 |
| 793 | ;; are handled separately below | 792 | ;; are handled separately below |
| 794 | (,(python-font-lock-assignment-matcher | 793 | (,(python-font-lock-assignment-matcher |
| 795 | (python-rx (? (or "[" "(") (* sp-nl)) | 794 | (python-rx (? (or "[" "(") (* space)) |
| 796 | grouped-assignment-target (* sp-nl) ?, (* sp-nl) | 795 | grouped-assignment-target (* space) ?, (* space) |
| 797 | (* assignment-target (* sp-nl) ?, (* sp-nl)) | 796 | (* assignment-target (* space) ?, (* space)) |
| 798 | (? assignment-target (* sp-nl)) | 797 | (? assignment-target (* space)) |
| 799 | (? ?, (* sp-nl)) | 798 | (? ?, (* space)) |
| 800 | (? (or ")" "]") (* sp-bsnl)) | 799 | (? (or ")" "]") (* space)) |
| 801 | (group assignment-operator))) | 800 | (group assignment-operator))) |
| 802 | (1 font-lock-variable-name-face) | 801 | (1 font-lock-variable-name-face) |
| 803 | (2 'font-lock-operator-face) | 802 | (2 'font-lock-operator-face) |
| @@ -813,9 +812,9 @@ sign in chained assignment." | |||
| 813 | ;; c: Collection = {1, 2, 3} | 812 | ;; c: Collection = {1, 2, 3} |
| 814 | ;; d: Mapping[int, str] = {1: 'bar', 2: 'baz'} | 813 | ;; d: Mapping[int, str] = {1: 'bar', 2: 'baz'} |
| 815 | (,(python-font-lock-assignment-matcher | 814 | (,(python-font-lock-assignment-matcher |
| 816 | (python-rx (or line-start ?\;) (* sp-bsnl) | 815 | (python-rx (or line-start ?\;) (* space) |
| 817 | grouped-assignment-target (* sp-bsnl) | 816 | grouped-assignment-target (* space) |
| 818 | (? ?: (* sp-bsnl) (+ not-simple-operator) (* sp-bsnl)) | 817 | (? ?: (* space) (+ not-simple-operator) (* space)) |
| 819 | (group assignment-operator))) | 818 | (group assignment-operator))) |
| 820 | (1 font-lock-variable-name-face) | 819 | (1 font-lock-variable-name-face) |
| 821 | (2 'font-lock-operator-face)) | 820 | (2 'font-lock-operator-face)) |
| @@ -824,10 +823,10 @@ sign in chained assignment." | |||
| 824 | ;; [a] = 5, | 823 | ;; [a] = 5, |
| 825 | ;; [*a] = 5, 6 | 824 | ;; [*a] = 5, 6 |
| 826 | (,(python-font-lock-assignment-matcher | 825 | (,(python-font-lock-assignment-matcher |
| 827 | (python-rx (or line-start ?\; ?=) (* sp-bsnl) | 826 | (python-rx (or line-start ?\; ?=) (* space) |
| 828 | (or "[" "(") (* sp-nl) | 827 | (or "[" "(") (* space) |
| 829 | grouped-assignment-target (* sp-nl) | 828 | grouped-assignment-target (* space) |
| 830 | (or ")" "]") (* sp-bsnl) | 829 | (or ")" "]") (* space) |
| 831 | (group assignment-operator))) | 830 | (group assignment-operator))) |
| 832 | (1 font-lock-variable-name-face) | 831 | (1 font-lock-variable-name-face) |
| 833 | (2 'font-lock-operator-face)) | 832 | (2 'font-lock-operator-face)) |
| @@ -869,22 +868,6 @@ decorators, exceptions, and assignments.") | |||
| 869 | Which one will be chosen depends on the value of | 868 | Which one will be chosen depends on the value of |
| 870 | `font-lock-maximum-decoration'.") | 869 | `font-lock-maximum-decoration'.") |
| 871 | 870 | ||
| 872 | (defvar font-lock-beg) | ||
| 873 | (defvar font-lock-end) | ||
| 874 | (defun python-font-lock-extend-region () | ||
| 875 | "Extend font-lock region to statement boundaries." | ||
| 876 | (let ((beg font-lock-beg) | ||
| 877 | (end font-lock-end)) | ||
| 878 | (goto-char beg) | ||
| 879 | (python-nav-beginning-of-statement) | ||
| 880 | (beginning-of-line) | ||
| 881 | (when (< (point) beg) | ||
| 882 | (setq font-lock-beg (point))) | ||
| 883 | (goto-char end) | ||
| 884 | (python-nav-end-of-statement) | ||
| 885 | (when (< end (point)) | ||
| 886 | (setq font-lock-end (point))) | ||
| 887 | (or (/= beg font-lock-beg) (/= end font-lock-end)))) | ||
| 888 | 871 | ||
| 889 | (defconst python-syntax-propertize-function | 872 | (defconst python-syntax-propertize-function |
| 890 | (syntax-propertize-rules | 873 | (syntax-propertize-rules |
| @@ -6709,8 +6692,6 @@ implementations: `python-mode' and `python-ts-mode'." | |||
| 6709 | nil nil nil nil | 6692 | nil nil nil nil |
| 6710 | (font-lock-syntactic-face-function | 6693 | (font-lock-syntactic-face-function |
| 6711 | . python-font-lock-syntactic-face-function))) | 6694 | . python-font-lock-syntactic-face-function))) |
| 6712 | (add-hook 'font-lock-extend-region-functions | ||
| 6713 | #'python-font-lock-extend-region nil t) | ||
| 6714 | (setq-local syntax-propertize-function | 6695 | (setq-local syntax-propertize-function |
| 6715 | python-syntax-propertize-function) | 6696 | python-syntax-propertize-function) |
| 6716 | (setq-local imenu-create-index-function | 6697 | (setq-local imenu-create-index-function |