bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#15812: 24.3.50; docstring starting with "return" confuses python-mod


From: Nathan Trapuzzano
Subject: bug#15812: 24.3.50; docstring starting with "return" confuses python-mode indentation
Date: Wed, 06 Nov 2013 09:23:23 -0500
User-agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3.50 (gnu/linux)

Friedrich Delgado <friedel@nomaden.org> writes:

> emacs -Q
> M-x python-mode
> M-x erase-buffer<RET>y<RET>y
> def foo():
>     "return stuff"
> <TAB>
>
> Expected behaviour: The cursor is placed under the first quotation
> mark (4 spaces indent)
>
> Actual behaviour: The cursor is placed at the beginning of the line.

Patch attached with regression test.  `python-nav-begining-of-statement'
puts point on the first non-whitespace character of the statement, so
it's safe to use `looking-at' here.

>From 49df44bf51b0a3b2a8c90180764aa37d5f3e95de Mon Sep 17 00:00:00 2001
From: Nathan Trapuzzano <nbtrap@nbtrap.com>
Date: Wed, 6 Nov 2013 08:11:43 -0500
Subject: [PATCH] Fix python-mode indentation bug #15812, and add regression
 test.

* progmodes/python.el (python-indent-calculate-indentation): When
determining indentation, don't treat "return", "pass", etc., as
operators when they are just string constituents.  (Bug#15812)

* automated/python-test.el (python-indent-block-enders)
(python-indent-block-enders-1, python-indent-block-enders-2):
Rename one test, add another.
---
 lisp/ChangeLog                 |  6 ++++++
 lisp/progmodes/python.el       |  2 +-
 test/ChangeLog                 |  6 ++++++
 test/automated/python-tests.el | 23 ++++++++++++++++++++++-
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d69ea7c..847a335 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2013-11-06  Nathan Trapuzzano  <nbtrap@nbtrap.com>
+
+       * progmodes/python.el (python-indent-calculate-indentation): When
+       determining indentation, don't treat "return", "pass", etc., as
+       operators when they are just string constituents.  (Bug#15812)
+
 2013-11-06  Eli Zaretskii  <eliz@gnu.org>
 
        * menu-bar.el (popup-menu, menu-bar-open): When displaying TTY
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 7a90f0b..4d4c504 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -775,7 +775,7 @@ START is the buffer position where the sexp starts."
                     (save-excursion
                       (python-util-forward-comment -1)
                       (python-nav-beginning-of-statement)
-                      (member (current-word) python-indent-block-enders)))
+                      (looking-at (regexp-opt python-indent-block-enders))))
                 python-indent-offset
               0)))
           ;; When inside of a string, do nothing. just use the current
diff --git a/test/ChangeLog b/test/ChangeLog
index e032af4..a0ad888 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,9 @@
+2013-11-06  Nathan Trapuzzano  <nbtrap@nbtrap.com>
+
+       * automated/python-test.el (python-indent-block-enders)
+       (python-indent-block-enders-1, python-indent-block-enders-2):
+       Rename one test, add another.
+
 2013-11-06  Michael Albinus  <michael.albinus@gmx.de>
 
        * automated/tramp-tests.el (tramp-test07-file-exists-p):
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index ef1c015..798e21f 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -447,7 +447,7 @@ objects = Thing.objects.all() \\\\
    (should (eq (car (python-indent-context)) 'after-line))
    (should (= (python-indent-calculate-indentation) 0))))
 
-(ert-deftest python-indent-block-enders ()
+(ert-deftest python-indent-block-enders-1 ()
   "Test `python-indent-block-enders' value honoring."
   (python-tests-with-temp-buffer
    "
@@ -469,6 +469,27 @@ Class foo(object):
    (forward-line 1)
    (should (= (python-indent-calculate-indentation) 8))))
 
+(ert-deftest python-indent-block-enders-2 ()
+  "Test `python-indent-block-enders' value honoring."
+  (python-tests-with-temp-buffer
+   "
+Class foo(object):
+    '''raise lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+
+    eiusmod tempor incididunt ut labore et dolore magna aliqua.
+    '''
+    def bar(self):
+        \"return (1, 2, 3).\"
+        if self.baz:
+            return (1,
+                    2,
+                    3)
+"
+   (python-tests-look-at "def")
+   (should (= (python-indent-calculate-indentation) 4))
+   (python-tests-look-at "if")
+   (should (= (python-indent-calculate-indentation) 8))))
+
 
 ;;; Navigation
 
-- 
1.8.4.2


reply via email to

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