From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id CJQiN0bkLWOXawAAbAwnHQ (envelope-from ) for ; Fri, 23 Sep 2022 18:52:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id mNpCNkbkLWPH/QAAG6o9tA (envelope-from ) for ; Fri, 23 Sep 2022 18:52:22 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 13A1231458 for ; Fri, 23 Sep 2022 18:52:22 +0200 (CEST) Received: from localhost ([::1]:57156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obluX-0005Vd-7e for larch@yhetil.org; Fri, 23 Sep 2022 12:52:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oblte-0005UC-4u for emacs-orgmode@gnu.org; Fri, 23 Sep 2022 12:51:27 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:43193) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obltb-0006A6-RS for emacs-orgmode@gnu.org; Fri, 23 Sep 2022 12:51:25 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 8FB745C009E; Fri, 23 Sep 2022 12:51:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 23 Sep 2022 12:51:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tecosaur.net; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1663951881; x=1664038281; bh=s+vGFFqpTM Ej4jSjhGaJ0T8OUeLjk8svB8SKcAp8YL8=; b=B7ChPjy+qdOUYYcek5CxIo8+1H HACNcZ4isUS6MAtoX+K9yZzPvkHdVGiOBNklhjseHJP2GJOQDIh4H/UaVD4MNcKb bO4A4coMWjdWXI3g7vlw2DnQ49h7PoMdfkhNHOFbF9VtcoStsZ/Hdim57U5PvCTK CANvdKBbGiPDPZfbiJy1w46lWyfi3V1DKL1HmrhHmcXkOd+XhuXRl9/Tcr8LiK20 z4RtH9w0AP34s7H7dr2zCsoONl+d/xs1cnClAj1zrwWKf1g4VT34y+Fizv9Rt913 H5dMkcn8eG5qGiNI/XGI9iqkfQ7RGtM+Q8vejZTxZcKlbPjorG6rhHhcEbxg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1663951881; x=1664038281; bh=s+vGFFqpTMEj4jSjhGaJ0T8OUeLj k8svB8SKcAp8YL8=; b=ue70zxU4RQnkqYQQFtU6v1Pat5byQppPzvp5iuZGJPKn DyQnpTK/z3MMfPlSRU2Kr1hvI8b1TO2QYcUxSnaO/xn56dDTXaFg88/Paz4tr/66 ixBbo08YZfFPnfnJDFpyMY2Km+MjqIcJyj9UcdXVh57fT5dY2tZ8cOlAku4nSnFJ R74XRpnam2m6io/zFBTIa1MlgqPpcFVIbgAOJbxFTATSqfAhCyNdCZKi9QU8u3c8 +wUc8EKLphbiY5X3kHI/Ko4FQUrS/UbmDZ9zYKUGXFKZojWm9WxrczAN/0D/w/cL uAjAL6XnpHMayuNdfUFw/R/lbrwbr3Uz+nvf5YL5jw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeefiedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvvefuffhffggjkfggtgesmh dtreertderjeenucfhrhhomhepvfhimhhothhhhicuoehorhhgmhhouggvsehtvggtrdht vggtohhsrghurhdrnhgvtheqnecuggftrfgrthhtvghrnhepuefguddugfeuteeffeehle fhhfdujedvkeegtefgkeehudfgieekueeihfevleffnecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomhepohhrghhmohguvgesthgvtgdrthgvtghosh gruhhrrdhnvght X-ME-Proxy: Feedback-ID: iecf94634:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 23 Sep 2022 12:51:19 -0400 (EDT) From: Timothy To: emacs-orgmode@gnu.org Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] Babel evaluation: location and timing information (v2) Date: Sat, 24 Sep 2022 00:46:53 +0800 References: <87edw9z81n.fsf@tec.tecosaur.net> User-agent: mu4e 1.8.8; emacs 28.1.50 In-reply-to: <87edw9z81n.fsf@tec.tecosaur.net> Message-ID: <87mtaq8265.fsf@tec.tecosaur.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: none client-ip=66.111.4.29; envelope-from=orgmode@tec.tecosaur.net; helo=out5-smtp.messagingengine.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1663951942; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=s+vGFFqpTMEj4jSjhGaJ0T8OUeLjk8svB8SKcAp8YL8=; b=R0fqGbN4o8UnohvepwZsy3z2Z37WQH/BPpVbwJ8HPgC0onJxdVcY/h0FkP2rSGPvYGbCa/ HA1kGvVw/VB1QEQxorSBXFir3W0Co/lTvON9bkjEtbc0mlpRHGqb2/mn2mpDlrY27yism4 JS6BcBAGw/5fjAcxtL/PdKXRh6eeCSkgEnetYXFAVQofM/Uj6z5j+BSwJEDuLkOd+fWdKI QbIHbyiPrXfF+hAFme8pOPV4qamztCLfIpiLbApl46EfpV9xTz4naBjN0mjZ7HjAAFC08h W2qdTR4ZpUH4U/a9yr1uGVH92Z1BJyVtCOFnweJz1q/8j1hIOBualhSnOO2wVQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1663951942; a=rsa-sha256; cv=none; b=N74IMigO7lCa1eXH6xJWpbGEY4NIm1GE49ciwrjnAf4iR9xrj12q9dX9cWfC+oZahY2W+Q W8y1ktlTtUXUixa6lSdYKeGnX4BG6BbgN7mZmRpBkrXv2CSpAw7OOoWsqirBK72+Tvt2c0 ca8i1/26iF+Z2DmD3YhPUWOwQ1L4JSMuM0Pzc3/cc66N4g0ffXacL66E5oPJ7wtLxap7pn QzMjIAPLpY0l1J5icCUhQaAHys5IEZAOKXRHTU4t9Uufdcf8ORnQUMD+mfIeH6lxtJQXg7 zAzfHn5m8kO6EcRyhHQxYaH8ElwaorW5aKVgd2lJxJty/PYfqzHOQayDUa/RoA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=tecosaur.net header.s=fm1 header.b=B7ChPjy+; dkim=fail ("headers rsa verify failed") header.d=messagingengine.com header.s=fm2 header.b=ue70zxU4; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 1.25 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=tecosaur.net header.s=fm1 header.b=B7ChPjy+; dkim=fail ("headers rsa verify failed") header.d=messagingengine.com header.s=fm2 header.b=ue70zxU4; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 13A1231458 X-Spam-Score: 1.25 X-Migadu-Scanner: scn1.migadu.com X-TUID: 51YqpxjVlzzZ --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi All, Ihor raised a concern about the time needed to determine element type. This information is now passed on from other parts of Org, so there=E2=80=99s no= overhead from this any more. Since this also applies to inline types, I=E2=80=99ve switched to showing t= he point position instead of the line number. As a side effect, that renders concerns about the performance of `line-number-at-pos' moot. So, I think this set of patches should be good to go. Let me know if you can spot anything else that looks like it should be tweaked. All the best, Timothy --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-ob-core-Display-babel-execution-time.patch >From 81c5cf82cffd2b01fac39eaaf7a1a6ee58802e25 Mon Sep 17 00:00:00 2001 From: TEC 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 | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index c2f5eccfd..e6802e739 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -791,7 +791,7 @@ (defun org-babel-execute-src-block (&optional arg info params executor) (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..." @@ -806,7 +806,8 @@ (defun org-babel-execute-src-block (&optional arg info params executor) (if name (format "(%s)" name) (format "at point %d" (nth 5 info))))) - (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) @@ -849,7 +850,8 @@ (defun org-babel-execute-src-block (&optional arg info params executor) (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))))))) @@ -2260,7 +2262,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 @@ -2268,7 +2270,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: @@ -2573,11 +2576,18 @@ (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 + ;; Only show the time when something other than + ;; 0s will be shown, i.e. check if the time is at + ;; least half of the displayed precision. + (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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-ob-core-Display-type-of-element-babel-executes.patch >From 753d441ea9c190055566a53f88dc0d687ee72808 Mon Sep 17 00:00:00 2001 From: TEC 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-lob.el (org-babel-lob-execute-maybe): Pass the type of the execution triggering element to `org-babel-execute-src-block'. * lisp/org.el (org-ctrl-c-ctrl-c): When executing a babel call, pass the type of the execution triggering element to `org-babel-execute-src-block'. --- lisp/ob-core.el | 32 ++++++++++++++++++++++++++++---- lisp/ob-lob.el | 5 +++-- lisp/org.el | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 767586376..c2f5eccfd 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -715,7 +715,7 @@ (defvar *this*) ; Dynamically bound in `org-babel-execute-src-block' ; and `org-babel-read' ;;;###autoload -(defun org-babel-execute-src-block (&optional arg info params) +(defun org-babel-execute-src-block (&optional arg info params executor) "Execute the current source code block and return the result. Insert the results of execution into the buffer. Source code execution and the collection and formatting of results can be @@ -729,13 +729,31 @@ (defun org-babel-execute-src-block (&optional arg info params) Optionally supply a value for PARAMS which will be merged with the header arguments specified at the front of the source code -block." +block. + +EXECUTOR is the type of the org element responsible for the +execution of the source block. If not provided then this is +inferred to be a source block or inline source block, inspecting +the buffer content at the block location to determine which." (interactive) (let* ((org-babel-current-src-block-location (or org-babel-current-src-block-location (nth 5 info) (org-babel-where-is-src-block-head))) - (info (if info (copy-tree info) (org-babel-get-src-block-info)))) + (info (if info (copy-tree info) (org-babel-get-src-block-info))) + (executor + (or executor + ;; If `executor' is unset, then this cannot be a babel + ;; call (as `org-babel-lob-execute-maybe' provides the + ;; type of the execution triggering element) and so this + ;; must be an inline src block or src block. We can + ;; easily pick between the two by just looking at the + ;; first character of each case. In case something + ;; strange happens, this can be set to unknown. + (pcase (char-after org-babel-current-src-block-location) + (?s 'inline-src-block) + (?# 'src-block) + (_ 'unknown))))) ;; Merge PARAMS with INFO before considering source block ;; evaluation since both could disagree. (cl-callf org-babel-merge-params (nth 2 info) params) @@ -776,8 +794,14 @@ (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 executor + ('src-block "code block") + ('inline-src-block "inline code block") + ('babel-call "call") + ('inline-babel-call "inline call") + (e (symbol-name e))) (let ((name (nth 4 info))) (if name (format "(%s)" name) diff --git a/lisp/ob-lob.el b/lisp/ob-lob.el index 8da91bdaf..c6be8be80 100644 --- a/lisp/ob-lob.el +++ b/lisp/ob-lob.el @@ -78,9 +78,10 @@ (defun org-babel-lob-execute-maybe () Detect if this is context for a Library Of Babel source block and if so then run the appropriate source block from the Library." (interactive) - (let ((info (org-babel-lob-get-info))) + (let* ((datum (org-element-context)) + (info (org-babel-lob-get-info datum))) (when info - (org-babel-execute-src-block nil info) + (org-babel-execute-src-block nil info nil (org-element-type datum)) t))) (defun org-babel-lob--src-info (ref) diff --git a/lisp/org.el b/lisp/org.el index 142d5451b..a5d6bb931 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -17297,7 +17297,7 @@ (defun org-ctrl-c-ctrl-c (&optional arg) "`\\[org-ctrl-c-ctrl-c]' can do nothing useful here")))) ((or `babel-call `inline-babel-call) (let ((info (org-babel-lob-get-info context))) - (when info (org-babel-execute-src-block nil info)))) + (when info (org-babel-execute-src-block nil info nil type)))) (`clock (org-clock-update-time-maybe)) (`dynamic-block (save-excursion -- 2.37.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-core-Display-position-of-executed-babel-blocks.patch >From 5566c371f20228b0b33be54537c95f2d2fb6b191 Mon Sep 17 00:00:00 2001 From: TEC Date: Tue, 13 Sep 2022 18:55:06 +0800 Subject: [PATCH 1/3] ob-core: Display position of executed babel blocks * lisp/ob-core.el (org-babel-execute-src-block): When an unnamed babel block is executed, show the position of the block. This makes it easier to track the execution without having to name every block. ob-core: point * lisp/ob-core.el (org-babel-execute-src-block): --- lisp/ob-core.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 8a963fa8e..767586376 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -779,7 +779,9 @@ (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 "at point %d" (nth 5 info))))) (setq result (let ((r (funcall cmd body params))) (if (and (eq (cdr (assq :result-type params)) 'value) -- 2.37.1 --=-=-=--