]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix electric indent bug in python-mode after dedenting colon
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 27 Dec 2018 15:52:07 +0000 (16:52 +0100)
committerEli Zaretskii <eliz@gnu.org>
Sat, 5 Jan 2019 09:02:02 +0000 (11:02 +0200)
* list/progmodes/python.el (python-indent-post-self-insert-function):
Use markers instead of positions when reindenting statement(s) after
inserting electric colon to avoid reindenting too many
statements (bug#22663).

* test/lisp/progmodes/python-tests.el (python-indent-electric-colon-2):
Improve test case to also verify the fix of bug#22663.

Copyright-paperwork-exempt: yes

lisp/progmodes/python.el
test/lisp/progmodes/python-tests.el

index ea34e1d9ab512950f1d155d260eb9ba6b8d4b525..71b2a94c071dfe80da7f55a868df6a4802827bdf 100644 (file)
@@ -1334,16 +1334,17 @@ the line will be re-indented automatically if needed."
            (not (equal ?: (char-before (1- (point)))))
            (not (python-syntax-comment-or-string-p)))
       ;; Just re-indent dedenters
-      (let ((dedenter-pos (python-info-dedenter-statement-p))
-            (current-pos (point)))
+      (let ((dedenter-pos (python-info-dedenter-statement-p)))
         (when dedenter-pos
-          (save-excursion
-            (goto-char dedenter-pos)
-            (python-indent-line)
-            (unless (= (line-number-at-pos dedenter-pos)
-                       (line-number-at-pos current-pos))
-              ;; Reindent region if this is a multiline statement
-              (python-indent-region dedenter-pos current-pos)))))))))
+          (let ((start (copy-marker dedenter-pos))
+                (end (point-marker)))
+            (save-excursion
+              (goto-char start)
+              (python-indent-line)
+              (unless (= (line-number-at-pos start)
+                         (line-number-at-pos end))
+                ;; Reindent region if this is a multiline statement
+                (python-indent-region start end))))))))))
 
 \f
 ;;; Mark
index 34a05194dfa2a156cd65c3e20cec5b45d4980897..94c846ecb16f46be701fcc56882326e054a76f3b 100644 (file)
@@ -1161,10 +1161,13 @@ def b()
 if do:
     something()
     else
+outside
 "
    (python-tests-look-at "else")
    (goto-char (line-end-position))
    (python-tests-self-insert ":")
+   (should (= (current-indentation) 0))
+   (python-tests-look-at "outside")
    (should (= (current-indentation) 0))))
 
 (ert-deftest python-indent-electric-colon-3 ()