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