emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: stardiviner <numbchild@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] support insert link without write result to :file link
Date: Tue, 27 Mar 2018 10:56:59 +0800	[thread overview]
Message-ID: <11516348-a184-6f9e-6a10-15fe4b06d0fb@gmail.com> (raw)
In-Reply-To: <87zi2u90f6.fsf@luisa.c0t0d0s0.de>

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

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

[-- Attachment #1.2: Type: text/html, Size: 2876 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-core.el-org-babel-execute-src-block-support-resul.patch --]
[-- Type: text/x-patch; name="0001-ob-core.el-org-babel-execute-src-block-support-resul.patch", Size: 1978 bytes --]

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

 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
 ** 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"
 *** Add ~:session~ support of ob-js for js-comint
 #+begin_src js :session "*Javascript REPL*"
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)))))))

  reply	other threads:[~2018-03-27  2:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-26 15:35 How to let ob-shell to download file and get result as a link to file? stardiviner
2018-03-26 18:06 ` Michael Welle
2018-03-27  2:56   ` stardiviner [this message]
2018-03-27  6:26     ` [PATCH] support insert link without write result to :file link Nicolas Goaziou
2018-03-28 16:11       ` stardiviner
2018-03-28 16:23         ` Nicolas Goaziou
2018-03-29  3:39           ` stardiviner
2018-03-29 16:30             ` Berry, Charles

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11516348-a184-6f9e-6a10-15fe4b06d0fb@gmail.com \
    --to=numbchild@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


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).