emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: sebastien.miquel@posteo.eu
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: [PATCH] org-babel: Do not echo output of resolved noweb references
Date: Thu, 21 Jul 2022 19:13:38 +0800	[thread overview]
Message-ID: <87fsiu3ehp.fsf@localhost> (raw)
In-Reply-To: <7702b511-c289-5688-c64c-fb673324a63a@posteo.eu>

[-- Attachment #1: Type: text/plain, Size: 2908 bytes --]

Sébastien Miquel <sebastien.miquel@posteo.eu> writes:

>>>    + the tangle gets very noisy: not only are the result of execution
>>>      printed in the echo buffer, but emacs visits the tangling buffer
>>>      and moves the point to each block.
>>>      Perhaps this is a bug that can be fixed.
>> Did you try to play with :results header argument to disable messages?
>> What exactly went unexpected?
>
> I did. I might have missed something, but no combination of :results
> argument to both the latex block and the string-escape block silences
> the tangle (except for :results none, which doesn't tangle the content
> of the block). During tangle, the contents of the latex block are
> displayed (shortly) in the echo buffer (check *Messages*), and the
> point very briefly moves to the latex block. This isn't very
> noticeable with a single block.

Point movement is normal, but usually invisible because it happens
faster than redisplay cycle. As for displaying the resolved noweb
references, I do think that it should not happen.

Currently, every time Org resolves noweb references, the behaviour is
resembling :results silent. That is, the results of evaluation are
displayed, but not inserted after the executed source blocks.

I propose to change this by using :results none that will display
"results silenced" echo instead of messaging the whole result string.

The proposed behaviour makes more sense compared with the default value
because resolved noweb references are usually used to pipe data
(including table data) between source blocks and to include generated
code during noweb expansion. Such data tends to be fairly bulky and
creates a lot of noise during export/tangling. Not to mention that
displaying large messages also gives a considerable slowdown to the
whole export/tangle process.

Note that changing the current behaviour also triggered the way :results
none are being processed. The de facto implementation in ob-core does
not do any kind of return value post-processing on :results none, which
is not consistent with the manual (16.6 Results of Evaluation). In the
manual, "none" option is a part of the option class consisting of
"replace", "silent", "none", "append", and "prepend". All other
alternative options only influence how the results are inserted after
evaluation and processing. The fact that "none" result is not being
processed according to :file, :post, and other arguments is not
consistent. I changed that. Now, :results "none" are being processed
completely, and only the actual insertion is not performed.

The above change affects the return value of
org-babel-execute-src-block. Previously, it always returned nil with
:results none. Now, it returns the actual post-processed result of
evaluation.

Let me know if you see any potential issues with the proposed change.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-babel-Do-not-echo-output-of-resolved-noweb-refer.patch --]
[-- Type: text/x-patch, Size: 7234 bytes --]

From f01818ef5bce0a557eb119c58c449d75b28a923e Mon Sep 17 00:00:00 2001
Message-Id: <f01818ef5bce0a557eb119c58c449d75b28a923e.1658401224.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Thu, 21 Jul 2022 18:54:30 +0800
Subject: [PATCH] org-babel: Do not echo output of resolved noweb references

