From ffdb56c385f40e22031828cf08b7dd8482aea109 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Thu, 17 May 2012 00:03:04 -0300 Subject: [PATCH] Implemented python-indent-electric-colon --- lisp/progmodes/python.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 564638c1b58..76546aa9799 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -142,6 +142,7 @@ (define-key map (kbd "") 'python-indent-dedent-line) (define-key map "\C-c<" 'python-indent-shift-left) (define-key map "\C-c>" 'python-indent-shift-right) + (define-key map ":" 'python-indent-electric-colon) ;; Shell interaction (define-key map "\C-c\C-s" 'python-shell-send-string) (define-key map "\C-c\C-r" 'python-shell-send-region) @@ -786,6 +787,19 @@ lie." (setq count python-indent-offset)) (indent-rigidly start end count)) +;; Directly from Dave Love's python.el +(defun python-indent-electric-colon (arg) + "Insert a colon and maybe outdent the line if it is a statement like `else'. +With numeric ARG, just insert that many colons. With \\[universal-argument], +just insert a single colon." + (interactive "*P") + (self-insert-command (if (not (integerp arg)) 1 arg)) + (and (not arg) + (eolp) + (not (nth 8 (syntax-ppss))) + (save-excursion (python-indent-line)))) +(put 'python-indent-electric-colon 'delete-selection t) + ;;; Navigation -- 2.39.5