diff options
| -rw-r--r-- | lisp/progmodes/python.el | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 3eed67ab3a4..47e6fc0380d 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -990,6 +990,27 @@ With numeric ARG, just insert that many colons. With | |||
| 990 | (indent-line-to indentation))))))) | 990 | (indent-line-to indentation))))))) |
| 991 | (put 'python-indent-electric-colon 'delete-selection t) | 991 | (put 'python-indent-electric-colon 'delete-selection t) |
| 992 | 992 | ||
| 993 | (defun python-indent-post-self-insert-function () | ||
| 994 | "Adjust closing paren line indentation after a char is added. | ||
| 995 | This function is intended to be added to the | ||
| 996 | `post-self-insert-hook.' If a line renders a paren alone, after | ||
| 997 | adding a char before it, the line will be re-indented | ||
| 998 | automatically if needed." | ||
| 999 | (when (and (eq (char-before) last-command-event) | ||
| 1000 | (= (current-indentation) 0) | ||
| 1001 | (not (bolp)) | ||
| 1002 | (memq (char-after) '(?\) ?\] ?\}))) | ||
| 1003 | (let ((indentation (save-excursion | ||
| 1004 | ;; If after going to the beginning of line the point | ||
| 1005 | ;; is still inside a paren it's ok to do the trick | ||
| 1006 | (goto-char (line-beginning-position)) | ||
| 1007 | (when (python-info-ppss-context 'paren) | ||
| 1008 | (python-indent-calculate-indentation))))) | ||
| 1009 | (when (and indentation | ||
| 1010 | (< (current-indentation) indentation)) | ||
| 1011 | (save-excursion | ||
| 1012 | (indent-line-to indentation)))))) | ||
| 1013 | |||
| 993 | 1014 | ||
| 994 | ;;; Navigation | 1015 | ;;; Navigation |
| 995 | 1016 | ||
| @@ -2778,6 +2799,9 @@ if that value is non-nil." | |||
| 2778 | (add-hook 'completion-at-point-functions | 2799 | (add-hook 'completion-at-point-functions |
| 2779 | 'python-completion-complete-at-point nil 'local) | 2800 | 'python-completion-complete-at-point nil 'local) |
| 2780 | 2801 | ||
| 2802 | (add-hook 'post-self-insert-hook | ||
| 2803 | 'python-indent-post-self-insert-function nil 'local) | ||
| 2804 | |||
| 2781 | (setq imenu-create-index-function #'python-imenu-create-index) | 2805 | (setq imenu-create-index-function #'python-imenu-create-index) |
| 2782 | 2806 | ||
| 2783 | (set (make-local-variable 'add-log-current-defun-function) | 2807 | (set (make-local-variable 'add-log-current-defun-function) |