From e626b929e0c89b9a09f83eb20bffbe5a56a5256f Mon Sep 17 00:00:00 2001 From: stardiviner Date: Tue, 10 Apr 2018 17:44:41 +0800 Subject: [PATCH 2/2] ob-core.el: support graphics :results type. * lisp/ob-core.el (org-babel-common-header-args-w-values): Add "graphics" :results type. * testing/lisp/test-ob.el (test-ob/result-graphics-link-type-header-argument) Add test for "graphics" :results type. * doc/org-manual.org: add manual for "graphics" :results type. --- doc/org-manual.org | 16 ++++++++++++++++ lisp/ob-core.el | 2 +- testing/lisp/test-ob.el | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 3c759d601..4b851e534 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -17189,6 +17189,22 @@ default behavior is to automatically determine the result type. wget -c "http://example.com/download.tar.gz" #+end_src +- =graphics= :: + + #+cindex: @samp{graphics}, header argument + When this result type used with header argument =:file=, generate a + link to =:file= specified file. Instead of writing src block + evaluate non-empty result to =:file= specified file. This will be + useful for generating Org inline image for src blocks. Like + following example: + + #+begin_src R :results graphics :file "graphics-result.png" + plot(seq(1,10)) + #+end_src + + #+RESULTS: + [[file:graphics-result.png]] + *** Format :PROPERTIES: :UNNUMBERED: notoc diff --git a/lisp/ob-core.el b/lisp/ob-core.el index e21cbf963..9c72bbccb 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -416,7 +416,7 @@ then run `org-babel-switch-to-session'." (results . ( ;; separate group to avoid been override by "file" ;; :results in `org-babel-merge-params'. - (link) + (link graphics) (file list vector table scalar verbatim) (raw html latex org code pp drawer) (replace silent none append prepend) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index e541ad726..3b7958552 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -1012,6 +1012,22 @@ echo \"test\" "hello\n" (buffer-substring-no-properties (point-min) (point-max))))))) +(ert-deftest test-ob/result-graphics-link-type-header-argument () + "Ensure that the result is a link to an image. +The file is just a link to :file value. Inhibit non-empty result write to :file." +(org-test-with-temp-text "#+begin_src shell :results value graphics :file \"/tmp/test.txt\" +echo \"hello\" > /tmp/test.txt +echo \"test\" +#+end_src" + (org-babel-execute-src-block) + (goto-char (point-min)) + (should (search-forward "[[file:/tmp/test.txt]]" nil nil)) + (should (with-temp-buffer + (insert-file-contents "/tmp/test.txt") + (string= + "hello\n" + (buffer-substring-no-properties (point-min) (point-max))))))) + (ert-deftest test-ob/inline-src_blk-preceded-punct-preceded-by-point () (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }") (org-babel-inline-result-wrap "=%s=")) -- 2.17.0