emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] add "link" :results type for Babel
@ 2018-04-10 10:07 stardiviner
  2018-04-11 20:55 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: stardiviner @ 2018-04-10 10:07 UTC (permalink / raw)
  To: org-mode


[-- Attachment #1.1: Type: text/plain, Size: 798 bytes --]

This patch try to support following way:

#+begin_src sh :results link :file "/tmp/test.txt"
echo "hello" > /tmp/test.txt
echo "test"
#+end_src

#+RESULTS:
[[file:/tmp/test.txt]]

Because:

- ~org-babel-execute-src-block~
  - ~(org-babel-get-src-block-info)~
    - (let* ((info .. (apply #'org-babel-merge-params ...))))
      - ~org-babel-merge-params~
        - [ ] *because* code ~(`(,(or :file :file-ext) . ,value) ...)~
          lines logic in function ~org-babel-get-src-block-info~, it
          merge "file" ~:results~, so override params plist :results
          value ~link~.
        - [ ] So I put ~link~ and ~graphics~ "~:results~" type into a
          separate group in constant
          ~org-babel-common-header-args-w-values~.

If anybody has better way, please improve my code.


[-- Attachment #1.2: 0001-ob-core.el-add-results-link-type-result-for-babel.patch --]
[-- Type: text/x-patch, Size: 5102 bytes --]

From dc3e482b1cad581b74a4303ca79375db6a6ba885 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Sun, 8 Apr 2018 20:56:28 +0800
Subject: [PATCH 1/2] ob-core.el: add :results link type result for babel.

* lisp/ob-core.el (org-babel-execute-src-block): handle :results link
  type. Like :results graphics, don't write result to :file specified file.

* etc/ORG-NEWS: declare new :results type "link".

* doc/org-manual.org: add document for new type result "link".

* testing/lisp/test-ob.el (test-ob/result-file-link-type-header-argument):
  Add test for new added :results type "link".
---
 doc/org-manual.org      | 12 ++++++++++++
 etc/ORG-NEWS            |  9 +++++++++
 lisp/ob-core.el         | 16 ++++++++++------
 testing/lisp/test-ob.el | 16 ++++++++++++++++
 4 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index d787e5da4..3c759d601 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -17177,6 +17177,18 @@ default behavior is to automatically determine the result type.
      uses the generated file name for both the "link" and
      "description" parts of the link.
 
+- =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
+
 *** Format
 :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..e21cbf963 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -413,7 +413,11 @@ then run `org-babel-switch-to-session'."
     (padline	. ((yes no)))
     (post       . :any)
     (prologue   . :any)
-    (results	. ((file list vector table scalar verbatim)
+    (results	. (
+		   ;; separate group to avoid been override by "file"
+		   ;; :results in `org-babel-merge-params'.
+		   (link)
+		   (file list vector table scalar verbatim)
 		   (raw html latex org code pp drawer)
 		   (replace silent none append prepend)
 		   (output value)))
@@ -706,11 +710,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


[-- Attachment #1.3: Type: text/plain, Size: 86 bytes --]


The second patch is to add testing and document for merged graphics
implementation.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.4: 0002-ob-core.el-support-graphics-results-type.patch --]
[-- Type: text/x-patch, Size: 3268 bytes --]

From e626b929e0c89b9a09f83eb20bffbe5a56a5256f Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Tue, 10 Apr 2018 17:44:41 +0800
Subject: [PATCH 2/2] ob-core.el: support graphics :results type.

* lisp/ob-core.el (org-babel-common-header-args-w-values): Add
  "graphics" :results type.

* testing/lisp/test-ob.el (test-ob/result-graphics-link-type-header-argument)
  Add test for "graphics" :results type.

* doc/org-manual.org: add manual for "graphics" :results type.
---
 doc/org-manual.org      | 16 ++++++++++++++++
 lisp/ob-core.el         |  2 +-
 testing/lisp/test-ob.el | 16 ++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 3c759d601..4b851e534 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -17189,6 +17189,22 @@ default behavior is to automatically determine the result type.
      wget -c "http://example.com/download.tar.gz"
      #+end_src
 
+- =graphics= :: 
+
+     #+cindex: @samp{graphics}, 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. This will be
+     useful for generating Org inline image for src blocks. Like
+     following example:
+
+     #+begin_src R :results graphics :file "graphics-result.png"
+     plot(seq(1,10))
+     #+end_src
+
+     #+RESULTS:
+     [[file:graphics-result.png]]
+
 *** Format
 :PROPERTIES:
 :UNNUMBERED: notoc
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index e21cbf963..9c72bbccb 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -416,7 +416,7 @@ then run `org-babel-switch-to-session'."
     (results	. (
 		   ;; separate group to avoid been override by "file"
 		   ;; :results in `org-babel-merge-params'.
-		   (link)
+		   (link graphics)
 		   (file list vector table scalar verbatim)
 		   (raw html latex org code pp drawer)
 		   (replace silent none append prepend)
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index e541ad726..3b7958552 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -1012,6 +1012,22 @@ echo \"test\"
    	      "hello\n"
    	      (buffer-substring-no-properties (point-min) (point-max)))))))
 
+(ert-deftest test-ob/result-graphics-link-type-header-argument ()
+  "Ensure that the result is a link to an image.
+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 graphics :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


[-- Attachment #1.5: Type: text/plain, Size: 187 bytes --]


--
[ stardiviner ] don't need to convince with trends.
       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add "link" :results type for Babel
  2018-04-10 10:07 [PATCH] add "link" :results type for Babel stardiviner
@ 2018-04-11 20:55 ` Nicolas Goaziou
  2018-04-12  2:04   ` stardiviner
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2018-04-11 20:55 UTC (permalink / raw)
  To: stardiviner; +Cc: org-mode

Hello,

stardiviner <numbchild@gmail.com> writes:

> This patch try to support following way:
>
> #+begin_src sh :results link :file "/tmp/test.txt"
> echo "hello" > /tmp/test.txt
> echo "test"
> #+end_src
>
> #+RESULTS:
> [[file:/tmp/test.txt]]
>
> Because:
>
> - ~org-babel-execute-src-block~
>   - ~(org-babel-get-src-block-info)~
>     - (let* ((info .. (apply #'org-babel-merge-params ...))))
>       - ~org-babel-merge-params~
>         - [ ] *because* code ~(`(,(or :file :file-ext) . ,value) ...)~
>           lines logic in function ~org-babel-get-src-block-info~, it
>           merge "file" ~:results~, so override params plist :results
>           value ~link~.
>         - [ ] So I put ~link~ and ~graphics~ "~:results~" type into a
>           separate group in constant
>           ~org-babel-common-header-args-w-values~.
>
> If anybody has better way, please improve my code.

IIRC, there is no technical difference between ":results graphics" and
":results link". So, what about simply stating that `link' and
`graphics' are equivalent, like, e.g., `table' and `vector' or `scalar'
and `verbatim'?

Note that `graphics' results are not properly documented in the current
manual. They should probably go in "Working with Source Code/Results of
Evaluation/Format" section.

> -    (results	. ((file list vector table scalar verbatim)
> +    (results	. (
> +		   ;; separate group to avoid been override by "file"
> +		   ;; :results in `org-babel-merge-params'.
> +		   (link)

`link' is not an output type. `graphics' is not defined here either.

> +(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)))))))

Note that this test already passes when "link" is substituted with "graphics".

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add "link" :results type for Babel
  2018-04-11 20:55 ` Nicolas Goaziou
@ 2018-04-12  2:04   ` stardiviner
  2018-04-12 13:17     ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: stardiviner @ 2018-04-12  2:04 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode

[-- Attachment #1: Type: text/plain, Size: 2941 bytes --]


On 04/12/2018 04:55 AM, Nicolas Goaziou wrote:
> Hello,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> This patch try to support following way:
>>
>> #+begin_src sh :results link :file "/tmp/test.txt"
>> echo "hello" > /tmp/test.txt
>> echo "test"
>> #+end_src
>>
>> #+RESULTS:
>> [[file:/tmp/test.txt]]
>>
>> Because:
>>
>> - ~org-babel-execute-src-block~
>>    - ~(org-babel-get-src-block-info)~
>>      - (let* ((info .. (apply #'org-babel-merge-params ...))))
>>        - ~org-babel-merge-params~
>>          - [ ] *because* code ~(`(,(or :file :file-ext) . ,value) ...)~
>>            lines logic in function ~org-babel-get-src-block-info~, it
>>            merge "file" ~:results~, so override params plist :results
>>            value ~link~.
>>          - [ ] So I put ~link~ and ~graphics~ "~:results~" type into a
>>            separate group in constant
>>            ~org-babel-common-header-args-w-values~.
>>
>> If anybody has better way, please improve my code.
> IIRC, there is no technical difference between ":results graphics" and
> ":results link". So, what about simply stating that `link' and
> `graphics' are equivalent, like, e.g., `table' and `vector' or `scalar'
> and `verbatim'?
>
> Note that `graphics' results are not properly documented in the current
> manual. They should probably go in "Working with Source Code/Results of
> Evaluation/Format" section.
updated.
>
>> -    (results	. ((file list vector table scalar verbatim)
>> +    (results	. (
>> +		   ;; separate group to avoid been override by "file"
>> +		   ;; :results in `org-babel-merge-params'.
>> +		   (link)
> `link' is not an output type. `graphics' is not defined here either.
Updated. I put "link" and "graphics" into result format group now.
This is really good. I have not come up with this.
>
>> +(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)))))))
> Note that this test already passes when "link" is substituted with "graphics".
>
> Regards,
>
I think keep "graphics" result format test is necessary. Even though is 
is almost same way "link" result format test. Because I have some ideas 
on graphics result format. Might add in the future. Also it provide 
straight mean for result format. People can understand it clearly. What 
do you think?

I attached new generated patches.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-core.el-add-link-results-format-for-babel.patch --]
[-- Type: text/x-patch; name="0001-ob-core.el-add-link-results-format-for-babel.patch", Size: 4819 bytes --]

From 148d084ef100fb4ca32f8f19e36d4dcbe643b6b4 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
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


[-- Attachment #3: 0002-ob-core.el-add-document-and-test-for-graphics-result.patch --]
[-- Type: text/x-patch, Size: 3014 bytes --]

From d62e605ea127c18795e918b077da9155af31cacd Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Thu, 12 Apr 2018 09:54:23 +0800
Subject: [PATCH 2/2] ob-core.el: add document and test for "graphics" :results
 format.

* doc/org-manual.org: add document.

* lisp/ob-core.el (org-babel-common-header-args-w-values): add symbol
  "graphics".

* testing/lisp/test-ob.el (test-ob/result-graphics-link-type-header-argument):
  add test for graphics result format.
---
 doc/org-manual.org      | 14 ++++++++++++++
 lisp/ob-core.el         |  2 +-
 testing/lisp/test-ob.el | 16 ++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index afd968a38..a2ad8df43 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -17236,6 +17236,20 @@ follows from the type specified above.
      wget -c "http://example.com/download.tar.gz"
      #+end_src
 
+- =graphics= :: 
+
+     #+cindex: @samp{graphics}, header argument
+     It is technically same with =link= result type. This will be useful
+     for generating Org inline image for src blocks. Like following
+     example:
+
+     #+begin_src R :results graphics :file "graphics-result.png"
+     plot(seq(1,10))
+     #+end_src
+
+     #+RESULTS:
+     [[file:graphics-result.png]]
+
 *** Handling
 :PROPERTIES:
 :UNNUMBERED: notoc
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 2b72d7b32..1580795db 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 link)
+		   (raw html latex org code pp drawer link graphics)
 		   (replace silent none append prepend)
 		   (output value)))
     (rownames	. ((no yes)))
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index e541ad726..3b7958552 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -1012,6 +1012,22 @@ echo \"test\"
    	      "hello\n"
    	      (buffer-substring-no-properties (point-min) (point-max)))))))
 
+(ert-deftest test-ob/result-graphics-link-type-header-argument ()
+  "Ensure that the result is a link to an image.
+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 graphics :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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add "link" :results type for Babel
  2018-04-12  2:04   ` stardiviner
@ 2018-04-12 13:17     ` Nicolas Goaziou
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2018-04-12 13:17 UTC (permalink / raw)
  To: stardiviner; +Cc: org-mode

Hello,

stardiviner <numbchild@gmail.com> writes:

> I attached new generated patches.

Applied, with a few changes.

Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-04-12 13:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-10 10:07 [PATCH] add "link" :results type for Babel stardiviner
2018-04-11 20:55 ` Nicolas Goaziou
2018-04-12  2:04   ` stardiviner
2018-04-12 13:17     ` Nicolas Goaziou

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).