summaryrefslogtreecommitdiff
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2018-12-27 16:52:07 +0100
committerEli Zaretskii <eliz@gnu.org>2019-01-05 11:02:02 +0200
commita3c79d44ccb4f6503d0a8b02230ff7a41db64ff8 (patch)
tree9ce59ca12af69c9daa60a8374b66c60f8a0710a7 /lisp/progmodes/python.el
parentf6eacc468b8539be482260fa569e7b5ece07f4a2 (diff)
downloademacs-a3c79d44ccb4f6503d0a8b02230ff7a41db64ff8.tar.gz
Fix electric indent bug in python-mode after dedenting colon
* 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
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el19
1 files changed, 10 insertions, 9 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index ea34e1d9ab5..71b2a94c071 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -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))))))))))
;;; Mark