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.  A fourth optional argument is
added to allow for explicit specification of the type of element
responsible for the execution.

* 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'.
This commit is contained in:
TEC 2022-09-17 17:39:16 +08:00
parent 392ccbbf5d
commit d1c6d02092
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
3 changed files with 33 additions and 10 deletions

View File

@ -715,7 +715,7 @@ a list with the following pattern:
; 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-type)
"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,29 @@ Optionally supply a value for INFO in the form returned by
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-TYPE is the type of the org element responsible for the
execution of the source block. If not provided then informed
guess will be made."
(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))))
(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)))
(executor-type
(or executor-type
;; If `executor-type' is unset, then we will make an
;; informed guess.
(pcase (char-after org-babel-current-src-block-location)
(?s 'inline-src-block)
(?c 'inline-babel-call)
(?# (pcase (char-after (+ 2 org-babel-current-src-block-location))
(?b 'src-block)
(?c 'call-block)
(_ 'unknown)))
(_ '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 +792,14 @@ block."
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-type
('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)

View File

@ -78,9 +78,10 @@ should not be inherited from a source block.")
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)

View File

@ -17297,7 +17297,7 @@ This command does many different things, depending on context:
"`\\[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