>From a4da247355dd0f347843b06d9e64d26d210a4b0a Mon Sep 17 00:00:00 2001 From: stardiviner Date: Tue, 27 Mar 2018 10:50:03 +0800 Subject: [PATCH 1/2] * ob-core.el (org-babel-execute-src-block) support :results link. - doc/org.texi (:results): support :results link type. Don't write non-empty result to :file when result type is link. Use it like this: wget -c "http://ben.akrin.com/crackzor/crackzor_1.0.c.gz" [[file:data/tmp/crackzor_1.0.c.gz]] - testing/lisp/test-ob.el (test-ob/result-file-link-type-header-argument) add test. --- doc/org.texi | 3 +++ etc/ORG-NEWS | 9 +++++++++ lisp/ob-core.el | 13 ++++++++----- testing/lisp/test-ob.el | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index aaa180401..903f52143 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -16204,6 +16204,9 @@ example: @code{:results value verbatim}. @item @code{file} Interpret as path to a file. Inserts a link to the file. Usage example: @code{:results value file}. address@hidden @code{link} +Interpret as path to a file. Inserts a link to the file. Usage example: address@hidden:results value link}. @end itemize @subsubheading Format diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index d479b982c..e2a02d0a2 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -113,6 +113,15 @@ now sort according to the locale’s collation rules instead of by code-point. ** New features +*** add ~:results link~ support for org-babel +This will support only insert file link without writing result to file. +Like this case: +#+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]] *** Add ~:session~ support of ob-js for js-comint #+begin_src js :session "*Javascript REPL*" console.log("stardiviner") diff --git a/lisp/ob-core.el b/lisp/ob-core.el index e33168278..d2c1b70f3 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -413,7 +413,7 @@ then run `org-babel-switch-to-session'." (padline . ((yes no))) (post . :any) (prologue . :any) - (results . ((file list vector table scalar verbatim) + (results . ((file link list vector table scalar verbatim) (raw html latex org code pp drawer) (replace silent none append prepend) (output value))) @@ -707,10 +707,13 @@ block." ;; 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?)) + (member "graphics" (cdr (assq :result-params params)))) + (file-link? + (member "link" (cdr (assq :result-params params))))) + ;; If :results are special types like `link', `graphics' etc. + ;; don't write result to :file. literately only + ;; insert link to :file. + (when (and result (not graphics?) (not file-link?)) (with-temp-file file (insert (org-babel-format-result result (cdr (assq :sep params))))))) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index a4a590d6a..93eb7736a 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -996,6 +996,23 @@ 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." + (org-test-with-temp-text + "#+begin_src sh :results link :file \"test.txt\" + echo \"hello\" > test.txt + echo \"test\" + #+end_src" + (org-babel-execute-src-block) + (goto-char (point-min)) + (should (search-forward "[[file:test.txt]]" nil t)) + (should (with-temp-buffer + (insert-file-contents "test.txt") + (string-match + "hello.*" + (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.16.3