1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-17 19:30:38 -08:00

Enhancements to python-indent-electric-colon.

Only de-indent line if it really closes a block.
This commit is contained in:
Fabián Ezequiel Gallina 2012-05-17 00:03:08 -03:00 committed by Fabián Ezequiel Gallina
parent 14a7849583
commit c43cd8b10f

View file

@ -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)