]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
(py-electric-colon): new command
authorBarry Warsaw <barry@python.org>
Tue, 14 Mar 1995 15:55:20 +0000 (15:55 +0000)
committerBarry Warsaw <barry@python.org>
Tue, 14 Mar 1995 15:55:20 +0000 (15:55 +0000)
Misc/python-mode.el

index cdba45a38712f5d95a05385dfe4168090330f638..9e49ec6cd50a6bf83b876301e7d0764c692e2b5d 100644 (file)
@@ -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)
@@ -362,6 +363,30 @@ py-beep-if-tab-change\tring the bell if tab-width is changed"
       (run-hooks 'python-mode-hook)
     (run-hooks 'py-mode-hook)))
 
+\f
+;; 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)))
+      )))
+
 \f
 ;;; Functions that execute Python commands in a subprocess
 (defun py-shell ()