* 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
+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
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)
(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
+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.
(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
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)))
(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)))))