From: Fabián Ezequiel Gallina Date: Tue, 26 Mar 2013 01:55:11 +0000 (-0300) Subject: Un-indent after "pass" and "return" statements X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1943^2~30 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c9886b39eb33e444662f79d9eb649603fda6839a;p=emacs.git 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 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d843e0fa703..5783761a0b4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-03-26 Fabián Ezequiel Gallina + + Un-indent after "pass" and "return" statements (Bug#13888) + * progmodes/python.el (python-indent-block-enders): New var. + (python-indent-calculate-indentation): Use it. + 2013-03-25 Michael Albinus * 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.") These make `python-indent-calculate-indentation' subtract the value of `python-indent-offset'.") +(defvar python-indent-block-enders '("return" "pass") + "List of words that mark the end of a block. +These make `python-indent-calculate-indentation' subtract the +value of `python-indent-offset' when `python-indent-context' is +AFTER-LINE.") + (defun python-indent-guess-indent-offset () "Guess and set `python-indent-offset' for the current buffer." (interactive) @@ -753,9 +759,13 @@ START is the buffer position where the sexp starts." (save-excursion (goto-char context-start) (current-indentation)) - (if (progn - (back-to-indentation) - (looking-at (regexp-opt python-indent-dedenters))) + (if (or (save-excursion + (back-to-indentation) + (looking-at (regexp-opt python-indent-dedenters))) + (save-excursion + (python-util-forward-comment -1) + (python-nav-beginning-of-statement) + (member (current-word) python-indent-block-enders))) python-indent-offset 0))) ;; 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 @@ +2013-03-26 Fabián Ezequiel Gallina + + * automated/python-tests.el + (python-indent-block-enders): New test. + (python-info-current-defun-2): Fix test. + 2013-03-11 Glenn Morris * 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() \\\\ (should (eq (car (python-indent-context)) 'after-line)) (should (= (python-indent-calculate-indentation) 0)))) +(ert-deftest python-indent-block-enders () + "Test `python-indent-block-enders' value honouring." + (python-tests-with-temp-buffer + " +Class foo(object): + + def bar(self): + if self.baz: + return (1, + 2, + 3) + + else: + pass +" + (python-tests-look-at "3)") + (forward-line 1) + (= (python-indent-calculate-indentation) 12) + (python-tests-look-at "pass") + (forward-line 1) + (= (python-indent-calculate-indentation) 8))) + ;;; Navigation @@ -1546,13 +1568,13 @@ class C(object): return [] def b(): - pass + do_b() def a(): - pass + do_a() def c(self): - pass + do_c() " (forward-line 1) (should (string= "C" (python-info-current-defun))) @@ -1582,7 +1604,7 @@ class C(object): (python-tests-look-at "def c(self):") (should (string= "C.c" (python-info-current-defun))) (should (string= "def C.c" (python-info-current-defun t))) - (python-tests-look-at "pass") + (python-tests-look-at "do_c()") (should (string= "C.c" (python-info-current-defun))) (should (string= "def C.c" (python-info-current-defun t)))))