Browse Source

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'.
TEC 2 years ago
parent
commit
d1c6d02092
3 changed files with 33 additions and 10 deletions
  1. 29 7
      lisp/ob-core.el
  2. 3 2
      lisp/ob-lob.el
  3. 1 1
      lisp/org.el

+ 29 - 7
lisp/ob-core.el

@@ -715,7 +715,7 @@ a list with the following pattern:
                 ; and `org-babel-read'
                 ; and `org-babel-read'
 
 
 ;;;###autoload
 ;;;###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.
   "Execute the current source code block and return the result.
 Insert the results of execution into the buffer.  Source code
 Insert the results of execution into the buffer.  Source code
 execution and the collection and formatting of results can be
 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
 Optionally supply a value for PARAMS which will be merged with
 the header arguments specified at the front of the source code
 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)
   (interactive)
   (let* ((org-babel-current-src-block-location
   (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
     ;; Merge PARAMS with INFO before considering source block
     ;; evaluation since both could disagree.
     ;; evaluation since both could disagree.
     (cl-callf org-babel-merge-params (nth 2 info) params)
     (cl-callf org-babel-merge-params (nth 2 info) params)
@@ -776,8 +792,14 @@ block."
 		 result)
 		 result)
 	    (unless (fboundp cmd)
 	    (unless (fboundp cmd)
 	      (error "No org-babel-execute function for %s!" lang))
 	      (error "No org-babel-execute function for %s!" lang))
-	    (message "executing %s code block%s..."
+	    (message "executing %s %s %s..."
 		     (capitalize lang)
 		     (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)))
 		     (let ((name (nth 4 info)))
 		       (if name
 		       (if name
                            (format "(%s)" name)
                            (format "(%s)" name)

+ 3 - 2
lisp/ob-lob.el

@@ -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
 Detect if this is context for a Library Of Babel source block and
 if so then run the appropriate source block from the Library."
 if so then run the appropriate source block from the Library."
   (interactive)
   (interactive)
-  (let ((info (org-babel-lob-get-info)))
+  (let* ((datum (org-element-context))
+         (info (org-babel-lob-get-info datum)))
     (when info
     (when info
-      (org-babel-execute-src-block nil info)
+      (org-babel-execute-src-block nil info nil (org-element-type datum))
       t)))
       t)))
 
 
 (defun org-babel-lob--src-info (ref)
 (defun org-babel-lob--src-info (ref)

+ 1 - 1
lisp/org.el

@@ -17297,7 +17297,7 @@ This command does many different things, depending on context:
 	       "`\\[org-ctrl-c-ctrl-c]' can do nothing useful here"))))
 	       "`\\[org-ctrl-c-ctrl-c]' can do nothing useful here"))))
 	((or `babel-call `inline-babel-call)
 	((or `babel-call `inline-babel-call)
 	 (let ((info (org-babel-lob-get-info context)))
 	 (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))
 	(`clock (org-clock-update-time-maybe))
 	(`dynamic-block
 	(`dynamic-block
 	 (save-excursion
 	 (save-excursion