diff options
| author | Joel Rosdahl | 2018-12-27 16:52:07 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2019-01-05 11:02:02 +0200 |
| commit | a3c79d44ccb4f6503d0a8b02230ff7a41db64ff8 (patch) | |
| tree | 9ce59ca12af69c9daa60a8374b66c60f8a0710a7 | |
| parent | f6eacc468b8539be482260fa569e7b5ece07f4a2 (diff) | |
| download | emacs-a3c79d44ccb4f6503d0a8b02230ff7a41db64ff8.tar.gz emacs-a3c79d44ccb4f6503d0a8b02230ff7a41db64ff8.zip | |
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
| -rw-r--r-- | lisp/progmodes/python.el | 19 | ||||
| -rw-r--r-- | test/lisp/progmodes/python-tests.el | 3 |
2 files changed, 13 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." | |||
| 1334 | (not (equal ?: (char-before (1- (point))))) | 1334 | (not (equal ?: (char-before (1- (point))))) |
| 1335 | (not (python-syntax-comment-or-string-p))) | 1335 | (not (python-syntax-comment-or-string-p))) |
| 1336 | ;; Just re-indent dedenters | 1336 | ;; Just re-indent dedenters |
| 1337 | (let ((dedenter-pos (python-info-dedenter-statement-p)) | 1337 | (let ((dedenter-pos (python-info-dedenter-statement-p))) |
| 1338 | (current-pos (point))) | ||
| 1339 | (when dedenter-pos | 1338 | (when dedenter-pos |
| 1340 | (save-excursion | 1339 | (let ((start (copy-marker dedenter-pos)) |
| 1341 | (goto-char dedenter-pos) | 1340 | (end (point-marker))) |
| 1342 | (python-indent-line) | 1341 | (save-excursion |
| 1343 | (unless (= (line-number-at-pos dedenter-pos) | 1342 | (goto-char start) |
| 1344 | (line-number-at-pos current-pos)) | 1343 | (python-indent-line) |
| 1345 | ;; Reindent region if this is a multiline statement | 1344 | (unless (= (line-number-at-pos start) |
| 1346 | (python-indent-region dedenter-pos current-pos))))))))) | 1345 | (line-number-at-pos end)) |
| 1346 | ;; Reindent region if this is a multiline statement | ||
| 1347 | (python-indent-region start end)))))))))) | ||
| 1347 | 1348 | ||
| 1348 | 1349 | ||
| 1349 | ;;; Mark | 1350 | ;;; Mark |
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 34a05194dfa..94c846ecb16 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el | |||
| @@ -1161,10 +1161,13 @@ def b() | |||
| 1161 | if do: | 1161 | if do: |
| 1162 | something() | 1162 | something() |
| 1163 | else | 1163 | else |
| 1164 | outside | ||
| 1164 | " | 1165 | " |
| 1165 | (python-tests-look-at "else") | 1166 | (python-tests-look-at "else") |
| 1166 | (goto-char (line-end-position)) | 1167 | (goto-char (line-end-position)) |
| 1167 | (python-tests-self-insert ":") | 1168 | (python-tests-self-insert ":") |
| 1169 | (should (= (current-indentation) 0)) | ||
| 1170 | (python-tests-look-at "outside") | ||
| 1168 | (should (= (current-indentation) 0)))) | 1171 | (should (= (current-indentation) 0)))) |
| 1169 | 1172 | ||
| 1170 | (ert-deftest python-indent-electric-colon-3 () | 1173 | (ert-deftest python-indent-electric-colon-3 () |