summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstardiviner <numbchild@gmail.com>2018-04-08 20:56:28 +0800
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-04-12 15:15:59 +0200
commit296b0de4e881b6bd8657dadf7e73fd323f961d8c (patch)
tree69db2de421f1b9c44dc100de834c01da70feceb4
parent52ba1a27ad7ba917afc3a0d16f5c1b86f9c8d8ed (diff)
downloadorg-mode-296b0de4e881b6bd8657dadf7e73fd323f961d8c.tar.gz
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.
-rw-r--r--doc/org-manual.org13
-rw-r--r--etc/ORG-NEWS26
-rw-r--r--lisp/ob-core.el20
-rw-r--r--testing/lisp/test-ob.el15
4 files changed, 59 insertions, 15 deletions
diff --git a/doc/org-manual.org b/doc/org-manual.org
index fc53957..c9742a4 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 bfb5a2d..6a4fe40 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 129e17f..75311e0 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 a4a590d..add76da 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 "
+<point>#+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="))