GNU bug report logs - #13888
patch for python indentation

Previous Next

Package: emacs;

Reported by: Aaron Ecay <aaronecay <at> gmail.com>

Date: Wed, 6 Mar 2013 07:16:02 UTC

Severity: normal

Done: Fabian Ezequiel Gallina <fgallina <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 13888 in the body.
You can then email your comments to 13888 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#13888; Package emacs. (Wed, 06 Mar 2013 07:16:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Aaron Ecay <aaronecay <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 06 Mar 2013 07:16:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Aaron Ecay <aaronecay <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: patch for python indentation
Date: Wed, 06 Mar 2013 02:14:48 -0500
[Message part 1 (text/plain, inline)]
A previous version of emacs’ python-mode would unindent the line after a
pass or retrun keyword, which end the current block.  The current
version does not do so.  The attached patch restores this behavior.

[0001-Improve-python-indentation-after-return-or-pass.patch (text/x-patch, inline)]
From f695ce5ade65d3be0c34ec74443bb65f8cfa688b Mon Sep 17 00:00:00 2001
From: Aaron Ecay <aaronecay <at> gmail.com>
Date: Wed, 6 Mar 2013 01:33:48 -0500
Subject: [PATCH] Improve python indentation after return or pass

* progmodes/python.el (python-indent-calculate-indentation): Unindent
after a return or pass keyword on the previous line.
---
 lisp/ChangeLog           |  5 +++++
 lisp/progmodes/python.el | 12 +++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 88b9992..1cd9dc2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2013-03-06  Aaron Ecay  <aaronecay <at> gmail.com>
+
+	* progmodes/python.el (python-indent-calculate-indentation):
+	Unindent after a return or pass keyword on the previous line.
+
 2013-03-05  Michael Albinus  <michael.albinus <at> gmx.de>
 
 	* net/tramp-compat.el (tramp-compat-delete-directory): Implement
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index f0f67d0..6102490 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -763,9 +763,15 @@ START is the buffer position where the sexp starts."
             (save-excursion
               (goto-char context-start)
               (current-indentation))
-            (if (progn
-                  (back-to-indentation)
-                  (looking-at (regexp-opt python-indent-dedenters)))
+            (if (or (progn
+                      (back-to-indentation)
+                      (looking-at (regexp-opt python-indent-dedenters)))
+                    (progn
+                      (back-to-indentation)
+                      (skip-chars-backward (rx (or whitespace ?\n)))
+                      (back-to-indentation)
+                      (looking-at (rx (or "pass" "return")
+                                      (or " " "\n")))))
                 python-indent-offset
               0)))
           ;; When inside of a string, do nothing. just use the current
-- 
1.8.1.5

[Message part 3 (text/plain, inline)]
-- 
Aaron Ecay

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13888; Package emacs. (Sun, 17 Mar 2013 22:27:02 GMT) Full text and rfc822 format available.

Message #8 received at 13888 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Fabián Ezequiel Gallina <fabian <at> anue.biz>
Cc: 13888 <at> debbugs.gnu.org
Subject: Re: bug#13888: patch for python indentation
Date: Sun, 17 Mar 2013 18:25:04 -0400
> A previous version of emacs’ python-mode would unindent the line after a
> pass or retrun keyword, which end the current block.  The current
> version does not do so.  The attached patch restores this behavior.

Fabián, podrías mirar eso, por favor?


        Stefan


>> From f695ce5ade65d3be0c34ec74443bb65f8cfa688b Mon Sep 17 00:00:00 2001
> From: Aaron Ecay <aaronecay <at> gmail.com>
> Date: Wed, 6 Mar 2013 01:33:48 -0500
> Subject: [PATCH] Improve python indentation after return or pass

> * progmodes/python.el (python-indent-calculate-indentation): Unindent
> after a return or pass keyword on the previous line.
> ---
>  lisp/ChangeLog           |  5 +++++
>  lisp/progmodes/python.el | 12 +++++++++---
>  2 files changed, 14 insertions(+), 3 deletions(-)

> diff --git a/lisp/ChangeLog b/lisp/ChangeLog
> index 88b9992..1cd9dc2 100644
> --- a/lisp/ChangeLog
> +++ b/lisp/ChangeLog
> @@ -1,3 +1,8 @@
> +2013-03-06  Aaron Ecay  <aaronecay <at> gmail.com>
> +
> +	* progmodes/python.el (python-indent-calculate-indentation):
> +	Unindent after a return or pass keyword on the previous line.
> +
>  2013-03-05  Michael Albinus  <michael.albinus <at> gmx.de>
 
>  	* net/tramp-compat.el (tramp-compat-delete-directory): Implement
> diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
> index f0f67d0..6102490 100644
> --- a/lisp/progmodes/python.el
> +++ b/lisp/progmodes/python.el
> @@ -763,9 +763,15 @@ START is the buffer position where the sexp starts."
>              (save-excursion
>                (goto-char context-start)
>                (current-indentation))
> -            (if (progn
> -                  (back-to-indentation)
> -                  (looking-at (regexp-opt python-indent-dedenters)))
> +            (if (or (progn
> +                      (back-to-indentation)
> +                      (looking-at (regexp-opt python-indent-dedenters)))
> +                    (progn
> +                      (back-to-indentation)
> +                      (skip-chars-backward (rx (or whitespace ?\n)))
> +                      (back-to-indentation)
> +                      (looking-at (rx (or "pass" "return")
> +                                      (or " " "\n")))))
>                  python-indent-offset
>                0)))
>            ;; When inside of a string, do nothing. just use the current
> -- 
> 1.8.1.5



> -- 
> Aaron Ecay




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13888; Package emacs. (Sun, 31 Mar 2013 17:19:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Fabian Ezequiel Gallina <fgallina <at> gnu.org>:
Extra info received and forwarded to list. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 31 Mar 2013 17:19:01 GMT) Full text and rfc822 format available.

Message #13 received at 13888 <at> debbugs.gnu.org (full text, mbox):

From: Fabian Ezequiel Gallina <fgallina <at> gnu.org>
To: 13888 <at> debbugs.gnu.org
Subject: Re: bug#13888
Date: Mon, 25 Mar 2013 23:10:36 -0300
I just pushed a fix for this in revno 111338.


bug closed, send any further explanations to 13888 <at> debbugs.gnu.org and Aaron Ecay <aaronecay <at> gmail.com> Request was from Fabian Ezequiel Gallina <fgallina <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 31 Mar 2013 17:19:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 29 Apr 2013 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 7 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.