emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r115497: * lisp/progmodes/python.el (python-indent-c


From: Fabián Ezequiel Gallina
Subject: [Emacs-diffs] trunk r115497: * lisp/progmodes/python.el (python-indent-calculate-indentation): Fix
Date: Thu, 12 Dec 2013 23:32:31 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 115497
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/15731
committer: Fabián Ezequiel Gallina <address@hidden>
branch nick: trunk
timestamp: Thu 2013-12-12 20:32:05 -0300
message:
  * lisp/progmodes/python.el (python-indent-calculate-indentation): Fix
  de-denters cornercase.
  
  * test/automated/python-tests.el (python-indent-dedenters-2): New test.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/progmodes/python.el       python.el-20091113204419-o5vbwnq5f7feedwu-3008
  test/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-8588
  test/automated/python-tests.el 
pythontests.el-20130220195218-kqcioz3fssz9hwe1-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-12-12 19:47:11 +0000
+++ b/lisp/ChangeLog    2013-12-12 23:32:05 +0000
@@ -1,3 +1,8 @@
+2013-12-12  Fabián Ezequiel Gallina  <address@hidden>
+
+       * progmodes/python.el (python-indent-calculate-indentation): Fix
+       de-denters cornercase. (Bug#15731)
+
 2013-12-12  Stefan Monnier  <address@hidden>
 
        * emacs-lisp/nadvice.el: Add `depth' property to manage ordering.

=== modified file 'lisp/progmodes/python.el'
--- a/lisp/progmodes/python.el  2013-12-12 05:37:09 +0000
+++ b/lisp/progmodes/python.el  2013-12-12 23:32:05 +0000
@@ -780,19 +780,31 @@
           ;; indentation, in the case current line starts with a
           ;; `python-indent-dedenters' de-indent one level.
           (`after-line
-           (-
-            (save-excursion
-              (goto-char context-start)
-              (current-indentation))
-            (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)
-                      (looking-at (regexp-opt python-indent-block-enders))))
-                python-indent-offset
-              0)))
+           (let* ((pair (save-excursion
+                          (goto-char context-start)
+                          (cons
+                           (current-indentation)
+                           (python-info-beginning-of-block-p))))
+                  (context-indentation (car pair))
+                  (after-block-start-p (cdr pair))
+                  (adjustment
+                   (if (or (save-excursion
+                             (back-to-indentation)
+                             (and
+                              ;; De-indent only when dedenters are not
+                              ;; next to a block start. This allows
+                              ;; one-liner constructs such as:
+                              ;;     if condition: print "yay"
+                              ;;     else: print "wry"
+                              (not after-block-start-p)
+                              (looking-at (regexp-opt 
python-indent-dedenters))))
+                           (save-excursion
+                             (python-util-forward-comment -1)
+                             (python-nav-beginning-of-statement)
+                             (looking-at (regexp-opt 
python-indent-block-enders))))
+                       python-indent-offset
+                     0)))
+             (- context-indentation adjustment)))
           ;; When inside of a string, do nothing. just use the current
           ;; indentation.  XXX: perhaps it would be a good idea to
           ;; invoke standard text indentation here

=== modified file 'test/ChangeLog'
--- a/test/ChangeLog    2013-12-12 20:07:40 +0000
+++ b/test/ChangeLog    2013-12-12 23:32:05 +0000
@@ -1,5 +1,9 @@
 2013-12-12  Fabián Ezequiel Gallina  <address@hidden>
 
+       * automated/python-tests.el (python-indent-dedenters-2): New test.
+
+2013-12-12  Fabián Ezequiel Gallina  <address@hidden>
+
        * automated/python-tests.el (python-indent-after-comment-1)
        (python-indent-after-comment-2): New tests.
 

=== modified file 'test/automated/python-tests.el'
--- a/test/automated/python-tests.el    2013-12-12 05:37:09 +0000
+++ b/test/automated/python-tests.el    2013-12-12 23:32:05 +0000
@@ -458,6 +458,28 @@
    (should (eq (car (python-indent-context)) 'after-beginning-of-block))
    (should (= (python-indent-calculate-indentation) 12))))
 
+(ert-deftest python-indent-dedenters-2 ()
+  "Check one-liner block special case.."
+  (python-tests-with-temp-buffer
+   "
+cond = True
+if cond:
+
+    if cond: print 'True'
+else: print 'False'
+
+else:
+    return
+"
+   (python-tests-look-at "else: print 'False'")
+   ;; When a block has code after ":" it's just considered a simple
+   ;; line as that's a common thing to happen in one-liners.
+   (should (eq (car (python-indent-context)) 'after-line))
+   (should (= (python-indent-calculate-indentation) 4))
+   (python-tests-look-at "else:")
+   (should (eq (car (python-indent-context)) 'after-line))
+   (should (= (python-indent-calculate-indentation) 0))))
+
 (ert-deftest python-indent-after-backslash-1 ()
   "The most common case."
   (python-tests-with-temp-buffer


reply via email to

[Prev in Thread] Current Thread [Next in Thread]