diff options
| author | Fabián Ezequiel Gallina | 2012-05-17 00:03:08 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-05-17 00:03:08 -0300 |
| commit | c43cd8b10f278195c59fa641dca7670811e7c146 (patch) | |
| tree | 2207d4dd5cdedfb1ed354cffec1ce4641261b073 | |
| parent | 14a7849583a5d42aeb196226723cb9386aac2bba (diff) | |
| download | emacs-c43cd8b10f278195c59fa641dca7670811e7c146.tar.gz emacs-c43cd8b10f278195c59fa641dca7670811e7c146.zip | |
Enhancements to python-indent-electric-colon.
Only de-indent line if it really closes a block.
| -rw-r--r-- | lisp/progmodes/python.el | 19 |
1 files changed, 12 insertions, 7 deletions
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." | |||
| 830 | (setq count python-indent-offset)) | 830 | (setq count python-indent-offset)) |
| 831 | (indent-rigidly start end count))) | 831 | (indent-rigidly start end count))) |
| 832 | 832 | ||
| 833 | ;; Directly from Dave Love's python.el | ||
| 834 | (defun python-indent-electric-colon (arg) | 833 | (defun python-indent-electric-colon (arg) |
| 835 | "Insert a colon and maybe outdent the line if it is a statement like `else'. | 834 | "Insert a colon and maybe outdent the line if it is a statement like `else'. |
| 836 | With numeric ARG, just insert that many colons. With \\[universal-argument], | 835 | With numeric ARG, just insert that many colons. With \\[universal-argument], |
| 837 | just insert a single colon." | 836 | just insert a single colon." |
| 838 | (interactive "*P") | 837 | (interactive "*P") |
| 839 | (self-insert-command (if (not (integerp arg)) 1 arg)) | 838 | (self-insert-command (if (not (integerp arg)) 1 arg)) |
| 840 | (and (not arg) | 839 | (when (and (not arg) |
| 841 | (eolp) | 840 | (eolp) |
| 842 | (not (or (python-info-ppss-context 'string) | 841 | (not (equal ?: (char-after (- (point-marker) 2)))) |
| 843 | (python-info-ppss-context 'comment))) | 842 | (not (or (python-info-ppss-context 'string) |
| 844 | (> (current-indentation) (python-indent-calculate-indentation)) | 843 | (python-info-ppss-context 'comment)))) |
| 845 | (save-excursion (python-indent-line)))) | 844 | (let ((indentation (current-indentation)) |
| 845 | (calculated-indentation (python-indent-calculate-indentation))) | ||
| 846 | (when (> indentation calculated-indentation) | ||
| 847 | (save-excursion | ||
| 848 | (indent-line-to calculated-indentation) | ||
| 849 | (when (not (python-info-closing-block)) | ||
| 850 | (indent-line-to indentation))))))) | ||
| 846 | (put 'python-indent-electric-colon 'delete-selection t) | 851 | (put 'python-indent-electric-colon 'delete-selection t) |
| 847 | 852 | ||
| 848 | 853 | ||