diff options
author | Barry Warsaw <barry@python.org> | 1995-03-14 16:32:55 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1995-03-14 16:32:55 (GMT) |
commit | 0012c1ec742555b99ad84b02d646361ef07ba42b (patch) | |
tree | b32c8f9ab12b783ea58af42a6c7e7e81caee8d51 | |
parent | b86bbada3799a7e2ec604d1d2518c074d2bacaee (diff) | |
download | cpython-0012c1ec742555b99ad84b02d646361ef07ba42b.zip cpython-0012c1ec742555b99ad84b02d646361ef07ba42b.tar.gz cpython-0012c1ec742555b99ad84b02d646361ef07ba42b.tar.bz2 |
(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
-rw-r--r-- | Misc/python-mode.el | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Misc/python-mode.el b/Misc/python-mode.el index 194caa5..07b00f8 100644 --- a/Misc/python-mode.el +++ b/Misc/python-mode.el @@ -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.") ;;;###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) |