emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* send block evaluation results to specified buffer
@ 2019-09-12  0:44 Arthur A. Gleckler
  2019-09-12  0:45 ` Arthur A. Gleckler
  0 siblings, 1 reply; 3+ messages in thread
From: Arthur A. Gleckler @ 2019-09-12  0:44 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 564 bytes --]

Attached is a patch to allow one to specify that results from executing a
block should go to a specific buffer.

When a :buffer is specified, output goes to that buffer, which is erased
first, e.g.:

  #+begin_src sh :results buffer
  echo foo
  #+end_src

When no :buffer is specified, buffer *org results* is used, e.g.:

  #+begin_src sh :results buffer
  echo foo
  #+end_src

I've tried to follow the conventions for contributions to Org mode, buf if
I've missed something, please let me know.  (I'm happy to sign the FSF
paperwork.)

Thank you for Org mode!

[-- Attachment #1.2: Type: text/html, Size: 810 bytes --]

[-- Attachment #2: 0001-ob-core.el-block-result-output-to-buffer.patch --]
[-- Type: application/x-patch, Size: 3780 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread
* send block evaluation results to specified buffer
@ 2019-09-12  1:14 Arthur A. Gleckler
  0 siblings, 0 replies; 3+ messages in thread
From: Arthur A. Gleckler @ 2019-09-12  1:14 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 578 bytes --]

Attached is a patch to allow one to specify that results from executing a
block should go to a specific buffer.

When a :buffer is specified, output goes to that buffer, which is erased
first, e.g.:

  #+begin_src sh :results buffer :buffer *foo*
  echo foo
  #+end_src

When no :buffer is specified, buffer *org results* is used, e.g.:

  #+begin_src sh :results buffer
  echo foo
  #+end_src

I've tried to follow the conventions for contributions to Org mode, buf if
I've missed something, please let me know.  (I'm happy to sign the FSF
paperwork.)

Thank you for Org mode!

[-- Attachment #1.2: Type: text/html, Size: 829 bytes --]

[-- Attachment #2: 0001-ob-core.el-block-result-output-to-buffer.patch --]
[-- Type: text/x-patch, Size: 3794 bytes --]

From 52de54b8cf5b91ac01d3a566b3c1ca6176a9cb1d Mon Sep 17 00:00:00 2001
From: "Arthur A. Gleckler" <aag@alum.mit.edu>
Date: Wed, 11 Sep 2019 17:03:33 -0700
Subject: [PATCH] ob-core.el: block result output to buffer

* lisp/ob-core.el (org-babel-execute-src-block): Support buffers.
Allow specifying that results from executing a block should go to a
buffer.

When a :buffer is specified, output goes to that buffer, which is
erased first, e.g.:

  #+begin_src sh :results buffer :buffer *foo*
  echo foo
  #+end_src

When no :buffer is specified, buffer "*org results*" is used, e.g.:

  #+begin_src sh :results buffer
  echo foo
  #+end_src

Also fixed typo: "it's" vs. "its".
---
 doc/org-manual.org |  8 ++++++++
 lisp/ob-core.el    | 44 ++++++++++++++++++++++++++++----------------
 2 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index f2f059e77..8e2715eeb 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -17333,6 +17333,14 @@ default behavior is to automatically determine the result type.
   TAB-delimited output.  You can choose a different separator with
   the =sep= header argument.
 
+- =buffer= ::
+
+  Save results to a specific buffer.  Erase the buffer, save the
+  results of execution of the code block to that buffer, then display
+  it.  The buffer name may be specified in the =:buffer= header
+  argument.  If it's not specified, the buffer =*org results*= is
+  used.
+
 *** Format
 :PROPERTIES:
 :UNNUMBERED: notoc
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 97ec18fd1..1537b4363 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -707,22 +707,33 @@ block."
 			       (not (listp r)))
 			  (list (list r))
 			r)))
-	      (let ((file (and (member "file" result-params)
+	      (let ((buffer (and (member "buffer" result-params)
+				 (get-buffer-create
+				  (or (cdr (assq :buffer params))
+				      "*org result*"))))
+		    (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))))))
-		  (setq result file))
-		;; Possibly perform post process provided its
+		(cond (buffer
+		       (with-current-buffer buffer
+			 (erase-buffer)
+			 (insert (org-babel-format-result
+				  result
+				  (cdr (assq :sep params)))))
+		       (display-buffer buffer))
+		      (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))))))
+		       (setq result file)))
+		;; Possibly perform post process provided it's
 		;; appropriate.  Dynamically bind "*this*" to the
 		;; actual results of the block.
 		(let ((post (cdr (assq :post params))))
@@ -735,8 +746,9 @@ block."
 		      (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)))
+		(unless buffer
+		  (org-babel-insert-result
+		   result result-params info new-hash lang))))
 	    (run-hooks 'org-babel-after-execute-hook)
 	    result)))))))
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-09-12  1:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-12  0:44 send block evaluation results to specified buffer Arthur A. Gleckler
2019-09-12  0:45 ` Arthur A. Gleckler
  -- strict thread matches above, loose matches on Subject: below --
2019-09-12  1:14 Arthur A. Gleckler

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).