diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -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 | ||