all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Babel evaluation: location and timing information
@ 2022-09-18  3:09 Timothy
  2022-09-19 12:28 ` Fraga, Eric
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Timothy @ 2022-09-18  3:09 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 875 bytes --]

Hi All,

This is a small set of patches to add a bit more information to the messages
emitted in the course of babel evaluation. Specifically about
⁃ What type of element is responsible for the evaluation (source block, babel call,
  inline source)
⁃ Where the element is (if no name is set)
⁃ How long evaluation took

For example, previously `C-c C-c' on a babel call would have produced a message
like this:
┌────
│ executing Emacs-Lisp code block...
│ Code block evaluation complete.
└────
and now this might look like so:
┌────
│ executing Emacs-Lisp call on line 143...
│ Code block evaluation complete (took 0.2s).
└────

I think this is a pretty sensible change, but feedback is always nice.

If there are no objections, I expect I’ll merge this in a few days.

All the best,
Timothy

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-core-Display-line-number-of-exec-babel-blocks.patch --]
[-- Type: text/x-patch, Size: 1258 bytes --]

From 5be372f8185aa8b482f63f182ee1cf252a777c3b Mon Sep 17 00:00:00 2001
From: TEC <git@tecosaur.net>
Date: Tue, 13 Sep 2022 18:55:06 +0800
Subject: [PATCH 1/3] ob-core: Display line number of exec babel blocks

* lisp/ob-core.el (org-babel-execute-src-block): When an unnamed babel
block is executed, show the line number of the block.

