I added this patch to handle posted question case.

This will improve Org-mode links with org-babel resulta lot. Make Org-mode can insert link as user want at many places.

Hope can be merged.


On 03/27/2018 02:06 AM, Michael Welle wrote:
Hello,

stardiviner <numbch...@gmail.com> writes:

I tried the following example:

```

#+begin_src shell :mkdir yes :dir "data/tmp" :results file :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]]
```

But the files is empty, I check out Org-mode document about `:file`
header argument, seems org-babel will write result to `:file` specified
file. I wander how I can handle upper case correctly? (don't write
result to file, just insert a link to downloaded file as a result)
well, your above example would work, at least to a certain point, if you
let wget write its output to stdout:

#+begin_src sh :mkdir yes :dir "/tmp" :results file :file "crackzor_1.0.c.gz"
wget -c "http://ben.akrin.com/crackzor/crackzor_1.0.c.gz"; -O-
#+end_src

But I don't now know how to get the encoding right (I think that's the
problem). The zip file contains rubbish. What I would do instead is
something like this:

#+begin_src sh :mkdir yes :dir "/tmp" :results raw :var fn="crackzor_1.0.c.gz"
/usr/bin/wget -c "http://ben.akrin.com/crackzor/${fn}";
echo "[[file:/tmp/${fn}]]"
#+end_src

Regards
hmw


>From 6e6f04016525ece12610833d731e8a92d4473ee2 Mon Sep 17 00:00:00 2001
From: stardiviner <numbch...@gmail.com>
Date: Tue, 27 Mar 2018 10:50:03 +0800
Subject: [PATCH] * ob-core.el (org-babel-execute-src-block) support :results
 link.

---
 etc/ORG-NEWS    |  9 +++++++++
 lisp/ob-core.el | 11 +++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

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..a0e5663ec 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -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)))))))
-- 
2.16.3

Reply via email to