]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/python.el (python-indent-post-self-insert-function):
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 1 Sep 2014 22:51:46 +0000 (19:51 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 1 Sep 2014 22:51:46 +0000 (19:51 -0300)
Avoid electric colon at beginning-of-defun.

* test/automated/python-tests.el:
(python-indent-electric-colon-1): New test.  (Bug#18228)

lisp/ChangeLog
lisp/progmodes/python.el
test/ChangeLog
test/automated/python-tests.el

index 939553608ba0462fbc5b0b4023c5335d76eb6cd0..70e5ade2eee215cca1006b7a04bf7e7fb2d4a9ac 100644 (file)
@@ -1,3 +1,8 @@
+2014-09-01  Fabián Ezequiel Gallina  <fgallina@gnu.org>
+
+       * progmodes/python.el (python-indent-post-self-insert-function):
+       Avoid electric colon at beginning-of-defun.  (Bug#18228)
+
 2014-09-01  Glenn Morris  <rgm@gnu.org>
 
        * tutorial.el (tutorial--display-changes):
index a51cff8529ee4beca14c8e41dd0fd33222a047c4..740dfee5870320436b844c2c6b57694e45dbf916 100644 (file)
@@ -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)))))
 
 \f
index 90b30a4dd6670ba0aa26568f72bac3951db9c89e..dcab604dbb10a5d45ebeb855c3ed5db2c1bc1c14 100644 (file)
@@ -1,3 +1,8 @@
+2014-09-01  Fabián Ezequiel Gallina  <fgallina@gnu.org>
+
+       * automated/python-tests.el:
+       (python-indent-electric-colon-1): New test.  (Bug#18228)
+
 2014-08-18  Glenn Morris  <rgm@gnu.org>
 
        * automated/python-tests.el (python-shell-calculate-exec-path-2):
index 47dfa4b64ed2f1fb18cfd9a3a782bc175e0c522d..39195fd7086e354807a84079eb410e3c7cb56f52 100644 (file)
@@ -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))))
+
 \f
 ;;; Navigation