From: Noam Postavsky Date: Sun, 20 Sep 2020 08:46:16 +0000 (+0200) Subject: Fix slow python-mode inserts when there's a lot of strings X-Git-Tag: emacs-28.0.90~5994 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a68a0e69da11430401eb4868ee1bd1c88ae869d4;p=emacs.git Fix slow python-mode inserts when there's a lot of strings * lisp/progmodes/python.el (python-info-docstring-p): Doing more than two repetitions here doesn't improve indentation (bug#39598). --- diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index ccbcb081305..d2eb5f268bd 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5129,21 +5129,22 @@ point's current `syntax-ppss'." (>= 2 (let (last-backward-sexp-point) - (while (save-excursion - (python-nav-backward-sexp) - (setq backward-sexp-point (point)) - (and (= indentation (current-indentation)) - ;; Make sure we're always moving point. - ;; If we get stuck in the same position - ;; on consecutive loop iterations, - ;; bail out. - (prog1 (not (eql last-backward-sexp-point - backward-sexp-point)) - (setq last-backward-sexp-point - backward-sexp-point)) - (looking-at-p - (concat "[uU]?[rR]?" - (python-rx string-delimiter))))) + (while (and (<= counter 2) + (save-excursion + (python-nav-backward-sexp) + (setq backward-sexp-point (point)) + (and (= indentation (current-indentation)) + ;; Make sure we're always moving point. + ;; If we get stuck in the same position + ;; on consecutive loop iterations, + ;; bail out. + (prog1 (not (eql last-backward-sexp-point + backward-sexp-point)) + (setq last-backward-sexp-point + backward-sexp-point)) + (looking-at-p + (concat "[uU]?[rR]?" + (python-rx string-delimiter)))))) ;; Previous sexp was a string, restore point. (goto-char backward-sexp-point) (cl-incf counter))