From e4902995a0643c7658fb51b14911eaff2891a1e3 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Thu, 13 Jun 2024 15:16:54 +0200 Subject: [PATCH] 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 Link: https://yhetil.org/emacs-devel/868qzd9hjg.fsf@gnu.org/ --- lisp/ob-C.el | 2 +- lisp/ob-awk.el | 2 +- lisp/ob-core.el | 57 ++++++++++++++++++++++++---------------------- lisp/ob-ditaa.el | 5 ++-- lisp/ob-gnuplot.el | 6 ++--- lisp/ob-groovy.el | 2 +- lisp/ob-maxima.el | 4 ++-- lisp/ob-screen.el | 2 +- lisp/ob-sed.el | 2 +- 9 files changed, 43 insertions(+), 39 deletions(-) diff --git a/lisp/ob-C.el b/lisp/ob-C.el index d13c65d26..f7735ee72 100644 --- a/lisp/ob-C.el +++ b/lisp/ob-C.el @@ -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 diff --git a/lisp/ob-awk.el b/lisp/ob-awk.el index 9577a39ee..d94da405f 100644 --- a/lisp/ob-awk.el +++ b/lisp/ob-awk.el @@ -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))) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 2e0e86f70..0b329266a 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -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) diff --git a/lisp/ob-ditaa.el b/lisp/ob-ditaa.el index ba8e65394..715d8ddf0 100644 --- a/lisp/ob-ditaa.el +++ b/lisp/ob-ditaa.el @@ -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) diff --git a/lisp/ob-gnuplot.el b/lisp/ob-gnuplot.el index dc5cd0e52..956763c58 100644 --- a/lisp/ob-gnuplot.el +++ b/lisp/ob-gnuplot.el @@ -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) diff --git a/lisp/ob-groovy.el b/lisp/ob-groovy.el index 908df9337..d87ef4bb6 100644 --- a/lisp/ob-groovy.el +++ b/lisp/ob-groovy.el @@ -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)) diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el index ef875cfe8..681154adf 100644 --- a/lisp/ob-maxima.el +++ b/lisp/ob-maxima.el @@ -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 diff --git a/lisp/ob-screen.el b/lisp/ob-screen.el index ffb66d659..a56afc705 100644 --- a/lisp/ob-screen.el +++ b/lisp/ob-screen.el @@ -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))) diff --git a/lisp/ob-sed.el b/lisp/ob-sed.el index fa6a2bb19..83d9684ad 100644 --- a/lisp/ob-sed.el +++ b/lisp/ob-sed.el @@ -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)))