emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: stardiviner <numbchild@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] support insert link without write result to :file link
Date: Thu, 29 Mar 2018 00:11:00 +0800	[thread overview]
Message-ID: <55a201ba-d990-ede1-cf12-a6a3814d1979@gmail.com> (raw)
In-Reply-To: <87o9jarq4l.fsf@nicolasgoaziou.fr>


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

Hi, Nicolas, I have problem in my code. Even after many times and 5 
hourse Edebug on ob-core.el code. Still can't find out where is wrong. 
After Edebug, just know somewhere is wrong. here is my info:

- [ ] probelm is on ~org-babel-merge-params~, ~info~ is generated from 
it, but it removed ~link~ in ~:results~.
- [ ] org-babel-execute-src-block
   - [ ] (org-babel-get-src-block-info)
     - [ ] (let* ((info .. (apply #'org-babel-merge-params ...))))  -> 
info -> :results file replace (been removed here)
       - because ~:results link file replace~ are merged into ~:results 
file replace~?
         - where does the ~file~ comes from?
           - from ~:file~ header argument?
             - which function get this?
       - [ ] org-babel-process-params info


I added my latest patches in attachment (include test, and added your 
suggested modification). Can you help me on my code?


On 03/27/2018 02:26 PM, Nicolas Goaziou wrote:
> Hello,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> 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.
> Thank you.
>
> However, before thinking about merging it, it requires documentation and
> tests. You also need to update `org-babel-common-header-args-w-values'.
>
> Also, there are still failing tests from the last change to :results
> behaviour in master, if you ever have time to look into it.
>
> Regards,
>


[-- Attachment #1.2: Type: text/html, Size: 3180 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: 4385 bytes --]

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

- doc/org.texi (:results): support :results link type.

Don't write non-empty result to :file when result type is link.
Use it like this:

wget -c "http://ben.akrin.com/crackzor/crackzor_1.0.c.gz"

[[file:data/tmp/crackzor_1.0.c.gz]]

- testing/lisp/test-ob.el (test-ob/result-file-link-type-header-argument) add test.
---
 doc/org.texi            |  3 +++
 etc/ORG-NEWS            |  9 +++++++++
 lisp/ob-core.el         | 13 ++++++++-----
 testing/lisp/test-ob.el | 17 +++++++++++++++++
 4 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index aaa180401..903f52143 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -16204,6 +16204,9 @@ example: @code{:results value verbatim}.
 @item @code{file}
 Interpret as path to a file.  Inserts a link to the file.  Usage example:
 @code{:results value file}.
+@item @code{link}
+Interpret as path to a file.  Inserts a link to the file.  Usage example:
+@code{:results value link}.
 @end itemize
 
 @subsubheading Format
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..d2c1b70f3 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -413,7 +413,7 @@ then run `org-babel-switch-to-session'."
     (padline	. ((yes no)))
     (post       . :any)
     (prologue   . :any)
-    (results	. ((file list vector table scalar verbatim)
+    (results	. ((file link list vector table scalar verbatim)
 		   (raw html latex org code pp drawer)
 		   (replace silent none append prepend)
 		   (output value)))
@@ -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)))))))
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index a4a590d6a..93eb7736a 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -996,6 +996,23 @@ 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 sh :results link :file \"test.txt\"
+    echo \"hello\" > test.txt
+    echo \"test\"
+  #+end_src"
+   (org-babel-execute-src-block)
+   (goto-char (point-min))
+   (should (search-forward "[[file:test.txt]]" nil t))
+   (should (with-temp-buffer
+	     (insert-file-contents "test.txt")
+	     (string-match
+	      "hello.*"
+	      (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.16.3


[-- Attachment #3: 0002-ob-core.el-add-graphics-to-result-type.patch --]
[-- Type: text/x-patch, Size: 2901 bytes --]

From cacac1895c4871e122c16965edf6aad938c783dd Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Tue, 27 Mar 2018 20:03:48 +0800
Subject: [PATCH 2/2] * ob-core.el: add graphics to result type.

enhance for commit 39bd69b08.

- ob-core.el (org-babel-common-header-args-w-values): add keyword
  graphics.

- doc/org.texi (:results): add document for :results value graphics.

- testing/lisp/test-ob.el (test-ob/result-graphics-file-link-type-header-argument) add test.
---
 doc/org.texi            |  3 +++
 lisp/ob-core.el         |  2 +-
 testing/lisp/test-ob.el | 17 +++++++++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/doc/org.texi b/doc/org.texi
index 903f52143..be5d6ba2b 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -16207,6 +16207,9 @@ Interpret as path to a file.  Inserts a link to the file.  Usage example:
 @item @code{link}
 Interpret as path to a file.  Inserts a link to the file.  Usage example:
 @code{:results value link}.
+@item @code{graphics}
+Interpret as path to a graphic image file.  Inserts a link to the file.  Usage
+example: @code{:results value graphics}.
 @end itemize
 
 @subsubheading Format
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index d2c1b70f3..ef67bc8a7 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -413,7 +413,7 @@ then run `org-babel-switch-to-session'."
     (padline	. ((yes no)))
     (post       . :any)
     (prologue   . :any)
-    (results	. ((file link list vector table scalar verbatim)
+    (results	. ((file graphics link list vector table scalar verbatim)
 		   (raw html latex org code pp drawer)
 		   (replace silent none append prepend)
 		   (output value)))
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 93eb7736a..11b88275b 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -1013,6 +1013,23 @@ The file is just a link to :file value. Inhibit non-empty result write to :file.
 	      "hello.*"
 	      (buffer-substring-no-properties (point-min) (point-max)))))))
 
+(ert-deftest test-ob/result-graphics-file-link-type-header-argument ()
+  "Ensure that the result is a link to a graphic image file.
+The file is just a link to :file value. Inhibit non-empty result write to :file."
+  (org-test-with-temp-text
+   "#+begin_src sh :results value graphics :file \"test.png\"
+    echo \"hello\" > test.png
+    echo \"test\"
+  #+end_src"
+   (org-babel-execute-src-block)
+   (goto-char (point-min))
+   (should (search-forward "[[file:test.png]]" nil t))
+   (should (with-temp-buffer
+	     (insert-file-contents "test.png")
+	     (string-match
+	      "hello.*"
+	      (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.16.3


  reply	other threads:[~2018-03-28 16:11 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   ` [PATCH] support insert link without write result to :file link stardiviner
2018-03-27  6:26     ` Nicolas Goaziou
2018-03-28 16:11       ` stardiviner [this message]
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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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=55a201ba-d990-ede1-cf12-a6a3814d1979@gmail.com \
    --to=numbchild@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

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