From cd7ab092997474f7abba8bff2e0c5df888011ed7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Thu, 17 May 2012 00:03:42 -0300 Subject: [PATCH] Enhanced closing block notification when line is indented or a colon is inserted. `python-indent-line' and `python-indent-electric-colon' now uses the new `python-info-closing-block-message' function that takes care of messaging the block the current line is closing (if applicable). New Functions: + `python-info-closing-block-message' --- lisp/progmodes/python.el | 27 +++++++++++++++++---------- 1 file 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')" (beginning-of-line) (delete-horizontal-space) (indent-to (nth python-indent-current-level python-indent-levels)) - (save-restriction - (widen) - (let ((closing-block-point (python-info-closing-block))) - (when closing-block-point - (message "Closes %s" (buffer-substring - closing-block-point - (save-excursion - (goto-char closing-block-point) - (line-end-position)))))))) + (python-info-closing-block-message)) (defun python-indent-line-function () "`indent-line-function' for Python mode. @@ -983,10 +975,11 @@ With numeric ARG, just insert that many colons. With (python-info-ppss-context 'comment)))) (let ((indentation (current-indentation)) (calculated-indentation (python-indent-calculate-indentation))) + (python-info-closing-block-message) (when (> indentation calculated-indentation) (save-excursion (indent-line-to calculated-indentation) - (when (not (python-info-closing-block)) + (when (not (python-info-closing-block-message)) (indent-line-to indentation))))))) (put 'python-indent-electric-colon 'delete-selection t) @@ -2600,6 +2593,20 @@ not inside a defun." (when (member (current-word) '("except" "else")) (point-marker)))))))) +(defun python-info-closing-block-message (&optional closing-block-point) + "Message the contents of the block the current line closes. +With optional argument CLOSING-BLOCK-POINT use that instead of +recalculating it calling `python-info-closing-block'." + (let ((point (or closing-block-point (python-info-closing-block)))) + (when point + (save-restriction + (widen) + (message "Closes %s" (save-excursion + (goto-char point) + (back-to-indentation) + (buffer-substring + (point) (line-end-position)))))))) + (defun python-info-line-ends-backslash-p (&optional line-number) "Return non-nil if current line ends with backslash. With optional argument LINE-NUMBER, check that line instead." -- 2.39.2