aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorTom Gillespie2022-06-28 19:28:05 -0700
committerLars Ingebrigtsen2022-06-29 12:13:28 +0200
commitbf1dbdd87bb87eb9f18f7677d6d254b249b4c251 (patch)
treec3caa8db9e07c5325f19ce7f06b431b7a242f86f /lisp/progmodes/python.el
parente73dbcf26d9de114b3ba228edaf946418b476052 (diff)
downloademacs-bf1dbdd87bb87eb9f18f7677d6d254b249b4c251.tar.gz
emacs-bf1dbdd87bb87eb9f18f7677d6d254b249b4c251.zip
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)
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el11
1 files changed, 9 insertions, 2 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e0c937d7ce5..16cdf58611a 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1636,11 +1636,15 @@ of the statement."
1636 (while (and (or noend (goto-char (line-end-position))) 1636 (while (and (or noend (goto-char (line-end-position)))
1637 (not (eobp)) 1637 (not (eobp))
1638 (cond ((setq string-start (python-syntax-context 'string)) 1638 (cond ((setq string-start (python-syntax-context 'string))
1639 ;; The assertion can only fail if syntax table 1639 ;; The condition can be nil if syntax table
1640 ;; text properties and the `syntax-ppss' cache 1640 ;; text properties and the `syntax-ppss' cache
1641 ;; are somehow out of whack. This has been 1641 ;; are somehow out of whack. This has been
1642 ;; observed when using `syntax-ppss' during 1642 ;; observed when using `syntax-ppss' during
1643 ;; narrowing. 1643 ;; narrowing.
1644 ;; It can also fail in cases where the buffer is in
1645 ;; the process of being modified, e.g. when creating
1646 ;; a string with `electric-pair-mode' disabled such
1647 ;; that there can be an unmatched single quote
1644 (when (>= string-start last-string-end) 1648 (when (>= string-start last-string-end)
1645 (goto-char string-start) 1649 (goto-char string-start)
1646 (if (python-syntax-context 'paren) 1650 (if (python-syntax-context 'paren)
@@ -1723,7 +1727,10 @@ backward to previous statement."
1723 (while (and (forward-line 1) 1727 (while (and (forward-line 1)
1724 (not (eobp)) 1728 (not (eobp))
1725 (or (and (> (current-indentation) block-indentation) 1729 (or (and (> (current-indentation) block-indentation)
1726 (or (python-nav-end-of-statement) t)) 1730 (let ((start (point)))
1731 (python-nav-end-of-statement)
1732 ;; must move forward otherwise infinite loop
1733 (> (point) start)))
1727 (python-info-current-line-comment-p) 1734 (python-info-current-line-comment-p)
1728 (python-info-current-line-empty-p)))) 1735 (python-info-current-line-empty-p))))
1729 (python-util-forward-comment -1) 1736 (python-util-forward-comment -1)