This makes it easier to track the execution without having to name every
block.
---
 lisp/ob-core.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 8a963fa8e..0a179f379 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -779,7 +779,11 @@ (defun org-babel-execute-src-block (&optional arg info params)
 	    (message "executing %s code block%s..."
 		     (capitalize lang)
 		     (let ((name (nth 4 info)))
-		       (if name (format " (%s)" name) "")))
+		       (if name
+                           (format "(%s)" name)
+                         (format "on line %d"
+                                 (line-number-at-pos
+                                  (or (nth 5 info) org-babel-current-src-block-location))))))
 	    (setq result
 		  (let ((r (funcall cmd body params)))
 		    (if (and (eq (cdr (assq :result-type params)) 'value)
-- 
2.37.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ob-core-Display-type-of-element-babel-executes.patch --]
[-- Type: text/x-patch, Size: 1228 bytes --]

From 8e55a3e90f4c7bcec796d450e05e953ce3871e81 Mon Sep 17 00:00:00 2001
From: TEC <git@tecosaur.net>
Date: Sat, 17 Sep 2022 17:39:16 +0800
Subject: [PATCH 2/3] ob-core: Display type of element babel executes

* lisp/ob-core.el (org-babel-execute-src-block): The babel execute
function is run on more than just source blocks, so it makes sense to
note the type of element being executed.
---
 lisp/ob-core.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 0a179f379..f95bd56e6 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -776,8 +776,12 @@ (defun org-babel-execute-src-block (&optional arg info params)
 		 result)
 	    (unless (fboundp cmd)
 	      (error "No org-babel-execute function for %s!" lang))
-	    (message "executing %s code block%s..."
+	    (message "executing %s %s %s..."
 		     (capitalize lang)
+                     (pcase (org-element-type (org-element-at-point))
+                       ('src-block "code block")
+                       ('babel-call "call")
+                       ('paragraph "inline code block"))
 		     (let ((name (nth 4 info)))
 		       (if name
                            (format "(%s)" name)
-- 
2.37.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-ob-core-Display-babel-execution-time.patch --]
[-- Type: text/x-patch, Size: 4087 bytes --]

From f661b72d7c4837f5fed4201e0c764d0e0c6b0993 Mon Sep 17 00:00:00 2001
From: TEC <git@tecosaur.net>
Date: Sat, 17 Sep 2022 17:53:01 +0800
Subject: [PATCH 3/3] ob-core: Display babel execution time

* lisp/ob-core.el (org-babel-execute-src-block,
org-babel-format-result): Record the babel execution time, and then
supplement the "Code block evaluation complete." (etc.) messages with
the execution time when >0.05s.
---
 lisp/ob-core.el | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index f95bd56e6..946b37595 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -773,7 +773,7 @@ (defun org-babel-execute-src-block (&optional arg info params)
 		       (make-directory d 'parents)
 		       d))))
 		 (cmd (intern (concat "org-babel-execute:" lang)))
-		 result)
+		 result exec-start-time)
 	    (unless (fboundp cmd)
 	      (error "No org-babel-execute function for %s!" lang))
 	    (message "executing %s %s %s..."
@@ -788,7 +788,8 @@ (defun org-babel-execute-src-block (&optional arg info params)
                          (format "on line %d"
                                  (line-number-at-pos
                                   (or (nth 5 info) org-babel-current-src-block-location))))))
-	    (setq result
+	    (setq exec-start-time (current-time)
+                  result
 		  (let ((r (funcall cmd body params)))
 		    (if (and (eq (cdr (assq :result-type params)) 'value)
 			     (or (member "vector" result-params)
@@ -831,7 +832,8 @@ (defun org-babel-execute-src-block (&optional arg info params)
 	      (if (member "none" result-params)
 		  (message "result silenced")
 	        (org-babel-insert-result
-	         result result-params info new-hash lang)))
+	         result result-params info new-hash lang
+                 (time-subtract (current-time) exec-start-time))))
 	    (run-hooks 'org-babel-after-execute-hook)
 	    result)))))))
 
@@ -2242,7 +2244,7 @@ (defun org-babel-format-result (result &optional sep)
       ;; scalar result
       (funcall echo-res result))))
 
-(defun org-babel-insert-result (result &optional result-params info hash lang)
+(defun org-babel-insert-result (result &optional result-params info hash lang exec-time)
   "Insert RESULT into the current buffer.
 
 By default RESULT is inserted after the end of the current source
@@ -2250,7 +2252,8 @@ (defun org-babel-insert-result (result &optional result-params info hash lang)
 wrapped inside a `results' macro and placed on the same line as
 the inline source block.  The macro is stripped upon export.
 Multiline and non-scalar RESULTS from inline source blocks are
-not allowed.  With optional argument RESULT-PARAMS controls
+not allowed.  When EXEC-TIME is provided it may be included in a
+generated message.  With optional argument RESULT-PARAMS controls
 insertion of results in the Org mode file.  RESULT-PARAMS can
 take the following values:
 
@@ -2555,11 +2558,15 @@ (defun org-babel-insert-result (result &optional result-params info hash lang)
 			   (not (and (listp result)
 				     (member "append" result-params))))
 		  (indent-rigidly beg end indent))
-		(if (null result)
-		    (if (member "value" result-params)
-			(message "Code block returned no value.")
-		      (message "Code block produced no output."))
-		  (message "Code block evaluation complete.")))
+                (let ((time-info
+                       (if (and exec-time (> (float-time exec-time) 0.05))
+                           (format " (took %.1fs)" (float-time exec-time))
+                         "")))
+                  (if (null result)
+                      (if (member "value" result-params)
+                          (message "Code block returned no value%s." time-info)
+                        (message "Code block produced no output%s." time-info))
+                    (message "Code block evaluation complete%s." time-info))))
 	    (set-marker end nil)
 	    (when outside-scope (narrow-to-region visible-beg visible-end))
 	    (set-marker visible-beg nil)
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-09-24  9:15 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-18  3:09 [PATCH] Babel evaluation: location and timing information Timothy
2022-09-19 12:28 ` Fraga, Eric
2022-09-19 14:52 ` Max Nikulin
2022-09-22  7:03   ` Timothy
2022-09-22 12:15     ` Max Nikulin
2022-09-23  2:22       ` Ihor Radchenko
2022-09-23 16:21         ` line-number-at-pos performance and cache-long-scans Max Nikulin
2022-09-20  8:29 ` [PATCH] Babel evaluation: location and timing information Ihor Radchenko
2022-09-22  7:05   ` Timothy
2022-09-23  2:27     ` Ihor Radchenko
2022-09-23 16:46 ` [PATCH] Babel evaluation: location and timing information (v2) Timothy
2022-09-24  3:11   ` Ihor Radchenko
2022-09-24  9:12     ` Timothy

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.