From: "Arthur A. Gleckler" <orgmode@speechcode.com>
To: emacs-orgmode@gnu.org
Subject: send block evaluation results to specified buffer
Date: Wed, 11 Sep 2019 18:14:59 -0700 [thread overview]
Message-ID: <CALnw4L+xJd3Wo+_nCUWRTihNKrBz3LQJtPXRifaDur9t7FRuRA@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2019-09-12 1:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-12 1:14 Arthur A. Gleckler [this message]
2021-12-20 14:03 ` [O] send block evaluation results to specified buffer Ihor Radchenko
2021-12-20 15:35 ` Arthur A. Gleckler
-- strict thread matches above, loose matches on Subject: below --
2019-09-12 0:44 Arthur A. Gleckler
2019-09-12 0:45 ` Arthur A. Gleckler
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=CALnw4L+xJd3Wo+_nCUWRTihNKrBz3LQJtPXRifaDur9t7FRuRA@mail.gmail.com \
--to=orgmode@speechcode.com \
--cc=emacs-orgmode@gnu.org \
/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).