]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid hangs in python-mode with debug-on-error set
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 18 Apr 2022 11:17:32 +0000 (13:17 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 18 Apr 2022 11:19:57 +0000 (13:19 +0200)
* lisp/progmodes/python.el (python-nav-end-of-statement): Avoid
using cl-assert here, because this is called from the font-lock
machinery, and if debug-on-error is set here, we'll hang Emacs
(bug#54996).

Do not merge to master.

lisp/progmodes/python.el

index e6e8a37ad57be10bf61c9541be4e15814a5a069d..70828cb223a2688bc0dfc9e950d064c13bcf3430 100644 (file)
@@ -1620,23 +1620,20 @@ of the statement."
                        ;; are somehow out of whack.  This has been
                        ;; observed when using `syntax-ppss' during
                        ;; narrowing.
-                       (cl-assert (>= string-start last-string-end)
-                                  :show-args
-                                  "\
-Overlapping strings detected (start=%d, last-end=%d)")
-                       (goto-char string-start)
-                       (if (python-syntax-context 'paren)
-                           ;; Ended up inside a paren, roll again.
-                           (python-nav-end-of-statement t)
-                         ;; This is not inside a paren, move to the
-                         ;; end of this string.
-                         (goto-char (+ (point)
-                                       (python-syntax-count-quotes
-                                        (char-after (point)) (point))))
-                         (setq last-string-end
-                               (or (re-search-forward
-                                    (rx (syntax string-delimiter)) nil t)
-                                   (goto-char (point-max))))))
+                       (when (>= string-start last-string-end)
+                         (goto-char string-start)
+                         (if (python-syntax-context 'paren)
+                             ;; Ended up inside a paren, roll again.
+                             (python-nav-end-of-statement t)
+                           ;; This is not inside a paren, move to the
+                           ;; end of this string.
+                           (goto-char (+ (point)
+                                         (python-syntax-count-quotes
+                                          (char-after (point)) (point))))
+                           (setq last-string-end
+                                 (or (re-search-forward
+                                      (rx (syntax string-delimiter)) nil t)
+                                     (goto-char (point-max)))))))
                       ((python-syntax-context 'paren)
                        ;; The statement won't end before we've escaped
                        ;; at least one level of parenthesis.