From: Fabián Ezequiel Gallina Date: Thu, 17 May 2012 03:03:08 +0000 (-0300) Subject: Enhancements to python-indent-electric-colon. X-Git-Tag: emacs-24.2.90~1199^2~586 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c43cd8b10f278195c59fa641dca7670811e7c146;p=emacs.git Enhancements to python-indent-electric-colon. Only de-indent line if it really closes a block. --- diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index ab711724ae7..79ef752c0f2 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -830,19 +830,24 @@ 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 (or (python-info-ppss-context 'string) - (python-info-ppss-context 'comment))) - (> (current-indentation) (python-indent-calculate-indentation)) - (save-excursion (python-indent-line)))) + (when (and (not arg) + (eolp) + (not (equal ?: (char-after (- (point-marker) 2)))) + (not (or (python-info-ppss-context 'string) + (python-info-ppss-context 'comment)))) + (let ((indentation (current-indentation)) + (calculated-indentation (python-indent-calculate-indentation))) + (when (> indentation calculated-indentation) + (save-excursion + (indent-line-to calculated-indentation) + (when (not (python-info-closing-block)) + (indent-line-to indentation))))))) (put 'python-indent-electric-colon 'delete-selection t)