]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
(py-outdent-re): new constant
authorBarry Warsaw <barry@python.org>
Tue, 14 Mar 1995 16:32:55 +0000 (16:32 +0000)
committerBarry Warsaw <barry@python.org>
Tue, 14 Mar 1995 16:32:55 +0000 (16:32 +0000)
(py-electric-colon): use py-outdent-re instead of hardcoding

(py-indent-line): look for py-outdent-re and outdent a level
accordingly

Misc/python-mode.el

index 194caa56164761a82570e68fb09b11bad8511940..07b00f814f5d73b430c9565d2343c065de231271 100644 (file)
@@ -290,6 +290,15 @@ Currently-active file is at the head of the list.")
 (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.")
 
 \f
 ;;;###autoload
@@ -374,8 +383,8 @@ argument is provided, that many colons are inserted non-electrically."
   (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 @@ needed so that only a single column position is deleted."
   (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)