From 296b0de4e881b6bd8657dadf7e73fd323f961d8c Mon Sep 17 00:00:00 2001 From: stardiviner Date: Sun, 8 Apr 2018 20:56:28 +0800 Subject: [PATCH] ob-core: Add "link" results format * lisp/ob-core.el (org-babel-execute-src-block): Handle "link" :results format. * doc/org-manual.org: Add document for new result format "link". * testing/lisp/test-ob.el (test-ob/result-file-link-type-header-argument): New test. --- doc/org-manual.org | 13 +++++++++++++ etc/ORG-NEWS | 26 ++++++++++++++++++++------ lisp/ob-core.el | 20 +++++++++++--------- testing/lisp/test-ob.el | 15 +++++++++++++++ 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index fc53957bd..c9742a497 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -17224,6 +17224,19 @@ follows from the type specified above. =raw= or =org= results for later scripting and automated processing. Usage example: =:results value drawer=. +- =link= :: + + Result is a link to the file specified in =:file= header + argument. However, unlike plain =:file=, nothing is written to + the disk. The block is used for its side-effects only, as in the + following example: + + #+begin_example + ,#+begin_src shell :results link :file "download.tar.gz" + wget -c "http://example.com/download.tar.gz" + ,#+end_src + #+end_example + *** Handling :PROPERTIES: :UNNUMBERED: notoc diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index bfb5a2dc2..6a4fe40f0 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -113,6 +113,20 @@ now sort according to the locale’s collation rules instead of by code-point. ** New features +*** Add ~:results link~ support for Babel + +With this output format, create a link to the file specified in +~:file~ header argument, without actually writing any result to it: + +#+begin_example +,#+begin_src shell :dir "data/tmp" :results link :file "crackzor_1.0.c.gz" +wget -c "http://ben.akrin.com/crackzor/crackzor_1.0.c.gz" +,#+end_src + +,#+results: +[[file:data/tmp/crackzor_1.0.c.gz]] +#+end_example + *** Add ~:session~ support of ob-js for js-comint #+begin_src js :session "*Javascript REPL*" console.log("stardiviner") @@ -202,11 +216,11 @@ You can have a file =bananas.org= containing: ... and when going to the top of that file and entering column view you should expect to see something like: -| ITEM | CONFIRMED | Bananas | Confirmed Bananas | -|-----------------+-----------+---------+-------------------| -| All shipments | | 11 | 4 | -| Shipment 1 | [X] | 4 | 4 | -| Shipment 2 | [ ] | 7 | 7 | +| ITEM | CONFIRMED | Bananas | Confirmed Bananas | +|---------------+-----------+---------+-------------------| +| All shipments | | 11 | 4 | +| Shipment 1 | [X] | 4 | 4 | +| Shipment 2 | [ ] | 7 | 7 | #+BEGIN_EXAMPLE ,#+STARTUP: shrink @@ -3219,7 +3233,7 @@ See https://orgmode.org/elpa/ | =C-c C-x E= | =E= | [[doc::org-inc-effort][org-inc-effort]] | | | =#= | [[doc::org-toggle-comment][org-toggle-comment]] | | | =:= | [[doc::org-columns][org-columns]] | - | | =W= | Set =APPT_WARNTIME= | + | | =W= | Set =APPT_WARNTIME= | | =k= | | [[doc::org-agenda-capture][org-agenda-capture]] | | C-c , | , | [[doc::org-priority][org-priority]] | diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 129e17f62..75311e03b 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -414,7 +414,7 @@ then run `org-babel-switch-to-session'." (post . :any) (prologue . :any) (results . ((file list vector table scalar verbatim) - (raw html latex org code pp drawer) + (raw html latex org code pp drawer link) (replace silent none append prepend) (output value))) (rownames . ((no yes))) @@ -706,14 +706,16 @@ block." (let ((file (cdr (assq :file params)))) ;; If non-empty result and :file then write to :file. (when file - (let ((graphics? - (member "graphics" (cdr (assq :result-params params))))) - ;; Handle :results graphics :file case. Don't - ;; write result to file if result is graphics. - (when (and result (not graphics?)) - (with-temp-file file - (insert (org-babel-format-result - result (cdr (assq :sep params))))))) + ;; 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 ;; appropriate. Dynamically bind "*this*" to the diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index a4a590d6a..add76da84 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -996,6 +996,21 @@ trying to find the :END: marker." (should (search-forward "[[file:foo][bar]]" nil t)) (should (search-forward "[[file:foo][foo]]" nil t)))) +(ert-deftest test-ob/result-file-link-type-header-argument () + "Ensure that the result is a link to a file. +The file is just a link to `:file' value. Inhibit non-empty +result write to `:file' value." + (org-test-with-temp-text " +#+begin_src shell :results value link :file \"/tmp/test.txt\" +echo \"hello\" > /tmp/test.txt +echo \"test\" +#+end_src" + (org-babel-execute-src-block) + (should (search-forward "[[file:/tmp/test.txt]]" nil nil)) + (should (with-temp-buffer + (insert-file-contents "/tmp/test.txt") + (string= "hello\n" (buffer-string)))))) + (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.11.4.GIT