emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master bf1dbdd87b 1/2: lisp/progmodes/python.el (python-nav-end-of-block


From: Lars Ingebrigtsen
Subject: master bf1dbdd87b 1/2: lisp/progmodes/python.el (python-nav-end-of-block): prevent infinite loop
Date: Wed, 29 Jun 2022 06:14:27 -0400 (EDT)

branch: master
commit bf1dbdd87bb87eb9f18f7677d6d254b249b4c251
Author: Tom Gillespie <tgbugs@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    lisp/progmodes/python.el (python-nav-end-of-block): prevent infinite loop
    
    lisp/progmodes/python.el (python-nav-end-of-block): Fix a bad
    assumption that python-nav-end-of-statement always makes forward
    progress by testing that it actually does. If this check is not made
    then it is possible for python-nav-end-of-block to enter an infinite
    loop. (bug#56271)
---
 lisp/progmodes/python.el | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e0c937d7ce..16cdf58611 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1636,11 +1636,15 @@ of the statement."
     (while (and (or noend (goto-char (line-end-position)))
                 (not (eobp))
                 (cond ((setq string-start (python-syntax-context 'string))
-                       ;; The assertion can only fail if syntax table
+                       ;; The condition can be nil if syntax table
                        ;; text properties and the `syntax-ppss' cache
                        ;; are somehow out of whack.  This has been
                        ;; observed when using `syntax-ppss' during
                        ;; narrowing.
+                       ;; It can also fail in cases where the buffer is in
+                       ;; the process of being modified, e.g. when creating
+                       ;; a string with `electric-pair-mode' disabled such
+                       ;; that there can be an unmatched single quote
                        (when (>= string-start last-string-end)
                          (goto-char string-start)
                          (if (python-syntax-context 'paren)
@@ -1723,7 +1727,10 @@ backward to previous statement."
       (while (and (forward-line 1)
                   (not (eobp))
                   (or (and (> (current-indentation) block-indentation)
-                           (or (python-nav-end-of-statement) t))
+                           (let ((start (point)))
+                             (python-nav-end-of-statement)
+                             ;; must move forward otherwise infinite loop
+                             (> (point) start)))
                       (python-info-current-line-comment-p)
                       (python-info-current-line-empty-p))))
       (python-util-forward-comment -1)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]