diff options
| author | Fabián Ezequiel Gallina | 2013-03-25 22:55:11 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2013-03-25 22:55:11 -0300 |
| commit | c9886b39eb33e444662f79d9eb649603fda6839a (patch) | |
| tree | 13de29bfea76378d701f2a3b0a9bb9de75f73584 | |
| parent | 4430bd53998ea752ce99b1c25384cf7cfabcef88 (diff) | |
| download | emacs-c9886b39eb33e444662f79d9eb649603fda6839a.tar.gz emacs-c9886b39eb33e444662f79d9eb649603fda6839a.zip | |
Un-indent after "pass" and "return" statements
* lisp/progmodes/python.el (python-indent-block-enders): New var.
(python-indent-calculate-indentation): Use it.
* test/automated/python-tests.el
(python-indent-block-enders): New test.
(python-info-current-defun-2): Fix test.
Fixes: debbugs:13888
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 16 | ||||
| -rw-r--r-- | test/ChangeLog | 6 | ||||
| -rw-r--r-- | test/automated/python-tests.el | 30 |
4 files changed, 51 insertions, 7 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d843e0fa703..5783761a0b4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2013-03-26 Fabián Ezequiel Gallina <fabian@anue.biz> | ||
| 2 | |||
| 3 | Un-indent after "pass" and "return" statements (Bug#13888) | ||
| 4 | * progmodes/python.el (python-indent-block-enders): New var. | ||
| 5 | (python-indent-calculate-indentation): Use it. | ||
| 6 | |||
| 1 | 2013-03-25 Michael Albinus <michael.albinus@gmx.de> | 7 | 2013-03-25 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 8 | ||
| 3 | * net/tramp.el (tramp-drop-volume-letter): Make it an ordinary | 9 | * net/tramp.el (tramp-drop-volume-letter): Make it an ordinary |
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index c2739ce80a1..266d193cdda 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -628,6 +628,12 @@ It makes underscores and dots word constituent chars.") | |||
| 628 | These make `python-indent-calculate-indentation' subtract the value of | 628 | These make `python-indent-calculate-indentation' subtract the value of |
| 629 | `python-indent-offset'.") | 629 | `python-indent-offset'.") |
| 630 | 630 | ||
| 631 | (defvar python-indent-block-enders '("return" "pass") | ||
| 632 | "List of words that mark the end of a block. | ||
| 633 | These make `python-indent-calculate-indentation' subtract the | ||
| 634 | value of `python-indent-offset' when `python-indent-context' is | ||
| 635 | AFTER-LINE.") | ||
| 636 | |||
| 631 | (defun python-indent-guess-indent-offset () | 637 | (defun python-indent-guess-indent-offset () |
| 632 | "Guess and set `python-indent-offset' for the current buffer." | 638 | "Guess and set `python-indent-offset' for the current buffer." |
| 633 | (interactive) | 639 | (interactive) |
| @@ -753,9 +759,13 @@ START is the buffer position where the sexp starts." | |||
| 753 | (save-excursion | 759 | (save-excursion |
| 754 | (goto-char context-start) | 760 | (goto-char context-start) |
| 755 | (current-indentation)) | 761 | (current-indentation)) |
| 756 | (if (progn | 762 | (if (or (save-excursion |
| 757 | (back-to-indentation) | 763 | (back-to-indentation) |
| 758 | (looking-at (regexp-opt python-indent-dedenters))) | 764 | (looking-at (regexp-opt python-indent-dedenters))) |
| 765 | (save-excursion | ||
| 766 | (python-util-forward-comment -1) | ||
| 767 | (python-nav-beginning-of-statement) | ||
| 768 | (member (current-word) python-indent-block-enders))) | ||
| 759 | python-indent-offset | 769 | python-indent-offset |
| 760 | 0))) | 770 | 0))) |
| 761 | ;; When inside of a string, do nothing. just use the current | 771 | ;; When inside of a string, do nothing. just use the current |
diff --git a/test/ChangeLog b/test/ChangeLog index a2d657f57b5..d8b8fb661b5 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2013-03-26 Fabián Ezequiel Gallina <fabian@anue.biz> | ||
| 2 | |||
| 3 | * automated/python-tests.el | ||
| 4 | (python-indent-block-enders): New test. | ||
| 5 | (python-info-current-defun-2): Fix test. | ||
| 6 | |||
| 1 | 2013-03-11 Glenn Morris <rgm@gnu.org> | 7 | 2013-03-11 Glenn Morris <rgm@gnu.org> |
| 2 | 8 | ||
| 3 | * Version 24.3 released. | 9 | * Version 24.3 released. |
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index 6b380e75257..c90393ab8bb 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el | |||
| @@ -444,6 +444,28 @@ objects = Thing.objects.all() \\\\ | |||
| 444 | (should (eq (car (python-indent-context)) 'after-line)) | 444 | (should (eq (car (python-indent-context)) 'after-line)) |
| 445 | (should (= (python-indent-calculate-indentation) 0)))) | 445 | (should (= (python-indent-calculate-indentation) 0)))) |
| 446 | 446 | ||
| 447 | (ert-deftest python-indent-block-enders () | ||
| 448 | "Test `python-indent-block-enders' value honouring." | ||
| 449 | (python-tests-with-temp-buffer | ||
| 450 | " | ||
| 451 | Class foo(object): | ||
| 452 | |||
| 453 | def bar(self): | ||
| 454 | if self.baz: | ||
| 455 | return (1, | ||
| 456 | 2, | ||
| 457 | 3) | ||
| 458 | |||
| 459 | else: | ||
| 460 | pass | ||
| 461 | " | ||
| 462 | (python-tests-look-at "3)") | ||
| 463 | (forward-line 1) | ||
| 464 | (= (python-indent-calculate-indentation) 12) | ||
| 465 | (python-tests-look-at "pass") | ||
| 466 | (forward-line 1) | ||
| 467 | (= (python-indent-calculate-indentation) 8))) | ||
| 468 | |||
| 447 | 469 | ||
| 448 | ;;; Navigation | 470 | ;;; Navigation |
| 449 | 471 | ||
| @@ -1546,13 +1568,13 @@ class C(object): | |||
| 1546 | return [] | 1568 | return [] |
| 1547 | 1569 | ||
| 1548 | def b(): | 1570 | def b(): |
| 1549 | pass | 1571 | do_b() |
| 1550 | 1572 | ||
| 1551 | def a(): | 1573 | def a(): |
| 1552 | pass | 1574 | do_a() |
| 1553 | 1575 | ||
| 1554 | def c(self): | 1576 | def c(self): |
| 1555 | pass | 1577 | do_c() |
| 1556 | " | 1578 | " |
| 1557 | (forward-line 1) | 1579 | (forward-line 1) |
| 1558 | (should (string= "C" (python-info-current-defun))) | 1580 | (should (string= "C" (python-info-current-defun))) |
| @@ -1582,7 +1604,7 @@ class C(object): | |||
| 1582 | (python-tests-look-at "def c(self):") | 1604 | (python-tests-look-at "def c(self):") |
| 1583 | (should (string= "C.c" (python-info-current-defun))) | 1605 | (should (string= "C.c" (python-info-current-defun))) |
| 1584 | (should (string= "def C.c" (python-info-current-defun t))) | 1606 | (should (string= "def C.c" (python-info-current-defun t))) |
| 1585 | (python-tests-look-at "pass") | 1607 | (python-tests-look-at "do_c()") |
| 1586 | (should (string= "C.c" (python-info-current-defun))) | 1608 | (should (string= "C.c" (python-info-current-defun))) |
| 1587 | (should (string= "def C.c" (python-info-current-defun t))))) | 1609 | (should (string= "def C.c" (python-info-current-defun t))))) |
| 1588 | 1610 | ||