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) (defun org-babel-C-header-to-C (head type)
"Convert an elisp list of header table into a C or D vector "Convert an elisp list of header table into a C or D vector
specifying a variable with the name of the table." specifying a variable with the name of the table."
(message "%S" type) (unless noninteractive (message "%S" type))
(let ((table (car head)) (let ((table (car head))
(headers (cdr head)) (headers (cdr head))
(typename (pcase type (typename (pcase type

View File

@ -61,7 +61,7 @@
"Execute a block of Awk code BODY with org-babel. "Execute a block of Awk code BODY with org-babel.
PARAMS is a plist of src block parameters . PARAMS is a plist of src block parameters .
This function is called by `org-babel-execute-src-block'." 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))) (let* ((result-params (cdr (assq :result-params params)))
(cmd-line (cdr (assq :cmd-line params))) (cmd-line (cdr (assq :cmd-line params)))
(in-file (cdr (assq :in-file params))) (in-file (cdr (assq :in-file params)))

View File

@ -855,8 +855,9 @@ guess will be made."
(forward-line) (forward-line)
(skip-chars-forward " \t") (skip-chars-forward " \t")
(let ((result (org-babel-read-result))) (let ((result (org-babel-read-result)))
(message (format "Cached: %s" (unless noninteractive
(replace-regexp-in-string "%" "%%" (format "%S" result)))) (message (format "Cached: %s"
(replace-regexp-in-string "%" "%%" (format "%S" result)))))
result))) result)))
((org-babel-confirm-evaluate info) ((org-babel-confirm-evaluate info)
(let* ((lang (nth 0 info)) (let* ((lang (nth 0 info))
@ -879,18 +880,19 @@ guess will be made."
result exec-start-time) result exec-start-time)
(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 %s %s..." (unless noninteractive
(capitalize lang) (message "Executing %s %s %s..."
(pcase executor-type (capitalize lang)
('src-block "code block") (pcase executor-type
('inline-src-block "inline code block") ('src-block "code block")
('babel-call "call") ('inline-src-block "inline code block")
('inline-babel-call "inline call") ('babel-call "call")
(e (symbol-name e))) ('inline-babel-call "inline call")
(let ((name (nth 4 info))) (e (symbol-name e)))
(if name (let ((name (nth 4 info)))
(format "(%s)" name) (if name
(format "at position %S" (nth 5 info))))) (format "(%s)" name)
(format "at position %S" (nth 5 info))))))
(setq exec-start-time (current-time) (setq exec-start-time (current-time)
result result
(let ((r (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 ;; In this case `table-align' does the work
;; for us. ;; for us.
(not (and (listp result) (not (and (listp result)
(member "append" result-params)))) (member "append" result-params))))
(indent-rigidly beg end indent)) (indent-rigidly beg end indent))
(let ((time-info (unless noninteractive
;; Only show the time when something other than (let ((time-info
;; 0s will be shown, i.e. check if the time is at ;; Only show the time when something other than
;; least half of the displayed precision. ;; 0s will be shown, i.e. check if the time is at
(if (and exec-time (> (float-time exec-time) 0.05)) ;; least half of the displayed precision.
(format " (took %.1fs)" (float-time exec-time)) (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) (if (null result)
(message "Code block returned no value%s." time-info) (if (member "value" result-params)
(message "Code block produced no output%s." time-info)) (message "Code block returned no value%s." time-info)
(message "Code block evaluation complete%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 end (set-marker end nil))
(when outside-scope (narrow-to-region visible-beg visible-end)) (when outside-scope (narrow-to-region visible-beg visible-end))
(set-marker visible-beg nil) (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) (unless (file-exists-p org-ditaa-jar-path)
(error "Could not find ditaa.jar at %s" org-ditaa-jar-path)) (error "Could not find ditaa.jar at %s" org-ditaa-jar-path))
(with-temp-file in-file (insert body)) (with-temp-file in-file (insert body))
(message cmd) (shell-command cmd) (unless noninteractive (message cmd))
(when pdf-cmd (message pdf-cmd) (shell-command pdf-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 nil)) ;; signal that output has already been written to file
(defun org-babel-prep-session:ditaa (_session _params) (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-"))) (let ((script-file (org-babel-temp-file "gnuplot-script-")))
(with-temp-file script-file (with-temp-file script-file
(insert (concat body "\n"))) (insert (concat body "\n")))
(message "gnuplot \"%s\"" script-file) (unless noninteractive (message "gnuplot \"%s\"" script-file))
(setq output (setq output
(shell-command-to-string (shell-command-to-string
(format (format
@ -219,7 +219,7 @@ This function is called by `org-babel-execute-src-block'."
script-file script-file
(if (member system-type '(cygwin windows-nt ms-dos)) (if (member system-type '(cygwin windows-nt ms-dos))
t nil))))) t nil)))))
(message "%s" output)) (unless noninteractive (message "%s" output)))
(with-temp-buffer (with-temp-buffer
(insert (concat body "\n")) (insert (concat body "\n"))
(gnuplot-mode) (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." "Prepare SESSION according to the header arguments in PARAMS."
(let* ((session (org-babel-gnuplot-initiate-session session)) (let* ((session (org-babel-gnuplot-initiate-session session))
(var-lines (org-babel-variable-assignments:gnuplot params))) (var-lines (org-babel-variable-assignments:gnuplot params)))
(message "%S" session) (unless noninteractive (message "%S" session))
(org-babel-comint-in-buffer session (org-babel-comint-in-buffer session
(dolist (var-line var-lines) (dolist (var-line var-lines)
(insert var-line) (insert var-line)

View File

@ -52,7 +52,7 @@ parameters may be used, like groovy -v"
(defun org-babel-execute:groovy (body params) (defun org-babel-execute:groovy (body params)
"Execute Groovy BODY according to PARAMS. "Execute Groovy BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'." 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)) (let* ((processed-params (org-babel-process-params params))
(session (org-babel-groovy-initiate-session (nth 0 processed-params))) (session (org-babel-groovy-initiate-session (nth 0 processed-params)))
(result-params (nth 2 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) (defun org-babel-execute:maxima (body params)
"Execute Maxima BODY according to PARAMS. "Execute Maxima BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'." 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)) ""))) (let ((result-params (split-string (or (cdr (assq :results params)) "")))
(result (result
(let* ((cmdline (or (cdr (assq :cmdline params)) "")) (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)) (format "(linenum:0, %s(%S))$" batch/load in-file))
cmdline))) cmdline)))
(with-temp-file in-file (insert (org-babel-maxima-expand body params))) (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' " ;; " | grep -v batch | grep -v 'replaced' | sed '/^$/d' "
(let ((raw (org-babel-eval cmd ""))) (let ((raw (org-babel-eval cmd "")))
(mapconcat (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) (defun org-babel-execute:screen (body params)
"Send BODY via screen to a terminal using Babel, according to PARAMS. "Send BODY via screen to a terminal using Babel, according to PARAMS.
\"default\" session is used when none is specified in the 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 (save-window-excursion
(let* ((session (cdr (assq :session params))) (let* ((session (cdr (assq :session params)))
(socket (org-babel-screen-session-socketname session))) (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 BODY is the source inside a sed source block and PARAMS is an
association list over the source block configurations. This association list over the source block configurations. This
function is called by `org-babel-execute-src-block'." 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))) (let* ((result-params (cdr (assq :result-params params)))
(cmd-line (cdr (assq :cmd-line params))) (cmd-line (cdr (assq :cmd-line params)))
(in-file (cdr (assq :in-file params))) (in-file (cdr (assq :in-file params)))