]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix slow python-mode inserts when there's a lot of strings
authorNoam Postavsky <npostavs@gmail.com>
Sun, 20 Sep 2020 08:46:16 +0000 (10:46 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 20 Sep 2020 08:46:16 +0000 (10:46 +0200)
* lisp/progmodes/python.el (python-info-docstring-p): Doing more
than two repetitions here doesn't improve indentation (bug#39598).

lisp/progmodes/python.el

index ccbcb0813058b6dc1e152617d0f84fd81be6be17..d2eb5f268bdb9aeec8c3094d32e0d1a4ebea6b00 100644 (file)
@@ -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))