org-babel: Reduce verbosity when running in batch mode

* lisp/ob-C.el (org-babel-C-header-to-C):
* lisp/ob-awk.el (org-babel-execute:awk):
* lisp/ob-core.el (org-babel-execute-src-block):
(org-babel-insert-result):
* lisp/ob-ditaa.el (org-babel-execute:ditaa):
* lisp/ob-gnuplot.el (org-babel-execute:gnuplot):
(org-babel-prep-session:gnuplot):
* lisp/ob-groovy.el (org-babel-execute:groovy):
* lisp/ob-maxima.el (org-babel-execute:maxima):
* lisp/ob-screen.el (org-babel-execute:screen):
* lisp/ob-sed.el (org-babel-execute:sed): Suppress progress messages
when running noninteractively (batch export, for example).  This
change follows the existing behavior of `org-babel-exp-src-block'.

Reported-by: Eli Zaretskii <eliz@gnu.org>
Link: https://yhetil.org/emacs-devel/868qzd9hjg.fsf@gnu.org/
This commit is contained in:
Ihor Radchenko 2024-06-13 15:16:54 +02:00
parent 84945f9de0
commit e4902995a0
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
9 changed files with 43 additions and 39 deletions

View File

@ -482,7 +482,7 @@ int get_column_num (int nbcols, const char** header, const char* column)
(defun org-babel-C-header-to-C (head type)
"Convert an elisp list of header table into a C or D vector
specifying a variable with the name of the table."
(message "%S" type)
(unless noninteractive (message "%S" type))
(let ((table (car head))
(headers (cdr head))
(typename (pcase type

View File

@ -61,7 +61,7 @@
"Execute a block of Awk code BODY with org-babel.
PARAMS is a plist of src block parameters .
This function is called by `org-babel-execute-src-block'."
(message "Executing Awk source code block")
(unless noninteractive (message "Executing Awk source code block"))
(let* ((result-params (cdr (assq :result-params params)))
(cmd-line (cdr (assq :cmd-line params)))
(in-file (cdr (assq :in-file params)))

View File

@ -855,8 +855,9 @@ guess will be made."
(forward-line)
(skip-chars-forward " \t")
(let ((result (org-babel-read-result)))
(message (format "Cached: %s"
(replace-regexp-in-string "%" "%%" (format "%S" result))))
(unless noninteractive
(message (format "Cached: %s"
(replace-regexp-in-string "%" "%%" (format "%S" result)))))
result)))
((org-babel-confirm-evaluate info)
(let* ((lang (nth 0 info))
@ -879,18 +880,19 @@ guess will be made."
result exec-start-time)
(unless (fboundp cmd)
(error "No org-babel-execute function for %s!" lang))
(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)
(format "at position %S" (nth 5 info)))))
(unless noninteractive
(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)
(format "at position %S" (nth 5 info))))))
(setq exec-start-time (current-time)
result
(let ((r
@ -2760,20 +2762,21 @@ INFO may provide the values of these header arguments (in the
;; In this case `table-align' does the work
;; for us.
(not (and (listp result)
(member "append" result-params))))
(member "append" result-params))))
(indent-rigidly beg end indent))
(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))))
(unless noninteractive
(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)))))
(when end (set-marker end nil))
(when outside-scope (narrow-to-region visible-beg visible-end))
(set-marker visible-beg nil)

View File

@ -113,8 +113,9 @@ This function is called by `org-babel-execute-src-block'."
(unless (file-exists-p org-ditaa-jar-path)
(error "Could not find ditaa.jar at %s" org-ditaa-jar-path))
(with-temp-file in-file (insert body))
(message cmd) (shell-command cmd)
(when pdf-cmd (message pdf-cmd) (shell-command pdf-cmd))
(unless noninteractive (message cmd))
(shell-command cmd)
(when pdf-cmd (unless noninteractive (message pdf-cmd)) (shell-command pdf-cmd))
nil)) ;; signal that output has already been written to file
(defun org-babel-prep-session:ditaa (_session _params)

View File

@ -210,7 +210,7 @@ This function is called by `org-babel-execute-src-block'."
(let ((script-file (org-babel-temp-file "gnuplot-script-")))
(with-temp-file script-file
(insert (concat body "\n")))
(message "gnuplot \"%s\"" script-file)
(unless noninteractive (message "gnuplot \"%s\"" script-file))
(setq output
(shell-command-to-string
(format
@ -219,7 +219,7 @@ This function is called by `org-babel-execute-src-block'."
script-file
(if (member system-type '(cygwin windows-nt ms-dos))
t nil)))))
(message "%s" output))
(unless noninteractive (message "%s" output)))
(with-temp-buffer
(insert (concat body "\n"))
(gnuplot-mode)
@ -232,7 +232,7 @@ This function is called by `org-babel-execute-src-block'."
"Prepare SESSION according to the header arguments in PARAMS."
(let* ((session (org-babel-gnuplot-initiate-session session))
(var-lines (org-babel-variable-assignments:gnuplot params)))
(message "%S" session)
(unless noninteractive (message "%S" session))
(org-babel-comint-in-buffer session
(dolist (var-line var-lines)
(insert var-line)

View File

@ -52,7 +52,7 @@ parameters may be used, like groovy -v"
(defun org-babel-execute:groovy (body params)
"Execute Groovy BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(message "Executing Groovy source code block")
(unless noninteractive (message "Executing Groovy source code block"))
(let* ((processed-params (org-babel-process-params params))
(session (org-babel-groovy-initiate-session (nth 0 processed-params)))
(result-params (nth 2 processed-params))

View File

@ -131,7 +131,7 @@ Return nil if LINE is zero-length or it matches a regexp in
(defun org-babel-execute:maxima (body params)
"Execute Maxima BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(message "Executing Maxima source code block")
(unless noninteractive (message "Executing Maxima source code block"))
(let ((result-params (split-string (or (cdr (assq :results params)) "")))
(result
(let* ((cmdline (or (cdr (assq :cmdline params)) ""))
@ -151,7 +151,7 @@ This function is called by `org-babel-execute-src-block'."
(format "(linenum:0, %s(%S))$" batch/load in-file))
cmdline)))
(with-temp-file in-file (insert (org-babel-maxima-expand body params)))
(message cmd)
(unless noninteractive (message cmd))
;; " | grep -v batch | grep -v 'replaced' | sed '/^$/d' "
(let ((raw (org-babel-eval cmd "")))
(mapconcat

View File

@ -52,7 +52,7 @@ In case you want to use a different screen than one selected by your $PATH")
(defun org-babel-execute:screen (body params)
"Send BODY via screen to a terminal using Babel, according to PARAMS.
\"default\" session is used when none is specified in the PARAMS."
(message "Sending source code block to interactive terminal session...")
(unless noninteractive (message "Sending source code block to interactive terminal session..."))
(save-window-excursion
(let* ((session (cdr (assq :session params)))
(socket (org-babel-screen-session-socketname session)))

View File

@ -65,7 +65,7 @@
BODY is the source inside a sed source block and PARAMS is an
association list over the source block configurations. This
function is called by `org-babel-execute-src-block'."
(message "Executing sed source code block")
(unless noninteractive (message "Executing sed source code block"))
(let* ((result-params (cdr (assq :result-params params)))
(cmd-line (cdr (assq :cmd-line params)))
(in-file (cdr (assq :in-file params)))