From: Fabián Ezequiel Gallina Date: Mon, 1 Sep 2014 22:51:46 +0000 (-0300) Subject: * lisp/progmodes/python.el (python-indent-post-self-insert-function): X-Git-Tag: emacs-24.3.94~65 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0e4c8f1856c46900f9530977e5ac9f83ca13bbfd;p=emacs.git * lisp/progmodes/python.el (python-indent-post-self-insert-function): Avoid electric colon at beginning-of-defun. * test/automated/python-tests.el: (python-indent-electric-colon-1): New test. (Bug#18228) --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 939553608ba..70e5ade2eee 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2014-09-01 Fabián Ezequiel Gallina + + * progmodes/python.el (python-indent-post-self-insert-function): + Avoid electric colon at beginning-of-defun. (Bug#18228) + 2014-09-01 Glenn Morris * tutorial.el (tutorial--display-changes): diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index a51cff8529e..740dfee5870 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1155,9 +1155,15 @@ the line will be re-indented automatically if needed." ((and (eq ?: last-command-event) (memq ?: electric-indent-chars) (not current-prefix-arg) + ;; Trigger electric colon only at end of line (eolp) + ;; Avoid re-indenting on extra colon (not (equal ?: (char-before (1- (point))))) - (not (python-syntax-comment-or-string-p))) + (not (python-syntax-comment-or-string-p)) + ;; Never re-indent at beginning of defun + (not (save-excursion + (python-nav-beginning-of-statement) + (python-info-looking-at-beginning-of-defun)))) (python-indent-line))))) diff --git a/test/ChangeLog b/test/ChangeLog index 90b30a4dd66..dcab604dbb1 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2014-09-01 Fabián Ezequiel Gallina + + * automated/python-tests.el: + (python-indent-electric-colon-1): New test. (Bug#18228) + 2014-08-18 Glenn Morris * automated/python-tests.el (python-shell-calculate-exec-path-2): diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index 47dfa4b64ed..39195fd7086 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el @@ -711,6 +711,20 @@ if a: (should (= (python-indent-calculate-indentation) 0)) (should (equal (python-indent-calculate-levels) '(0))))) +(ert-deftest python-indent-electric-colon-1 () + "Test indentation case from Bug#18228." + (python-tests-with-temp-buffer + " +def a(): + pass + +def b() +" + (python-tests-look-at "def b()") + (goto-char (line-end-position)) + (python-tests-self-insert ":") + (should (= (current-indentation) 0)))) + ;;; Navigation