Subject: patch for python indentation

From: Aaron Ecay <[email-masked]>
Date: Wed, 06 Mar 2013 02:14:48 -0500

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.

>From f695ce5ade65d3be0c34ec74443bb65f8cfa688b Mon Sep 17 00:00:00 2001
From: Aaron Ecay <[email-masked]>
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  <[email-masked]>
+
+	* progmodes/python.el (python-indent-calculate-indentation):
+	Unindent after a return or pass keyword on the previous line.
+
 2013-03-05  Michael Albinus  <[email-masked]>
 
 	* 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