From mboxrd@z Thu Jan 1 00:00:00 1970 From: stardiviner Subject: [PATCH] support insert link without write result to :file link Date: Tue, 27 Mar 2018 10:56:59 +0800 Message-ID: <11516348-a184-6f9e-6a10-15fe4b06d0fb@gmail.com> References: <87zi2u90f6.fsf@luisa.c0t0d0s0.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------3DC0203D59B90DC595E97A4A" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0enN-00044i-BX for emacs-orgmode@gnu.org; Mon, 26 Mar 2018 22:57:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0enK-0000pd-1z for emacs-orgmode@gnu.org; Mon, 26 Mar 2018 22:57:09 -0400 Received: from mail-pl0-x231.google.com ([2607:f8b0:400e:c01::231]:46778) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f0enJ-0000op-NF for emacs-orgmode@gnu.org; Mon, 26 Mar 2018 22:57:05 -0400 Received: by mail-pl0-x231.google.com with SMTP id f5-v6so13224705plj.13 for ; Mon, 26 Mar 2018 19:57:05 -0700 (PDT) Received: from [0.0.0.0] ([119.28.89.243]) by smtp.gmail.com with ESMTPSA id 89sm292137pfs.156.2018.03.26.19.57.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 19:57:02 -0700 (PDT) In-Reply-To: <87zi2u90f6.fsf@luisa.c0t0d0s0.de> Content-Language: en-US List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------3DC0203D59B90DC595E97A4A Content-Type: multipart/alternative; boundary="------------DC6E837906BD1E11C38D8433" --------------DC6E837906BD1E11C38D8433 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 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 > --------------DC6E837906BD1E11C38D8433 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit

I added this patch to handle posted question case.

This will improve Org-mode links with org-babel result a 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

#+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


--------------DC6E837906BD1E11C38D8433-- --------------3DC0203D59B90DC595E97A4A Content-Type: text/x-patch; name="0001-ob-core.el-org-babel-execute-src-block-support-resul.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename*0="0001-ob-core.el-org-babel-execute-src-block-support-resul.pa"; filename*1="tch" >From 6e6f04016525ece12610833d731e8a92d4473ee2 Mon Sep 17 00:00:00 2001 From: stardiviner 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 --------------3DC0203D59B90DC595E97A4A--