diff options
author | Barry Warsaw <barry@python.org> | 1995-03-14 22:05:53 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1995-03-14 22:05:53 (GMT) |
commit | 3874a3d7ef85b9ea068d81aeb80e9c251ff1b561 (patch) | |
tree | 4348ee766a0e1bb969f38890e58122177bad1193 /Misc/python-mode.el | |
parent | 1c1fbf817e7eaf3f755fa498f3e5730d3bfb5396 (diff) | |
download | cpython-3874a3d7ef85b9ea068d81aeb80e9c251ff1b561.zip cpython-3874a3d7ef85b9ea068d81aeb80e9c251ff1b561.tar.gz cpython-3874a3d7ef85b9ea068d81aeb80e9c251ff1b561.tar.bz2 |
(py-outdent-p): new function
(py-electric-colon, py-indent-line): watch out for intervening blank
or comment lines.
Diffstat (limited to 'Misc/python-mode.el')
-rw-r--r-- | Misc/python-mode.el | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/Misc/python-mode.el b/Misc/python-mode.el index 0d5df7b..619f3f8 100644 --- a/Misc/python-mode.el +++ b/Misc/python-mode.el @@ -403,6 +403,19 @@ py-beep-if-tab-change\tring the bell if tab-width is changed" ;; electric characters +(defun py-outdent-p () + ;; returns non-nil if the current line should outdent one level + (save-excursion + (and (progn (back-to-indentation) + (looking-at py-outdent-re)) + (progn (backward-to-indentation 1) + (while (or (looking-at py-blank-or-comment-re) + (bobp)) + (backward-to-indentation 1)) + (not (looking-at py-no-outdent-re))) + ))) + + (defun py-electric-colon (arg) "Insert a colon. In certain cases the line is outdented appropriately. If a numeric @@ -414,13 +427,7 @@ argument is provided, that many colons are inserted non-electrically." (outdent 0) (indent (py-compute-indentation))) (if (and (not arg) - (progn - (back-to-indentation) - (looking-at py-outdent-re)) - (prog2 - (backward-to-indentation 1) - (not (looking-at py-no-outdent-re)) - (goto-char here)) + (py-outdent-p) (= indent (progn (forward-line -1) (py-compute-indentation))) @@ -650,11 +657,7 @@ needed so that only a single column position is deleted." (move-to-indentation-p (<= (current-column) ci)) (need (py-compute-indentation))) ;; see if we need to outdent - (if (save-excursion - (and (progn (back-to-indentation) - (looking-at py-outdent-re)) - (progn (backward-to-indentation 1) - (not (looking-at py-no-outdent-re))))) + (if (py-outdent-p) (setq need (- need py-indent-offset))) (if (/= ci need) (save-excursion |