]> git.eshelyaron.com Git - emacs.git/commitdiff
Enhanced closing block notification when line is indented or a colon is inserted.
authorFabián Ezequiel Gallina <fgallina@cuca>
Thu, 17 May 2012 03:03:42 +0000 (00:03 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Thu, 17 May 2012 03:03:42 +0000 (00:03 -0300)
`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

index 47e6fc0380d88f105fb1247096ca56e2b7fa0e69..e549c477233efae4ebb5d52c8e35f98c36f1b8b8 100644 (file)
@@ -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."