diff Misc/python-mode.el @ 2537:6fcd0b022fa7 legacy-trunk

(py-outdent-re): new constant (py-electric-colon): use py-outdent-re instead of hardcoding (py-indent-line): look for py-outdent-re and outdent a level accordingly
author Barry Warsaw <barry@python.org>
date Tue, 14 Mar 1995 16:32:55 +0000
parents a14fc2d04c06
children 1a448dd84edc
line wrap: on
line diff
--- a/Misc/python-mode.el	Tue Mar 14 15:56:35 1995 +0000
+++ b/Misc/python-mode.el	Tue Mar 14 16:32:55 1995 +0000
@@ -290,6 +290,15 @@
 (defconst py-blank-or-comment-re "[ \t]*\\($\\|#\\)"
   "Regexp matching blank or comment lines.")
 
+(defconst py-outdent-re
+  (concat "\\(" (mapconcat 'identity
+			   '("else:"
+			     "except\\s +.*:"
+			     "finally:"
+			     "elif\\s +.*:")
+			   "\\|")
+	  "\\)")
+  "Regexp matching clauses to be outdented one level.")
 
 
 ;;;###autoload
@@ -374,8 +383,8 @@
   (let (this-indent)
     (if (and (not arg)
 	     (save-excursion
-	       (forward-word -1)
-	       (looking-at "\\(else\\|except\\|finally\\elif\\):"))
+	       (back-to-indentation)
+	       (looking-at py-outdent-re))
 	     (= (setq this-indent (py-compute-indentation))
 		(save-excursion
 		  (forward-line -1)
@@ -604,6 +613,11 @@
   (let* ((ci (current-indentation))
 	 (move-to-indentation-p (<= (current-column) ci))
 	 (need (py-compute-indentation)))
+    ;; watch for outdents
+    (if (save-excursion
+	  (back-to-indentation)
+	  (looking-at py-outdent-re))
+	(setq need (- need py-indent-offset)))
     (if (/= ci need)
 	(save-excursion
 	  (beginning-of-line)