* lisp/ob-core.el (org-babel-execute-src-block): Post-process and
return results even when "none" results parameter is given.  Document
that the result value is returned, as it is assumed by
`org-babel-ref-resolve'.
(org-babel-result-cond): Do return results even when "none" results
parameter is given.

According to the manual ":results none" should only affect how the
results of evaluation are inserted into the buffer.  However, the
results are simply ignored currently.  Fix this.
* lisp/ob-ref.el (org-babel-ref-resolve): Set :results to "none" when
resolving noweb references.  Together with the above changes, this
makes Org not echo the results value yet returning the value
programatically.

Reported in https://orgmode.org/list/7702b511-c289-5688-c64c-fb673324a63a@posteo.eu
---
 lisp/ob-core.el | 118 ++++++++++++++++++++++++------------------------
 lisp/ob-ref.el  |   2 +-
 2 files changed, 59 insertions(+), 61 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index ac9af5d24..714f70c6a 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -712,7 +712,7 @@ (defvar *this*) ; Dynamically bound in `org-babel-execute-src-block'
 
 ;;;###autoload
 (defun org-babel-execute-src-block (&optional arg info params)
-  "Execute the current source code block.
+  "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
 controlled through a variety of header arguments.
@@ -776,51 +776,50 @@ (defun org-babel-execute-src-block (&optional arg info params)
 		     (capitalize lang)
 		     (let ((name (nth 4 info)))
 		       (if name (format " (%s)" name) "")))
-	    (if (member "none" result-params)
-		(progn (funcall cmd body params)
-		       (message "result silenced"))
-	      (setq result
-		    (let ((r (funcall cmd body params)))
-		      (if (and (eq (cdr (assq :result-type params)) 'value)
-			       (or (member "vector" result-params)
-				   (member "table" result-params))
-			       (not (listp r)))
-			  (list (list r))
-			r)))
-	      (let ((file (and (member "file" result-params)
-			       (cdr (assq :file params)))))
-		;; If non-empty result and :file then write to :file.
-		(when file
-		  ;; If `:results' are special types like `link' or
-		  ;; `graphics', don't write result to `:file'.  Only
-		  ;; insert a link to `:file'.
-		  (when (and result
-			     (not (or (member "link" result-params)
-				      (member "graphics" result-params))))
-		    (with-temp-file file
-		      (insert (org-babel-format-result
-			       result
-			       (cdr (assq :sep params)))))
-		    ;; Set file permissions if header argument
-		    ;; `:file-mode' is provided.
-		    (when (assq :file-mode params)
-		      (set-file-modes file (cdr (assq :file-mode params)))))
-		  (setq result file))
-		;; Possibly perform post process provided its
-		;; appropriate.  Dynamically bind "*this*" to the
-		;; actual results of the block.
-		(let ((post (cdr (assq :post params))))
-		  (when post
-		    (let ((*this* (if (not file) result
-				    (org-babel-result-to-file
-				     file
-				     (org-babel--file-desc params result)
-                                     'attachment))))
-		      (setq result (org-babel-ref-resolve post))
-		      (when file
-			(setq result-params (remove "file" result-params))))))
-		(org-babel-insert-result
-		 result result-params info new-hash lang)))
+	    (setq result
+		  (let ((r (funcall cmd body params)))
+		    (if (and (eq (cdr (assq :result-type params)) 'value)
+			     (or (member "vector" result-params)
+				 (member "table" result-params))
+			     (not (listp r)))
+			(list (list r))
+		      r)))
+	    (let ((file (and (member "file" result-params)
+			     (cdr (assq :file params)))))
+	      ;; If non-empty result and :file then write to :file.
+	      (when file
+		;; If `:results' are special types like `link' or
+		;; `graphics', don't write result to `:file'.  Only
+		;; insert a link to `:file'.
+		(when (and result
+			   (not (or (member "link" result-params)
+				  (member "graphics" result-params))))
+		  (with-temp-file file
+		    (insert (org-babel-format-result
+			     result
+			     (cdr (assq :sep params)))))
+		  ;; Set file permissions if header argument
+		  ;; `:file-mode' is provided.
+		  (when (assq :file-mode params)
+		    (set-file-modes file (cdr (assq :file-mode params)))))
+		(setq result file))
+	      ;; Possibly perform post process provided its
+	      ;; appropriate.  Dynamically bind "*this*" to the
+	      ;; actual results of the block.
+	      (let ((post (cdr (assq :post params))))
+		(when post
+		  (let ((*this* (if (not file) result
+				  (org-babel-result-to-file
+				   file
+				   (org-babel--file-desc params result)
+                                   'attachment))))
+		    (setq result (org-babel-ref-resolve post))
+		    (when file
+		      (setq result-params (remove "file" result-params))))))
+	      (if (member "none" result-params)
+		  (message "result silenced")
+	        (org-babel-insert-result
+	         result result-params info new-hash lang)))
 	    (run-hooks 'org-babel-after-execute-hook)
 	    result)))))))
 
@@ -3199,20 +3198,19 @@ (defmacro org-babel-result-cond (result-params scalar-form &rest table-forms)
   (declare (indent 1) (debug t))
   (org-with-gensyms (params)
     `(let ((,params ,result-params))
-       (unless (member "none" ,params)
-	 (if (or (member "scalar" ,params)
-		 (member "verbatim" ,params)
-		 (member "html" ,params)
-		 (member "code" ,params)
-		 (member "pp" ,params)
-		 (member "file" ,params)
-		 (and (or (member "output" ,params)
-			  (member "raw"    ,params)
-			  (member "org"    ,params)
-			  (member "drawer" ,params))
-		      (not (member "table" ,params))))
-	     ,scalar-form
-	   ,@table-forms)))))
+       (if (or (member "scalar" ,params)
+	       (member "verbatim" ,params)
+	       (member "html" ,params)
+	       (member "code" ,params)
+	       (member "pp" ,params)
+	       (member "file" ,params)
+	       (and (or (member "output" ,params)
+			(member "raw"    ,params)
+			(member "org"    ,params)
+			(member "drawer" ,params))
+		    (not (member "table" ,params))))
+	   ,scalar-form
+	 ,@table-forms))))
 
 (defun org-babel-temp-file (prefix &optional suffix)
   "Create a temporary file in the `org-babel-temporary-directory'.
diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el
index d5356f18c..87a7ccf63 100644
--- a/lisp/ob-ref.el
+++ b/lisp/ob-ref.el
@@ -153,7 +153,7 @@ (defun org-babel-ref-resolve (ref)
 	    (setq ref split-ref))
 	  (org-with-wide-buffer
 	   (goto-char (point-min))
-	   (let* ((params (append args '((:results . "silent"))))
+	   (let* ((params (append args '((:results . "none"))))
 		  (regexp (org-babel-named-data-regexp-for-name ref))
 		  (result
 		   (catch :found
-- 
2.35.1


  parent reply	other threads:[~2022-07-21 11:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-15 10:42 [PATCH] Add :noweb-prefix and :noweb-trans babel header arguments Sébastien Miquel
2022-04-28 13:45 ` Ihor Radchenko
2022-04-29 14:27   ` Sébastien Miquel
2022-04-30  6:05     ` Ihor Radchenko
2022-04-30  7:35       ` Sébastien Miquel
2022-04-30  8:41         ` Ihor Radchenko
2022-05-30 19:51       ` Sébastien Miquel
2022-05-31  5:14         ` Ihor Radchenko
2022-05-31  6:48           ` Sébastien Miquel
2022-07-16  8:57             ` [FR] Make :var foo=name-of-src-block assign the source block code instead of currently assigned result of evaluation (was: [PATCH] Add :noweb-prefix and :noweb-trans babel header arguments) Ihor Radchenko
2022-07-16 10:17               ` Greg Minshall
2022-07-16 10:45                 ` Ihor Radchenko
2022-07-16 14:31                   ` Greg Minshall
2022-07-17 17:39                   ` Sébastien Miquel
2022-07-23  4:52                     ` Ihor Radchenko
2022-08-29 17:39                       ` [PATCH] " Sébastien Miquel
2022-08-31  4:04                         ` Ihor Radchenko
2022-07-21 11:13             ` Ihor Radchenko [this message]
2022-07-21 13:41               ` [PATCH] org-babel: Do not echo output of resolved noweb references Sébastien Miquel
2022-08-22 12:01               ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fsiu3ehp.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=sebastien.miquel@posteo.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).