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.
This commit is contained in:
stardiviner 2018-04-08 20:56:28 +08:00 committed by Nicolas Goaziou
parent 52ba1a27ad
commit 296b0de4e8
4 changed files with 59 additions and 15 deletions

View File

@ -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

View File

@ -113,6 +113,20 @@ now sort according to the locales 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]] |

View File

@ -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

View File

@ -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="))