From 148d084ef100fb4ca32f8f19e36d4dcbe643b6b4 Mon Sep 17 00:00:00 2001 From: stardiviner Date: Sun, 8 Apr 2018 20:56:28 +0800 Subject: [PATCH 1/2] ob-core.el: add "link" :results format for babel. * lisp/ob-core.el (org-babel-execute-src-block): handle "link" :results format. Don't write result to :file specified file. * etc/ORG-NEWS: declare new "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): Add test for new added :results format "link". --- doc/org-manual.org | 12 ++++++++++++ etc/ORG-NEWS | 9 +++++++++ lisp/ob-core.el | 12 ++++++------ testing/lisp/test-ob.el | 16 ++++++++++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index d787e5da4..afd968a38 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -17224,6 +17224,18 @@ follows from the type specified above. =raw= or =org= results for later scripting and automated processing. Usage example: =:results value drawer=. +- =link= :: + + #+cindex: @samp{link}, 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. Like following + example: + + #+begin_src shell :results link :file "download.tar.gz" + wget -c "http://example.com/download.tar.gz" + #+end_src + *** Handling :PROPERTIES: :UNNUMBERED: notoc diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 0edd77115..3833b57b2 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 129e17f62..2b72d7b32 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,11 +706,11 @@ 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?)) + (let ((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..e541ad726 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -996,6 +996,22 @@ 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 shell :results value link :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