unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Nathan Trapuzzano <nbtrap@nbtrap.com>
To: Friedrich Delgado <friedel@nomaden.org>
Cc: 15812@debbugs.gnu.org
Subject: bug#15812: 24.3.50; docstring starting with "return" confuses python-mode indentation
Date: Wed, 06 Nov 2013 09:23:23 -0500	[thread overview]
Message-ID: <87r4atpq1w.fsf@nbtrap.com> (raw)
In-Reply-To: <20131105152130.GA32322@dudelab.org> (Friedrich Delgado's message of "Tue, 5 Nov 2013 16:21:30 +0100")

[-- Attachment #1: Type: text/plain, Size: 501 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: python-mode.el.patch --]
[-- Type: text/x-diff, Size: 3791 bytes --]

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))))
+
 \f
 ;;; Navigation
 
-- 
1.8.4.2


  parent reply	other threads:[~2013-11-06 14:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-05 15:21 bug#15812: 24.3.50; docstring starting with "return" confuses python-mode indentation Friedrich Delgado
2013-11-06  7:16 ` Andreas Röhler
2013-11-06 11:51 ` Nathan Trapuzzano
2013-11-06 14:23 ` Nathan Trapuzzano [this message]
2013-11-07  8:36   ` Friedrich Delgado
2013-12-12  3:51 ` bug#15812: Fabián Ezequiel Gallina
2013-12-12  4:21   ` bug#15812: Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r4atpq1w.fsf@nbtrap.com \
    --to=nbtrap@nbtrap.com \
    --cc=15812@debbugs.gnu.org \
    --cc=friedel@nomaden.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).