[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 aa5158630e7 2/2: Use 'font-lock-extend-region-functions' in pyt
From: |
Eli Zaretskii |
Subject: |
emacs-29 aa5158630e7 2/2: Use 'font-lock-extend-region-functions' in python-mode |
Date: |
Fri, 26 May 2023 06:00:21 -0400 (EDT) |
branch: emacs-29
commit aa5158630e7113a67ae804d4253911028cb8f984
Author: kobarity <kobarity@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>
Use 'font-lock-extend-region-functions' in python-mode
* lisp/progmodes/python.el (python-font-lock-extend-region): Change
arguments and return value for 'font-lock-extend-region-functions'.
(python-mode): Change from
'font-lock-extend-after-change-region-function' to
'font-lock-extend-region-functions'. (Bug#63622)
---
lisp/progmodes/python.el | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 032a17c52ff..adaeacc2ec1 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -869,18 +869,22 @@ decorators, exceptions, and assignments.")
Which one will be chosen depends on the value of
`font-lock-maximum-decoration'.")
-(defun python-font-lock-extend-region (beg end _old-len)
- "Extend font-lock region given by BEG and END to statement boundaries."
- (save-excursion
- (save-match-data
- (goto-char beg)
- (python-nav-beginning-of-statement)
- (setq beg (point))
- (goto-char end)
- (python-nav-end-of-statement)
- (setq end (point))
- (cons beg end))))
-
+(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
@@ -6704,9 +6708,9 @@ implementations: `python-mode' and `python-ts-mode'."
`(,python-font-lock-keywords
nil nil nil nil
(font-lock-syntactic-face-function
- . python-font-lock-syntactic-face-function)
- (font-lock-extend-after-change-region-function
- . python-font-lock-extend-region)))
+ . 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