diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 52 |
1 files changed, 17 insertions, 35 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 8c716ffb313..86bbf51dab7 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 |
| @@ -6171,7 +6154,8 @@ Optional argument REGEXP selects variables to clone and defaults | |||
| 6171 | to \"^python-\"." | 6154 | to \"^python-\"." |
| 6172 | (mapc | 6155 | (mapc |
| 6173 | (lambda (pair) | 6156 | (lambda (pair) |
| 6174 | (and (symbolp (car pair)) | 6157 | (and (consp pair) |
| 6158 | (symbolp (car pair)) | ||
| 6175 | (string-match (or regexp "^python-") | 6159 | (string-match (or regexp "^python-") |
| 6176 | (symbol-name (car pair))) | 6160 | (symbol-name (car pair))) |
| 6177 | (set (make-local-variable (car pair)) | 6161 | (set (make-local-variable (car pair)) |
| @@ -6769,8 +6753,6 @@ implementations: `python-mode' and `python-ts-mode'." | |||
| 6769 | nil nil nil nil | 6753 | nil nil nil nil |
| 6770 | (font-lock-syntactic-face-function | 6754 | (font-lock-syntactic-face-function |
| 6771 | . python-font-lock-syntactic-face-function))) | 6755 | . python-font-lock-syntactic-face-function))) |
| 6772 | (add-hook 'font-lock-extend-region-functions | ||
| 6773 | #'python-font-lock-extend-region nil t) | ||
| 6774 | (setq-local syntax-propertize-function | 6756 | (setq-local syntax-propertize-function |
| 6775 | python-syntax-propertize-function) | 6757 | python-syntax-propertize-function) |
| 6776 | (setq-local imenu-create-index-function | 6758 | (setq-local imenu-create-index-function |