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
This commit is contained in:
parent
4430bd5399
commit
c9886b39eb
4 changed files with 51 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)))))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue