]> git.eshelyaron.com Git - emacs.git/commitdiff
Un-indent after "pass" and "return" statements
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Tue, 26 Mar 2013 01:55:11 +0000 (22:55 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Tue, 26 Mar 2013 01:55:11 +0000 (22:55 -0300)
* 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
lisp/ChangeLog
lisp/progmodes/python.el
test/ChangeLog
test/automated/python-tests.el

index d843e0fa7034759df34f3baea6cc3c24cdf52c62..5783761a0b4063d75d755fa51b944274d1e0933a 100644 (file)
@@ -1,3 +1,9 @@
+2013-03-26  Fabián Ezequiel Gallina  <fabian@anue.biz>
+
+       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  <michael.albinus@gmx.de>
 
        * net/tramp.el (tramp-drop-volume-letter): Make it an ordinary
index c2739ce80a1eb57c2f77eb1be8f51e598060eb0f..266d193cddae27f680129931e97ed4b27f12bb92 100644 (file)
@@ -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
index a2d657f57b52a973b013df2d6805c3f9e089333d..d8b8fb661b595aaf63f5968350ca1efe637643cd 100644 (file)
@@ -1,3 +1,9 @@
+2013-03-26  Fabián Ezequiel Gallina  <fabian@anue.biz>
+
+       * automated/python-tests.el
+       (python-indent-block-enders): New test.
+       (python-info-current-defun-2): Fix test.
+
 2013-03-11  Glenn Morris  <rgm@gnu.org>
 
        * Version 24.3 released.
index 6b380e752571c58db13d49aeed9374f3036ae1de..c90393ab8bbd234390454613b975a154d819a899 100644 (file)
@@ -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)))
+
 \f
 ;;; 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)))))