diff options
| author | Fabián Ezequiel Gallina | 2014-12-22 02:24:42 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2014-12-22 02:24:42 -0300 |
| commit | 749813e9d4a844384e0450f6f7f88484b15e348a (patch) | |
| tree | 11dacc975324be1c08bf16c4430183fbb624f53b | |
| parent | 936d5e5bb63358da281188d9c8e9e21341df9444 (diff) | |
| download | emacs-749813e9d4a844384e0450f6f7f88484b15e348a.tar.gz emacs-749813e9d4a844384e0450f6f7f88484b15e348a.zip | |
python.el: Fix electric colon behavior
* lisp/progmodes/python.el (python-indent-post-self-insert-function):
Make colon to re-indent only for dedenters, handling
multiline-statements gracefully.
* test/automated/python-tests.el (python-indent-electric-colon-2)
(python-indent-electric-colon-3): New tests.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 18 | ||||
| -rw-r--r-- | test/ChangeLog | 5 | ||||
| -rw-r--r-- | test/automated/python-tests.el | 33 |
4 files changed, 56 insertions, 6 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e4f620ecb40..c00d6bcc690 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2014-12-22 Fabián Ezequiel Gallina <fgallina@gnu.org> | ||
| 2 | |||
| 3 | * progmodes/python.el (python-indent-post-self-insert-function): | ||
| 4 | Make colon to re-indent only for dedenters, handling | ||
| 5 | multiline-statements gracefully. | ||
| 6 | |||
| 1 | 2014-12-21 Michael Albinus <michael.albinus@gmx.de> | 7 | 2014-12-21 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 8 | ||
| 3 | * net/tramp.el (tramp-handle-insert-file-contents): | 9 | * net/tramp.el (tramp-handle-insert-file-contents): |
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 357ca5b56d8..6d3916c07a5 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1175,12 +1175,18 @@ the line will be re-indented automatically if needed." | |||
| 1175 | (eolp) | 1175 | (eolp) |
| 1176 | ;; Avoid re-indenting on extra colon | 1176 | ;; Avoid re-indenting on extra colon |
| 1177 | (not (equal ?: (char-before (1- (point))))) | 1177 | (not (equal ?: (char-before (1- (point))))) |
| 1178 | (not (python-syntax-comment-or-string-p)) | 1178 | (not (python-syntax-comment-or-string-p))) |
| 1179 | ;; Never re-indent at beginning of defun | 1179 | ;; Just re-indent dedenters |
| 1180 | (not (save-excursion | 1180 | (let ((dedenter-pos (python-info-dedenter-statement-p)) |
| 1181 | (python-nav-beginning-of-statement) | 1181 | (current-pos (point))) |
| 1182 | (python-info-looking-at-beginning-of-defun)))) | 1182 | (when dedenter-pos |
| 1183 | (python-indent-line))))) | 1183 | (save-excursion |
| 1184 | (goto-char dedenter-pos) | ||
| 1185 | (python-indent-line) | ||
| 1186 | (unless (= (line-number-at-pos dedenter-pos) | ||
| 1187 | (line-number-at-pos current-pos)) | ||
| 1188 | ;; Reindent region if this is a multiline statement | ||
| 1189 | (python-indent-region dedenter-pos current-pos))))))))) | ||
| 1184 | 1190 | ||
| 1185 | 1191 | ||
| 1186 | ;;; Navigation | 1192 | ;;; Navigation |
diff --git a/test/ChangeLog b/test/ChangeLog index a117834cd34..a91392d3fe7 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2014-12-22 Fabián Ezequiel Gallina <fgallina@gnu.org> | ||
| 2 | |||
| 3 | * automated/python-tests.el (python-indent-electric-colon-2) | ||
| 4 | (python-indent-electric-colon-3): New tests. | ||
| 5 | |||
| 1 | 2014-12-14 João Távora <joaotavora@gmail.com> | 6 | 2014-12-14 João Távora <joaotavora@gmail.com> |
| 2 | 7 | ||
| 3 | * automated/electric-tests.el (autowrapping-7): Tests for | 8 | * automated/electric-tests.el (autowrapping-7): Tests for |
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index f84ded8cad2..d1713ac1851 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el | |||
| @@ -740,6 +740,39 @@ def b() | |||
| 740 | (python-tests-self-insert ":") | 740 | (python-tests-self-insert ":") |
| 741 | (should (= (current-indentation) 0)))) | 741 | (should (= (current-indentation) 0)))) |
| 742 | 742 | ||
| 743 | (ert-deftest python-indent-electric-colon-2 () | ||
| 744 | "Test indentation case for dedenter." | ||
| 745 | (python-tests-with-temp-buffer | ||
| 746 | " | ||
| 747 | if do: | ||
| 748 | something() | ||
| 749 | else | ||
| 750 | " | ||
| 751 | (python-tests-look-at "else") | ||
| 752 | (goto-char (line-end-position)) | ||
| 753 | (python-tests-self-insert ":") | ||
| 754 | (should (= (current-indentation) 0)))) | ||
| 755 | |||
| 756 | (ert-deftest python-indent-electric-colon-3 () | ||
| 757 | "Test indentation case for multi-line dedenter." | ||
| 758 | (python-tests-with-temp-buffer | ||
| 759 | " | ||
| 760 | if do: | ||
| 761 | something() | ||
| 762 | elif (this | ||
| 763 | and | ||
| 764 | that) | ||
| 765 | " | ||
| 766 | (python-tests-look-at "that)") | ||
| 767 | (goto-char (line-end-position)) | ||
| 768 | (python-tests-self-insert ":") | ||
| 769 | (python-tests-look-at "elif" -1) | ||
| 770 | (should (= (current-indentation) 0)) | ||
| 771 | (python-tests-look-at "and") | ||
| 772 | (should (= (current-indentation) 6)) | ||
| 773 | (python-tests-look-at "that)") | ||
| 774 | (should (= (current-indentation) 6)))) | ||
| 775 | |||
| 743 | (ert-deftest python-indent-region-1 () | 776 | (ert-deftest python-indent-region-1 () |
| 744 | "Test indentation case from Bug#18843." | 777 | "Test indentation case from Bug#18843." |
| 745 | (let ((contents " | 778 | (let ((contents " |