aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el27
1 files changed, 17 insertions, 10 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 47e6fc0380d..e549c477233 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -869,15 +869,7 @@ to (`nth' `python-indent-current-level' `python-indent-levels')"
869 (beginning-of-line) 869 (beginning-of-line)
870 (delete-horizontal-space) 870 (delete-horizontal-space)
871 (indent-to (nth python-indent-current-level python-indent-levels)) 871 (indent-to (nth python-indent-current-level python-indent-levels))
872 (save-restriction 872 (python-info-closing-block-message))
873 (widen)
874 (let ((closing-block-point (python-info-closing-block)))
875 (when closing-block-point
876 (message "Closes %s" (buffer-substring
877 closing-block-point
878 (save-excursion
879 (goto-char closing-block-point)
880 (line-end-position))))))))
881 873
882(defun python-indent-line-function () 874(defun python-indent-line-function ()
883 "`indent-line-function' for Python mode. 875 "`indent-line-function' for Python mode.
@@ -983,10 +975,11 @@ With numeric ARG, just insert that many colons. With
983 (python-info-ppss-context 'comment)))) 975 (python-info-ppss-context 'comment))))
984 (let ((indentation (current-indentation)) 976 (let ((indentation (current-indentation))
985 (calculated-indentation (python-indent-calculate-indentation))) 977 (calculated-indentation (python-indent-calculate-indentation)))
978 (python-info-closing-block-message)
986 (when (> indentation calculated-indentation) 979 (when (> indentation calculated-indentation)
987 (save-excursion 980 (save-excursion
988 (indent-line-to calculated-indentation) 981 (indent-line-to calculated-indentation)
989 (when (not (python-info-closing-block)) 982 (when (not (python-info-closing-block-message))
990 (indent-line-to indentation))))))) 983 (indent-line-to indentation)))))))
991(put 'python-indent-electric-colon 'delete-selection t) 984(put 'python-indent-electric-colon 'delete-selection t)
992 985
@@ -2600,6 +2593,20 @@ not inside a defun."
2600 (when (member (current-word) '("except" "else")) 2593 (when (member (current-word) '("except" "else"))
2601 (point-marker)))))))) 2594 (point-marker))))))))
2602 2595
2596(defun python-info-closing-block-message (&optional closing-block-point)
2597 "Message the contents of the block the current line closes.
2598With optional argument CLOSING-BLOCK-POINT use that instead of
2599recalculating it calling `python-info-closing-block'."
2600 (let ((point (or closing-block-point (python-info-closing-block))))
2601 (when point
2602 (save-restriction
2603 (widen)
2604 (message "Closes %s" (save-excursion
2605 (goto-char point)
2606 (back-to-indentation)
2607 (buffer-substring
2608 (point) (line-end-position))))))))
2609
2603(defun python-info-line-ends-backslash-p (&optional line-number) 2610(defun python-info-line-ends-backslash-p (&optional line-number)
2604 "Return non-nil if current line ends with backslash. 2611 "Return non-nil if current line ends with backslash.
2605With optional argument LINE-NUMBER, check that line instead." 2612With optional argument LINE-NUMBER, check that line instead."