summaryrefslogtreecommitdiffstats
path: root/Misc/python-mode.el
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1995-03-14 15:55:20 (GMT)
committerBarry Warsaw <barry@python.org>1995-03-14 15:55:20 (GMT)
commitb91b743476f3dfea4b33dfa47b93c740948dba76 (patch)
treeee47ec599ae939f64f305b66307c511a0dc3cd0b /Misc/python-mode.el
parent0c891ce61a2441e77521bf2f436e6d4545cc2158 (diff)
downloadcpython-b91b743476f3dfea4b33dfa47b93c740948dba76.zip
cpython-b91b743476f3dfea4b33dfa47b93c740948dba76.tar.gz
cpython-b91b743476f3dfea4b33dfa47b93c740948dba76.tar.bz2
(py-electric-colon): new command
Diffstat (limited to 'Misc/python-mode.el')
-rw-r--r--Misc/python-mode.el27
1 files changed, 26 insertions, 1 deletions
diff --git a/Misc/python-mode.el b/Misc/python-mode.el
index cdba45a..9e49ec6 100644
--- a/Misc/python-mode.el
+++ b/Misc/python-mode.el
@@ -222,7 +222,8 @@ Currently-active file is at the head of the list.")
(mapcar (function
(lambda (x)
(define-key py-mode-map (car x) (cdr x))))
- '(("\C-c\C-c" . py-execute-buffer)
+ '((":" . py-electric-colon)
+ ("\C-c\C-c" . py-execute-buffer)
("\C-c|" . py-execute-region)
("\C-c!" . py-shell)
("\177" . py-delete-char)
@@ -363,6 +364,30 @@ py-beep-if-tab-change\tring the bell if tab-width is changed"
(run-hooks 'py-mode-hook)))
+;; electric characters
+(defun py-electric-colon (arg)
+ "Insert a colon.
+In certain cases the line is outdented appropriately. If a numeric
+argument is provided, that many colons are inserted non-electrically."
+ (interactive "P")
+ (self-insert-command (prefix-numeric-value arg))
+ (let (this-indent)
+ (if (and (not arg)
+ (save-excursion
+ (forward-word -1)
+ (looking-at "\\(else\\|except\\|finally\\elif\\):"))
+ (= (setq this-indent (py-compute-indentation))
+ (save-excursion
+ (forward-line -1)
+ (py-compute-indentation)))
+ )
+ (save-excursion
+ (beginning-of-line)
+ (delete-horizontal-space)
+ (indent-to (- this-indent py-indent-offset)))
+ )))
+
+
;;; Functions that execute Python commands in a subprocess
(defun py-shell ()
"Start an interactive Python interpreter in another window.