emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* New source block results option for attaching file to node
@ 2021-08-26  8:48 Ryan Scott
  2021-08-31 11:15 ` Timothy
  0 siblings, 1 reply; 18+ messages in thread
From: Ryan Scott @ 2021-08-26  8:48 UTC (permalink / raw)
  To: emacs-orgmode


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

An additional option for use with ":results file" that moves the returned
path to the node attachment directory (as returned by org-attach-dir),
creating it if necessary.

First time submitting a patch. Any feedback is appreciated.

-ryan

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

[-- Attachment #2: 0001-ob-core-Added-option-for-attaching-file-from-babel-s.patch --]
[-- Type: application/octet-stream, Size: 4923 bytes --]

From cbe97587df4b660f56e420015222e4f3559588a2 Mon Sep 17 00:00:00 2001
From: "Ryan C. Scott" <ryan@5pmcasual.com>
Date: Wed, 25 Aug 2021 02:15:09 -0700
Subject: [PATCH] ob-core: Added option for attaching file from babel src block
 result

* ob-core.el (org-babel-format-result): Added `:results-param' option `attach' which when used with `file' will cause the resultant file path to be moved to the `org-attach-dir' for the node.
(org-babel-result-to-file): Added optional 3rd parameter `type' which will be used in place of "file" in link type, if present.
(org-babel-result-to-file-attachment): New function that moves the file at theh provided `result' path to the nodes attachment directory, creating it as necessary using `org-attach-dir'.  A new function was created to adhere to the design of the API and not complicated `org-babel-result-to-file' with the movement to the attachment directory.

* org-attach.el (org-attach-dir): Added autoload header to simplify dependencies necessary to support this feature (called in `org-babel-result-to-file-attachment').
---
 lisp/ob-core.el    | 31 ++++++++++++++++++++++++++-----
 lisp/org-attach.el |  1 +
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 857e03e55..c1d1b77e0 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2188,6 +2188,10 @@ silent -- no results are inserted into the Org buffer but
 file ---- the results are interpreted as a file path, and are
           inserted into the buffer using the Org file syntax.
 
+attach -- used with `file', will move the file at the path returned
+          by the source block to the nodes attachmen directory (as
+          reported by `org-attach-dir'.
+
 list ---- the results are interpreted as an Org list.
 
 raw ----- results are added directly to the Org file.  This is
@@ -2241,9 +2245,13 @@ INFO may provide the values of these header arguments (in the
   (cond ((stringp result)
 	 (setq result (org-no-properties result))
 	 (when (member "file" result-params)
-	   (setq result (org-babel-result-to-file
-			 result
-			 (org-babel--file-desc (nth 2 info) result)))))
+	   (setq result (if (member "attach" result-params)
+                            (org-babel-result-to-file-attachment
+                             result
+                             (org-babel--file-desc (nth 2 info) result))
+                          (org-babel-result-to-file
+			   result
+			   (org-babel--file-desc (nth 2 info) result))))))
 	((listp result))
 	(t (setq result (format "%S" result))))
   (if (and result-params (member "silent" result-params))
@@ -2548,7 +2556,7 @@ in the buffer."
 		 (line-beginning-position 2))
 	     (point))))))
 
-(defun org-babel-result-to-file (result &optional description)
+(defun org-babel-result-to-file (result &optional description type)
   "Convert RESULT into an Org link with optional DESCRIPTION.
 If the `default-directory' is different from the containing
 file's directory then expand relative links."
@@ -2559,7 +2567,8 @@ file's directory then expand relative links."
 			    (expand-file-name
 			     (file-name-directory
 			      (buffer-file-name (buffer-base-buffer)))))))))
-      (format "[[file:%s]%s]"
+      (format "[[%s:%s]%s]"
+              (or type "file")
 	      (if (and default-directory
 		       (buffer-file-name (buffer-base-buffer)) same-directory?)
 		  (if (eq org-link-file-path-type 'adaptive)
@@ -2571,6 +2580,18 @@ file's directory then expand relative links."
 		result)
 	      (if description (concat "[" description "]") "")))))
 
+(defun org-babel-result-to-file-attachment (result &optional description)
+  "Convert RESULT into an Org link after moving the provided path to the current node's attachment directory as reported by `org-attach-dir', using the optional DESCRIPTION if provided.
+See `org-babel-result-to-file' for further link generation details."
+
+  (let* ((dir (file-relative-name
+               (org-attach-dir t)))
+         (filename (file-name-nondirectory result))
+         (newname (format "%s/%s" dir filename)))
+
+    (rename-file result newname t)
+    (org-babel-result-to-file filename description "attachment")))
+
 (defun org-babel-examplify-region (beg end &optional results-switches inline)
   "Comment out region using the inline `==' or `: ' org example quote."
   (interactive "*r")
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index e8e8ade83..9f180255a 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -323,6 +323,7 @@ Shows a list of commands and prompts for another key to execute a command."
 	    (call-interactively command)
 	  (error "No such attachment command: %c" c))))))
 
+;;;###autoload
 (defun org-attach-dir (&optional create-if-not-exists-p no-fs-check)
   "Return the directory associated with the current outline node.
 First check for DIR property, then ID property.
-- 
2.32.0.windows.2


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

* Re: New source block results option for attaching file to node
  2021-08-26  8:48 New source block results option for attaching file to node Ryan Scott
@ 2021-08-31 11:15 ` Timothy
  2021-08-31 19:43   ` Ryan Scott
  0 siblings, 1 reply; 18+ messages in thread
From: Timothy @ 2021-08-31 11:15 UTC (permalink / raw)
  To: Ryan Scott; +Cc: emacs-orgmode


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

Hi Ryan,

Thanks for submitting your first patch to Org! 🎉

Regarding the purpose of the patch, I take it this is useful with source blocks
that return a file patch and should be added as an attachment? Would you mind
expanding on this use case? Oh, and `org-attach-dir' doesn’t show up a function or
variable for me, I take it you meant something else?

Lastly, with your commit message, you’ve clearly looked at the requested commit
message format 😊. There’s the odd typo (“theh”) and the line length is too
long. It’s good if you hard line-wrap to 72 characters (if you use Magit, this
should happen automatically FYI). Other than that it looks good to me.

All the best,
Timothy

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

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

* Re: New source block results option for attaching file to node
  2021-08-31 11:15 ` Timothy
@ 2021-08-31 19:43   ` Ryan Scott
  2021-09-01 14:45     ` Ihor Radchenko
  0 siblings, 1 reply; 18+ messages in thread
From: Ryan Scott @ 2021-08-31 19:43 UTC (permalink / raw)
  To: Timothy; +Cc: emacs-orgmode

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

Great. Yeah I tried to adhere to the commit format the best I could.
org-attach-dir is a function for me (latest org pulled using straight.el)
org/lisp/org-attach.el:327.

The primary use case is src blocks that generate files, in my case usually
gnuplot or graphviz, and return a file path. With a collection of org files
in a directory, organization can get messy, and creating an organizational
scheme essentially recreates the attachment directory design.

Another approach would be to instead only modify org to have hooks (or any
other callback mechanism really) that are run on link insertion and have
access to the result-params for the block. The rest of this could then be a
separate package easily enough. Would that be a better approach as it would
allow the org core to not be so tightly coupled to org-attach?

I'm using magit; I just don't normally restrain myself to the line length.
I'll make sure to do that for submitted patches here.

In terms of this mailing list and overall contribution process, how best to
remedy things for the patch? Just modify it and reply with the modified
patch as an attachment?

On Tue, Aug 31, 2021 at 4:24 AM Timothy <tecosaur@gmail.com> wrote:

> Hi Ryan,
>
> Thanks for submitting your first patch to Org! 🎉
>
> Regarding the purpose of the patch, I take it this is useful with source
> blocks that return a file patch and should be added as an attachment? Would
> you mind expanding on this use case? Oh, and org-attach-dir doesn’t show
> up a function or variable for me, I take it you meant something else?
>
> Lastly, with your commit message, you’ve clearly looked at the requested
> commit message format 😊. There’s the odd typo (“theh”) and the line length
> is too long. It’s good if you hard line-wrap to 72 characters (if you use
> Magit, this should happen automatically FYI). Other than that it looks
> good to me.
>
> All the best,
> *Timothy*
>
> * From*: Ryan Scott <%22Ryan+Scott%22+%3Cryan@vicarious-living.com%3E>
> * Subject*: New source block results option for attaching file to node
> * To*: emacs-orgmode@gnu.org
> <%22emacs-orgmode@gnu.org%22+%3Cemacs-orgmode@gnu.org%3E>
> * Date*: Thu, 26 Aug 2021 16:48:50 +0800
> An additional option for use with ":results file" that moves the returned
> path to the node attachment directory (as returned by org-attach-dir),
> creating it if necessary.
>
> First time submitting a patch. Any feedback is appreciated.
>
> -ryan
>
>

[-- Attachment #2: Type: text/html, Size: 5289 bytes --]

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

* Re: New source block results option for attaching file to node
  2021-08-31 19:43   ` Ryan Scott
@ 2021-09-01 14:45     ` Ihor Radchenko
  2021-09-01 20:01       ` Ryan Scott
  0 siblings, 1 reply; 18+ messages in thread
From: Ihor Radchenko @ 2021-09-01 14:45 UTC (permalink / raw)
  To: Ryan Scott; +Cc: emacs-orgmode, Timothy

Ryan Scott <ryan@vicarious-living.com> writes:

The patch looks fine for me except a typo:

> +          by the source block to the nodes attachmen directory (as
                                              ^attachment

> org-attach-dir is a function for me (latest org pulled using straight.el)
> org/lisp/org-attach.el:327.

Timothy probably does not have (require 'org-attach) in his personal
config. However, it should not be an issue for your patch with the
autoload you added.

> The primary use case is src blocks that generate files, in my case usually
> gnuplot or graphviz, and return a file path. With a collection of org files
> in a directory, organization can get messy, and creating an organizational
> scheme essentially recreates the attachment directory design.

I am also using attach directories for gnuplot output. Your approach is
fine, but what about input directory? I find it a bit awkward to store
input files alongside with the main .org file, while keeping the output
images as attachments.

I personally prefer to set the working dir for gnuplot like

#+begin_src gnuplot :dir (org-attach-dir)

With my approach, both the input and output files are going to be in the
attach dir.

I even go as far as making attach dir my default directory of all the
code blocks.

Though your patch may be useful when input directory is read-only or
even remote.

> Another approach would be to instead only modify org to have hooks (or any
> other callback mechanism really) that are run on link insertion and have
> access to the result-params for the block. The rest of this could then be a
> separate package easily enough. Would that be a better approach as it would
> allow the org core to not be so tightly coupled to org-attach?

org-attach is in the Org core. It should not be a problem supporting
org-attach in org babel.

> I'm using magit; I just don't normally restrain myself to the line length.
> I'll make sure to do that for submitted patches here.

You may find flycheck-mode useful to hint things like line length.

> In terms of this mailing list and overall contribution process, how best to
> remedy things for the patch? Just modify it and reply with the modified
> patch as an attachment?

Yep. Just submit the updated patch. Preferably, also add [PATCH] at the
beginning of the message topic. Then, the patch will also be shown in
updates.orgmode.org

Best,
Ihor


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

* Re: New source block results option for attaching file to node
  2021-09-01 14:45     ` Ihor Radchenko
@ 2021-09-01 20:01       ` Ryan Scott
  2021-09-02  7:40         ` [PATCH] " Ryan Scott
  0 siblings, 1 reply; 18+ messages in thread
From: Ryan Scott @ 2021-09-01 20:01 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode, Timothy

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

I hadn't thought about input directories much as my usage of
graphviz/gnuplots is through [essentially] DSLs that I made for them, so
the blocks are actually elisp.
Perhaps a convenient way of setting the working directory to the attachment
directory per-block makes sense?

My own personal coding style doesn't include a hard line limit, so it just
wasn't on my mind.

I'll get my patch updated and submitted shortly. Thanks for the help!

On Wed, Sep 1, 2021 at 7:44 AM Ihor Radchenko <yantar92@gmail.com> wrote:

> Ryan Scott <ryan@vicarious-living.com> writes:
>
> The patch looks fine for me except a typo:
>
> > +          by the source block to the nodes attachmen directory (as
>                                               ^attachment
>
> > org-attach-dir is a function for me (latest org pulled using straight.el)
> > org/lisp/org-attach.el:327.
>
> Timothy probably does not have (require 'org-attach) in his personal
> config. However, it should not be an issue for your patch with the
> autoload you added.
>
> > The primary use case is src blocks that generate files, in my case
> usually
> > gnuplot or graphviz, and return a file path. With a collection of org
> files
> > in a directory, organization can get messy, and creating an
> organizational
> > scheme essentially recreates the attachment directory design.
>
> I am also using attach directories for gnuplot output. Your approach is
> fine, but what about input directory? I find it a bit awkward to store
> input files alongside with the main .org file, while keeping the output
> images as attachments.
>
> I personally prefer to set the working dir for gnuplot like
>
> #+begin_src gnuplot :dir (org-attach-dir)
>
> With my approach, both the input and output files are going to be in the
> attach dir.
>
> I even go as far as making attach dir my default directory of all the
> code blocks.
>
> Though your patch may be useful when input directory is read-only or
> even remote.
>
> > Another approach would be to instead only modify org to have hooks (or
> any
> > other callback mechanism really) that are run on link insertion and have
> > access to the result-params for the block. The rest of this could then
> be a
> > separate package easily enough. Would that be a better approach as it
> would
> > allow the org core to not be so tightly coupled to org-attach?
>
> org-attach is in the Org core. It should not be a problem supporting
> org-attach in org babel.
>
> > I'm using magit; I just don't normally restrain myself to the line
> length.
> > I'll make sure to do that for submitted patches here.
>
> You may find flycheck-mode useful to hint things like line length.
>
> > In terms of this mailing list and overall contribution process, how best
> to
> > remedy things for the patch? Just modify it and reply with the modified
> > patch as an attachment?
>
> Yep. Just submit the updated patch. Preferably, also add [PATCH] at the
> beginning of the message topic. Then, the patch will also be shown in
> updates.orgmode.org
>
> Best,
> Ihor
>

[-- Attachment #2: Type: text/html, Size: 3832 bytes --]

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

* [PATCH] Re: New source block results option for attaching file to node
  2021-09-01 20:01       ` Ryan Scott
@ 2021-09-02  7:40         ` Ryan Scott
  2021-09-02 13:44           ` Greg Minshall
  0 siblings, 1 reply; 18+ messages in thread
From: Ryan Scott @ 2021-09-02  7:40 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode, Timothy


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

Updated patch; fixed typos and wrapped the commit message to 72 characters

Thinking about the input files issue some more, I wonder if an attach
keyword wouldn't better function as setting the working directory to the
node's attachment directory and then fixing up any inserted link to use
"attachment:" if it's relative to that.

I've been working with this for a bit in my own workflow and it's been
useful, but I'll see about maybe experimenting with some other approaches
as well. Moving the referenced file to the attachment directory never felt
completely right to me.

On Wed, Sep 1, 2021 at 1:01 PM Ryan Scott <ryan@vicarious-living.com> wrote:

> I hadn't thought about input directories much as my usage of
> graphviz/gnuplots is through [essentially] DSLs that I made for them, so
> the blocks are actually elisp.
> Perhaps a convenient way of setting the working directory to the
> attachment directory per-block makes sense?
>
> My own personal coding style doesn't include a hard line limit, so it just
> wasn't on my mind.
>
> I'll get my patch updated and submitted shortly. Thanks for the help!
>
> On Wed, Sep 1, 2021 at 7:44 AM Ihor Radchenko <yantar92@gmail.com> wrote:
>
>> Ryan Scott <ryan@vicarious-living.com> writes:
>>
>> The patch looks fine for me except a typo:
>>
>> > +          by the source block to the nodes attachmen directory (as
>>                                               ^attachment
>>
>> > org-attach-dir is a function for me (latest org pulled using
>> straight.el)
>> > org/lisp/org-attach.el:327.
>>
>> Timothy probably does not have (require 'org-attach) in his personal
>> config. However, it should not be an issue for your patch with the
>> autoload you added.
>>
>> > The primary use case is src blocks that generate files, in my case
>> usually
>> > gnuplot or graphviz, and return a file path. With a collection of org
>> files
>> > in a directory, organization can get messy, and creating an
>> organizational
>> > scheme essentially recreates the attachment directory design.
>>
>> I am also using attach directories for gnuplot output. Your approach is
>> fine, but what about input directory? I find it a bit awkward to store
>> input files alongside with the main .org file, while keeping the output
>> images as attachments.
>>
>> I personally prefer to set the working dir for gnuplot like
>>
>> #+begin_src gnuplot :dir (org-attach-dir)
>>
>> With my approach, both the input and output files are going to be in the
>> attach dir.
>>
>> I even go as far as making attach dir my default directory of all the
>> code blocks.
>>
>> Though your patch may be useful when input directory is read-only or
>> even remote.
>>
>> > Another approach would be to instead only modify org to have hooks (or
>> any
>> > other callback mechanism really) that are run on link insertion and have
>> > access to the result-params for the block. The rest of this could then
>> be a
>> > separate package easily enough. Would that be a better approach as it
>> would
>> > allow the org core to not be so tightly coupled to org-attach?
>>
>> org-attach is in the Org core. It should not be a problem supporting
>> org-attach in org babel.
>>
>> > I'm using magit; I just don't normally restrain myself to the line
>> length.
>> > I'll make sure to do that for submitted patches here.
>>
>> You may find flycheck-mode useful to hint things like line length.
>>
>> > In terms of this mailing list and overall contribution process, how
>> best to
>> > remedy things for the patch? Just modify it and reply with the modified
>> > patch as an attachment?
>>
>> Yep. Just submit the updated patch. Preferably, also add [PATCH] at the
>> beginning of the message topic. Then, the patch will also be shown in
>> updates.orgmode.org
>>
>> Best,
>> Ihor
>>
>

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

[-- Attachment #2: 0001-ob-core-Added-option-for-attaching-file-from-babel-s.patch --]
[-- Type: application/octet-stream, Size: 4922 bytes --]

From cbe97587df4b660f56e420015222e4f3559588a2 Mon Sep 17 00:00:00 2001
From: "Ryan C. Scott" <ryan@5pmcasual.com>
Date: Wed, 25 Aug 2021 02:15:09 -0700
Subject: [PATCH] ob-core: Added option for attaching file from babel
src block result

* ob-core.el (org-babel-format-result): Added `:results-param' option
`attach' which when used with `file' will cause the resultant file path
to be moved to the `org-attach-dir' for the node.
(org-babel-result-to-file): Added optional 3rd parameter `type' which
will be used in place of "file" in link type, if present.
(org-babel-result-to-file-attachment): New function that moves the file
at the provided `result' path to the nodes attachment directory,
creating it as necessary using `org-attach-dir'.  A new function was
created to adhere to the design of the API and not complicated
`org-babel-result-to-file' with the movement to the attachment
directory.

* org-attach.el (org-attach-dir): Added autoload header to simplify
dependencies necessary to support this feature (called in
`org-babel-result-to-file-attachment').
---
 lisp/ob-core.el    | 31 ++++++++++++++++++++++++++-----
 lisp/org-attach.el |  1 +
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 857e03e55..c1d1b77e0 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2188,6 +2188,10 @@ silent -- no results are inserted into the Org buffer but
 file ---- the results are interpreted as a file path, and are
           inserted into the buffer using the Org file syntax.
 
+attach -- used with `file', will move the file at the path returned
+          by the source block to the nodes attachment directory (as
+          reported by `org-attach-dir'.
+
 list ---- the results are interpreted as an Org list.
 
 raw ----- results are added directly to the Org file.  This is
@@ -2241,9 +2245,13 @@ INFO may provide the values of these header arguments (in the
   (cond ((stringp result)
 	 (setq result (org-no-properties result))
 	 (when (member "file" result-params)
-	   (setq result (org-babel-result-to-file
-			 result
-			 (org-babel--file-desc (nth 2 info) result)))))
+	   (setq result (if (member "attach" result-params)
+                            (org-babel-result-to-file-attachment
+                             result
+                             (org-babel--file-desc (nth 2 info) result))
+                          (org-babel-result-to-file
+			   result
+			   (org-babel--file-desc (nth 2 info) result))))))
 	((listp result))
 	(t (setq result (format "%S" result))))
   (if (and result-params (member "silent" result-params))
@@ -2548,7 +2556,7 @@ in the buffer."
 		 (line-beginning-position 2))
 	     (point))))))
 
-(defun org-babel-result-to-file (result &optional description)
+(defun org-babel-result-to-file (result &optional description type)
   "Convert RESULT into an Org link with optional DESCRIPTION.
 If the `default-directory' is different from the containing
 file's directory then expand relative links."
@@ -2559,7 +2567,8 @@ file's directory then expand relative links."
 			    (expand-file-name
 			     (file-name-directory
 			      (buffer-file-name (buffer-base-buffer)))))))))
-      (format "[[file:%s]%s]"
+      (format "[[%s:%s]%s]"
+              (or type "file")
 	      (if (and default-directory
 		       (buffer-file-name (buffer-base-buffer)) same-directory?)
 		  (if (eq org-link-file-path-type 'adaptive)
@@ -2571,6 +2580,18 @@ file's directory then expand relative links."
 		result)
 	      (if description (concat "[" description "]") "")))))
 
+(defun org-babel-result-to-file-attachment (result &optional description)
+  "Convert RESULT into an Org link after moving the provided path to the current node's attachment directory as reported by `org-attach-dir', using the optional DESCRIPTION if provided.
+See `org-babel-result-to-file' for further link generation details."
+
+  (let* ((dir (file-relative-name
+               (org-attach-dir t)))
+         (filename (file-name-nondirectory result))
+         (newname (format "%s/%s" dir filename)))
+
+    (rename-file result newname t)
+    (org-babel-result-to-file filename description "attachment")))
+
 (defun org-babel-examplify-region (beg end &optional results-switches inline)
   "Comment out region using the inline `==' or `: ' org example quote."
   (interactive "*r")
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index e8e8ade83..9f180255a 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -323,6 +323,7 @@ Shows a list of commands and prompts for another key to execute a command."
 	    (call-interactively command)
 	  (error "No such attachment command: %c" c))))))
 
+;;;###autoload
 (defun org-attach-dir (&optional create-if-not-exists-p no-fs-check)
   "Return the directory associated with the current outline node.
 First check for DIR property, then ID property.
-- 
2.32.0.windows.2


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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-09-02  7:40         ` [PATCH] " Ryan Scott
@ 2021-09-02 13:44           ` Greg Minshall
  2021-09-03  3:10             ` Ihor Radchenko
  0 siblings, 1 reply; 18+ messages in thread
From: Greg Minshall @ 2021-09-02 13:44 UTC (permalink / raw)
  To: Ryan Scott; +Cc: emacs-orgmode, Ihor Radchenko, Timothy

Ryan, et al.,

i'm not entirely following the discussion, as i don't use "attaching".
but, fwiw, if i did, i can imagine wanting to have input files and
output files in separate directories.  (for ease in "make clean", if for
no other conceptual reason.)  (but, probably i don't understand.)

cheers, Greg


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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-09-02 13:44           ` Greg Minshall
@ 2021-09-03  3:10             ` Ihor Radchenko
  2021-09-03  3:28               ` Ryan Scott
  2021-10-05  0:04               ` Christopher M. Miles
  0 siblings, 2 replies; 18+ messages in thread
From: Ihor Radchenko @ 2021-09-03  3:10 UTC (permalink / raw)
  To: Greg Minshall; +Cc: Ryan Scott, emacs-orgmode, Timothy

Greg Minshall <minshall@umich.edu> writes:

> i can imagine wanting to have input files and
> output files in separate directories.  (for ease in "make clean", if for
> no other conceptual reason.)  (but, probably i don't understand.)

Makes sense. Currently, there is :dir header arg to set working
directory (aka input files directory). Maybe we can introduce something
like :results-dir header arg to set the output directory? It's value can
be a directory path or symbol 'attach.

`:results file :results-dir 'attach` will be equivalent of
`:results file attach` in the patch proposed by Ryan Scott.

WDYT?

Best,
Ihor


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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-09-03  3:10             ` Ihor Radchenko
@ 2021-09-03  3:28               ` Ryan Scott
  2021-09-05 13:22                 ` Ihor Radchenko
  2021-10-05  0:04               ` Christopher M. Miles
  1 sibling, 1 reply; 18+ messages in thread
From: Ryan Scott @ 2021-09-03  3:28 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Greg Minshall, emacs-orgmode, Timothy

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

That's starting to sound pretty good.

It might make sense to fix up inserted "file:" links that are under the
attachment directory to be "attachment:" style links by default anyway, no?
Then just being able to set the working directory to the attachment
directory easily would get the rest of the way there.

So I suppose that would then mean having the :dir header accept the symbol
`attach' or something like that?
I'll play around and see what that looks like.

On Thu, Sep 2, 2021 at 8:09 PM Ihor Radchenko <yantar92@gmail.com> wrote:

> Greg Minshall <minshall@umich.edu> writes:
>
> > i can imagine wanting to have input files and
> > output files in separate directories.  (for ease in "make clean", if for
> > no other conceptual reason.)  (but, probably i don't understand.)
>
> Makes sense. Currently, there is :dir header arg to set working
> directory (aka input files directory). Maybe we can introduce something
> like :results-dir header arg to set the output directory? It's value can
> be a directory path or symbol 'attach.
>
> `:results file :results-dir 'attach` will be equivalent of
> `:results file attach` in the patch proposed by Ryan Scott.
>
> WDYT?
>
> Best,
> Ihor
>

[-- Attachment #2: Type: text/html, Size: 1746 bytes --]

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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-09-03  3:28               ` Ryan Scott
@ 2021-09-05 13:22                 ` Ihor Radchenko
  2021-09-05 13:56                   ` Ryan Scott
  0 siblings, 1 reply; 18+ messages in thread
From: Ihor Radchenko @ 2021-09-05 13:22 UTC (permalink / raw)
  To: Ryan Scott; +Cc: Greg Minshall, emacs-orgmode, Timothy

Ryan Scott <ryan@vicarious-living.com> writes:

> It might make sense to fix up inserted "file:" links that are under the
> attachment directory to be "attachment:" style links by default anyway, no?
> Then just being able to set the working directory to the attachment
> directory easily would get the rest of the way there.

I am not sure. If the user explicitly states that :dir is the attachment
dir, it would make sense. However, what if the :dir is set explicitly
like below?

* Headline
:PROPERTIES:
:DIR: /actual/literal/path/to/attachment/dir
:END:

#+begin_src emacs-lisp :dir /actual/literal/path/to/attachment/dir
...

#+RESULTS:
attachment:...

The results will be indeed inside the attachment directory. However, the
:DIR: property may be changed at some point and the existing attachment:
link will not point to real file.

> So I suppose that would then mean having the :dir header accept the symbol
> `attach' or something like that?
> I'll play around and see what that looks like.

The above example should lead to more expected behaviour if the user
explicitly states that :dir is the attachment dir (even if it is going
to be changed in future):

* Headline
:PROPERTIES:
:DIR: /actual/literal/path/to/attachment/dir
:END:

#+begin_src emacs-lisp :dir 'attach
...

#+RESULTS:
attachment:...

Best,
Ihor


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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-09-05 13:22                 ` Ihor Radchenko
@ 2021-09-05 13:56                   ` Ryan Scott
  2021-09-10  1:04                     ` Ryan Scott
  0 siblings, 1 reply; 18+ messages in thread
From: Ryan Scott @ 2021-09-05 13:56 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Greg Minshall, emacs-orgmode, Timothy

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

Yeah your second example is what I'm thinking. It makes this all a fairly
concise extension of that existing mechanism and does away with the file
move after execution.

On Sun, Sep 5, 2021, 06:21 Ihor Radchenko <yantar92@gmail.com> wrote:

> Ryan Scott <ryan@vicarious-living.com> writes:
>
> > It might make sense to fix up inserted "file:" links that are under the
> > attachment directory to be "attachment:" style links by default anyway,
> no?
> > Then just being able to set the working directory to the attachment
> > directory easily would get the rest of the way there.
>
> I am not sure. If the user explicitly states that :dir is the attachment
> dir, it would make sense. However, what if the :dir is set explicitly
> like below?
>
> * Headline
> :PROPERTIES:
> :DIR: /actual/literal/path/to/attachment/dir
> :END:
>
> #+begin_src emacs-lisp :dir /actual/literal/path/to/attachment/dir
> ...
>
> #+RESULTS:
> attachment:...
>
> The results will be indeed inside the attachment directory. However, the
> :DIR: property may be changed at some point and the existing attachment:
> link will not point to real file.
>
> > So I suppose that would then mean having the :dir header accept the
> symbol
> > `attach' or something like that?
> > I'll play around and see what that looks like.
>
> The above example should lead to more expected behaviour if the user
> explicitly states that :dir is the attachment dir (even if it is going
> to be changed in future):
>
> * Headline
> :PROPERTIES:
> :DIR: /actual/literal/path/to/attachment/dir
> :END:
>
> #+begin_src emacs-lisp :dir 'attach
> ...
>
> #+RESULTS:
> attachment:...
>
> Best,
> Ihor
>

[-- Attachment #2: Type: text/html, Size: 2204 bytes --]

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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-09-05 13:56                   ` Ryan Scott
@ 2021-09-10  1:04                     ` Ryan Scott
  2021-09-10  6:26                       ` Timothy
  2021-10-02  8:32                       ` Ihor Radchenko
  0 siblings, 2 replies; 18+ messages in thread
From: Ryan Scott @ 2021-09-10  1:04 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Greg Minshall, emacs-orgmode, Timothy


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

Okay, Had some time to put into this. Much happier with this approach as it
doesn't require any file moving and generally leaves src blocks to their
own devices.
The short version is that specifying ":dir 'attach" for a block uses the
directory from (org-attach-dir) as its working directory and any generated
path that is a descendant of that directory will be converted to an
"attachment:" link.

ob-core.el/babel: Special handling for attachment links in src blocks

* ob-core.el (org-babel-execute-src-block): Specifying the symbol
'attach` as the value of the `:dir' header now functions as
":dir (org-attach-dir)"
(org-babel-result-to-file): Optional `TYPE' argument accepts symbol
'attachment` to fixup up paths under `DEFAULT-DIRECTORY' and use the
link type "attachment:" when that is detected.
(org-babel-insert-result): Pass symbol `attachment' as `TYPE' to
`org-babel-result-to-file' when header `:dir' is set to symbol
`attach'
(org-babel-load-in-session, org-babel-initiate-session) ":dir 'attach"
sets `default-directory' with "(org-attach-dir t)"
* org-attach.el (org-attach-dir): Added autoload header to simplify
dependencies necessary to support this feature (called in
`org-babel-execute-src-block').

On Sun, Sep 5, 2021 at 6:56 AM Ryan Scott <ryan@vicarious-living.com> wrote:

> Yeah your second example is what I'm thinking. It makes this all a fairly
> concise extension of that existing mechanism and does away with the file
> move after execution.
>
> On Sun, Sep 5, 2021, 06:21 Ihor Radchenko <yantar92@gmail.com> wrote:
>
>> Ryan Scott <ryan@vicarious-living.com> writes:
>>
>> > It might make sense to fix up inserted "file:" links that are under the
>> > attachment directory to be "attachment:" style links by default anyway,
>> no?
>> > Then just being able to set the working directory to the attachment
>> > directory easily would get the rest of the way there.
>>
>> I am not sure. If the user explicitly states that :dir is the attachment
>> dir, it would make sense. However, what if the :dir is set explicitly
>> like below?
>>
>> * Headline
>> :PROPERTIES:
>> :DIR: /actual/literal/path/to/attachment/dir
>> :END:
>>
>> #+begin_src emacs-lisp :dir /actual/literal/path/to/attachment/dir
>> ...
>>
>> #+RESULTS:
>> attachment:...
>>
>> The results will be indeed inside the attachment directory. However, the
>> :DIR: property may be changed at some point and the existing attachment:
>> link will not point to real file.
>>
>> > So I suppose that would then mean having the :dir header accept the
>> symbol
>> > `attach' or something like that?
>> > I'll play around and see what that looks like.
>>
>> The above example should lead to more expected behaviour if the user
>> explicitly states that :dir is the attachment dir (even if it is going
>> to be changed in future):
>>
>> * Headline
>> :PROPERTIES:
>> :DIR: /actual/literal/path/to/attachment/dir
>> :END:
>>
>> #+begin_src emacs-lisp :dir 'attach
>> ...
>>
>> #+RESULTS:
>> attachment:...
>>
>> Best,
>> Ihor
>>
>

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

[-- Attachment #2: 0001-ob-core.el-babel-Special-handling-for-attachment-lin.patch --]
[-- Type: application/octet-stream, Size: 6789 bytes --]

From 4d489da66cf6f4d44a320e2d3ccb7025aa8ada6d Mon Sep 17 00:00:00 2001
From: "Ryan C. Scott" <ryan@5pmcasual.com>
Date: Thu, 9 Sep 2021 17:19:34 -0700
Subject: [PATCH] ob-core.el/babel: Special handling for attachment links in
src block

* ob-core.el (org-babel-execute-src-block): Specifying the symbol
'attach` as the value of the `:dir' header now functions as
":dir (org-attach-dir)"
(org-babel-result-to-file): Optional `TYPE' argument accepts symbol
'attachment` to fixup up paths under `DEFAULT-DIRECTORY' and use the
link type "attachment:" when that is detected.
(org-babel-insert-result): Pass symbol `attachment' as `TYPE' to
`org-babel-result-to-file' when header `:dir' is set to symbol
`attach'
(org-babel-load-in-session, org-babel-initiate-session) ":dir 'attach"
sets `default-directory' with "(org-attach-dir t)"
* org-attach.el (org-attach-dir): Added autoload header to simplify
dependencies necessary to support this feature (called in
`org-babel-execute-src-block').
---
 lisp/ob-core.el    | 72 +++++++++++++++++++++++++++++++---------------
 lisp/org-attach.el |  1 +
 2 files changed, 50 insertions(+), 23 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 384c06c9a..90e454319 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -704,6 +704,9 @@ block."
 		 (mkdirp (cdr (assq :mkdirp params)))
 		 (default-directory
 		   (cond
+                    ((eq dir 'attach)
+                     (file-name-as-directory
+                      (org-attach-dir t)))
 		    ((not dir) default-directory)
 		    ((member mkdirp '("no" "nil" nil))
 		     (file-name-as-directory (expand-file-name dir)))
@@ -925,7 +928,10 @@ session."
          (session (cdr (assq :session params)))
 	 (dir (cdr (assq :dir params)))
 	 (default-directory
-	   (or (and dir (file-name-as-directory dir)) default-directory))
+	   (or (and dir (if (eq dir 'attach)
+                            (org-attach-dir t)
+                          (file-name-as-directory dir)))
+               default-directory))
 	 (cmd (intern (concat "org-babel-load-session:" lang))))
     (unless (fboundp cmd)
       (error "No org-babel-load-session function for %s!" lang))
@@ -946,7 +952,10 @@ the session.  Copy the body of the code block to the kill ring."
          (session (cdr (assq :session params)))
 	 (dir (cdr (assq :dir params)))
 	 (default-directory
-	   (or (and dir (file-name-as-directory dir)) default-directory))
+	   (or (and dir (if (eq dir 'attach)
+                            (org-attach-dir t)
+                          (file-name-as-directory dir)))
+               default-directory))
 	 (init-cmd (intern (format "org-babel-%s-initiate-session" lang)))
 	 (prep-cmd (intern (concat "org-babel-prep-session:" lang))))
     (when (and (stringp session) (string= session "none"))
@@ -2241,9 +2250,12 @@ INFO may provide the values of these header arguments (in the
   (cond ((stringp result)
 	 (setq result (org-no-properties result))
 	 (when (member "file" result-params)
-	   (setq result (org-babel-result-to-file
-			 result
-			 (org-babel--file-desc (nth 2 info) result)))))
+	   (setq result (let ((params (nth 2 info)))
+                          (org-babel-result-to-file
+			   result
+			   (org-babel--file-desc params result)
+                           (when (equal (cdr (assq :dir params)) 'attach)
+                             'attachment))))))
 	((listp result))
 	(t (setq result (format "%S" result))))
   (if (and result-params (member "silent" result-params))
@@ -2548,27 +2560,41 @@ in the buffer."
 		 (line-beginning-position 2))
 	     (point))))))
 
-(defun org-babel-result-to-file (result &optional description)
+(defun org-babel-result-to-file (result &optional description type)
   "Convert RESULT into an Org link with optional DESCRIPTION.
 If the `default-directory' is different from the containing
-file's directory then expand relative links."
+file's directory then expand relative links.
+If the optional TYPE is passed as 'attachment` and the path is a descendant of the DEFAULT-DIRECTORY, the generated link will be specified as an an \"attachment:\" style link"
   (when (stringp result)
-    (let ((same-directory?
-	   (and (buffer-file-name (buffer-base-buffer))
-		(not (string= (expand-file-name default-directory)
-			    (expand-file-name
-			     (file-name-directory
-			      (buffer-file-name (buffer-base-buffer)))))))))
-      (format "[[file:%s]%s]"
-	      (if (and default-directory
-		       (buffer-file-name (buffer-base-buffer)) same-directory?)
-		  (if (eq org-link-file-path-type 'adaptive)
-		      (file-relative-name
-		       (expand-file-name result default-directory)
-		       (file-name-directory
-			(buffer-file-name (buffer-base-buffer))))
-		    (expand-file-name result default-directory))
-		result)
+    (let* ((result-file-name (expand-file-name result))
+           (base-file-name (buffer-file-name (buffer-base-buffer)))
+           (same-directory?
+	    (and base-file-name
+	         (not (string= (expand-file-name default-directory)
+			       (expand-file-name
+			        (file-name-directory
+			         base-file-name))))))
+           (request-attachment (eq type 'attachment))
+           (attach-dir-len (when request-attachment (length default-directory)))
+           (in-attach-dir (when (and request-attachment (> (length result-file-name) attach-dir-len))
+                            (string=
+                             (substring result-file-name 0 attach-dir-len)
+                             default-directory))))
+      (format "[[%s:%s]%s]"
+              (pcase type
+                ('attachment "attachment")
+                (_ "file"))
+              (if (and request-attachment in-attach-dir)
+                  (file-relative-name result-file-name)
+	        (if (and default-directory
+		         base-file-name same-directory?)
+		    (if (eq org-link-file-path-type 'adaptive)
+		        (file-relative-name
+		         result-file-name
+                         (file-name-directory
+			  base-file-name))
+		      result-file-name)
+		  result))
 	      (if description (concat "[" description "]") "")))))
 
 (defun org-babel-examplify-region (beg end &optional results-switches inline)
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index f18453103..b06b85360 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -323,6 +323,7 @@ Shows a list of commands and prompts for another key to execute a command."
 	    (call-interactively command)
 	  (error "No such attachment command: %c" c))))))
 
+;;;###autoload
 (defun org-attach-dir (&optional create-if-not-exists-p no-fs-check)
   "Return the directory associated with the current outline node.
 First check for DIR property, then ID property.
-- 
2.32.0.windows.2


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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-09-10  1:04                     ` Ryan Scott
@ 2021-09-10  6:26                       ` Timothy
  2021-10-02  8:32                       ` Ihor Radchenko
  1 sibling, 0 replies; 18+ messages in thread
From: Timothy @ 2021-09-10  6:26 UTC (permalink / raw)
  To: Ryan Scott; +Cc: Greg Minshall, emacs-orgmode, Ihor Radchenko


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

Hi Ryan,

I’ve just had a glance, but this looks much better to me than what was proposed
earlier 👍. Hopefully we’ll be able to get some feedback on this from others,
and then see it merged 🙂.

All the best,
Timothy

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

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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-09-10  1:04                     ` Ryan Scott
  2021-09-10  6:26                       ` Timothy
@ 2021-10-02  8:32                       ` Ihor Radchenko
  2021-10-02  9:39                         ` Ryan Scott
  1 sibling, 1 reply; 18+ messages in thread
From: Ihor Radchenko @ 2021-10-02  8:32 UTC (permalink / raw)
  To: Ryan Scott; +Cc: Greg Minshall, emacs-orgmode, Timothy

Ryan Scott <ryan@vicarious-living.com> writes:

>  	 (default-directory
> -	   (or (and dir (file-name-as-directory dir)) default-directory))
> +	   (or (and dir (if (eq dir 'attach)
> +                            (org-attach-dir t)
> +                          (file-name-as-directory dir)))
> +               default-directory))

This does not always work.  Some ob-*.el code (namely, ob-lisp have the
following:

(let ((dir (if (assq :dir params)
               (cdr (assq :dir params))
              default-directory)))

As you can see, :dir parameter is overriding default-directory.  If :dir
is set to symbol 'attach, execution will fail.

I think that you also need to override :dir in the parameter list and
put actual path to attachment dir instead of symbol.  That way, we will
not need to change every possible ob-*.el implementation to account for
new 'attach option.

Also, marking this as patch.

Best,
Ihor


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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-10-02  8:32                       ` Ihor Radchenko
@ 2021-10-02  9:39                         ` Ryan Scott
  0 siblings, 0 replies; 18+ messages in thread
From: Ryan Scott @ 2021-10-02  9:39 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Greg Minshall, emacs-orgmode, Timothy

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

Would it be better then as a new option entirely that sets the default
directory to the attachment directory and results in attachment links for
any inserted paths that are under that?

The attachment link detection could possibly be default behavior for link
insertion, but i can imagine that might have broader implications.

I also found and have a fix for my patch where the 'attach symbol gets
converted to a string when using #+call to call a block that is defined
with this option, which felt a little awkward in the code.

I'll try this as a standalone option and see how that feels. That would
carve out space for other options in handling attachments.

On Sat, Oct 2, 2021, 01:31 Ihor Radchenko <yantar92@gmail.com> wrote:

> Ryan Scott <ryan@vicarious-living.com> writes:
>
> >        (default-directory
> > -        (or (and dir (file-name-as-directory dir)) default-directory))
> > +        (or (and dir (if (eq dir 'attach)
> > +                            (org-attach-dir t)
> > +                          (file-name-as-directory dir)))
> > +               default-directory))
>
> This does not always work.  Some ob-*.el code (namely, ob-lisp have the
> following:
>
> (let ((dir (if (assq :dir params)
>                (cdr (assq :dir params))
>               default-directory)))
>
> As you can see, :dir parameter is overriding default-directory.  If :dir
> is set to symbol 'attach, execution will fail.
>
> I think that you also need to override :dir in the parameter list and
> put actual path to attachment dir instead of symbol.  That way, we will
> not need to change every possible ob-*.el implementation to account for
> new 'attach option.
>
> Also, marking this as patch.
>
> Best,
> Ihor
>

[-- Attachment #2: Type: text/html, Size: 2402 bytes --]

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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-09-03  3:10             ` Ihor Radchenko
  2021-09-03  3:28               ` Ryan Scott
@ 2021-10-05  0:04               ` Christopher M. Miles
  2021-10-05  1:05                 ` Ryan Scott
  1 sibling, 1 reply; 18+ messages in thread
From: Christopher M. Miles @ 2021-10-05  0:04 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Greg Minshall, Ryan Scott, emacs-orgmode, Timothy


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



Ihor Radchenko <yantar92@gmail.com> writes:

> Greg Minshall <minshall@umich.edu> writes:
>
>> i can imagine wanting to have input files and
>> output files in separate directories.  (for ease in "make clean", if for
>> no other conceptual reason.)  (but, probably i don't understand.)

I agree with this thought. We should separate two directories.

>
> Makes sense. Currently, there is :dir header arg to set working
> directory (aka input files directory). Maybe we can introduce something
> like :results-dir header arg to set the output directory? It's value can
> be a directory path or symbol 'attach.
>
> `:results file :results-dir 'attach` will be equivalent of
> `:results file attach` in the patch proposed by Ryan Scott.
>
> WDYT?

I agree with this idea. Use ~:results-dir 'attach~ is better.

Will the patch be updated?

>
> Best,
> Ihor



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

[-- Attachment #2: Type: text/plain, Size: 282 bytes --]


<#secure method=pgpmime mode=sign>
-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-10-05  0:04               ` Christopher M. Miles
@ 2021-10-05  1:05                 ` Ryan Scott
  2021-10-08  1:22                   ` Christopher M. Miles
  0 siblings, 1 reply; 18+ messages in thread
From: Ryan Scott @ 2021-10-05  1:05 UTC (permalink / raw)
  To: numbchild; +Cc: Greg Minshall, emacs-orgmode, Ihor Radchenko, Timothy

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

I've been working through a few different approaches. What's shaping up is
something more general, having a special value for directory parameters
(i.e. 'attach) and auto-detection of link paths that are in the attachment
directory.
The latest iterations don't move any files around, so can't actually
enforce the output directory. That makes it safer overall as with my
initial patch if you were to return a path to something you *didn't* want
moved to your attachment directory you might get very surprising results.

I'll post a new patch with a different approach in a little bit.

On Mon, Oct 4, 2021 at 5:06 PM Christopher M. Miles <numbchild@gmail.com>
wrote:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
> Greg Minshall <minshall@umich.edu> writes:
>>
>> i can imagine wanting to have input files and output files in separate
>>> directories. (for ease in "make clean", if for no other conceptual reason.)
>>> (but, probably i don't understand.)
>>>
>> I agree with this thought. We should separate two directories.
>
> Makes sense. Currently, there is :dir header arg to set working directory
>> (aka input files directory). Maybe we can introduce something like
>> :results-dir header arg to set the output directory? It's value can be a
>> directory path or symbol 'attach.
>>
>> `:results file :results-dir 'attach` will be equivalent of `:results file
>> attach` in the patch proposed by Ryan Scott.
>>
>> WDYT?
>>
> I agree with this idea. Use :results-dir 'attach is better.
>
> Will the patch be updated?
>
> Best, Ihor
>>
>
> <#secure method=pgpmime mode=sign>
> --
> [ stardiviner ]
>        I try to make every word tell the meaning that I want to express.
>
>        Blog: https://stardiviner.github.io/
>        IRC(freenode): stardiviner, Matrix: stardiviner
>        GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
>

[-- Attachment #2: Type: text/html, Size: 3264 bytes --]

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

* Re: [PATCH] Re: New source block results option for attaching file to node
  2021-10-05  1:05                 ` Ryan Scott
@ 2021-10-08  1:22                   ` Christopher M. Miles
  0 siblings, 0 replies; 18+ messages in thread
From: Christopher M. Miles @ 2021-10-08  1:22 UTC (permalink / raw)
  To: Ryan Scott; +Cc: Greg Minshall, emacs-orgmode, Ihor Radchenko, Timothy


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



Ryan Scott <ryan@vicarious-living.com> writes:

> I've been working through a few different approaches. What's shaping up is something more general, having a special value
> for directory parameters (i.e. 'attach) and auto-detection of link paths that are in the attachment directory.
> The latest iterations don't move any files around, so can't actually enforce the output directory. That makes it safer
> overall as with my initial patch if you were to return a path to something you didn't want moved to your attachment
> directory you might get very surprising results.

I used to created a similar function extension called "ob-clojure-literate.el" for ob-clojure.el.
One functionality is to save plotting result image to a header argument :dir specified directory.
But it's a little complicated. Then later I found another solution through *header argument evaluation*:

#+begin_src clojure :results file link :dir "data/images" :file "ob-clojure-incanter-move.png" :var dir=(concat (file-name-directory (buffer-file-name)) "data/images/")
(use '(incanter core io charts stats))
(import '(java.io File))

(def hist (histogram (sample-normal 1000)))
(save hist "ob-clojure-incanter-move.png")
(.renameTo (File. "ob-clojure-incanter-move.png") (File. (str dir "ob-clojure-incanter-move.png")))
#+end_src

But this code has a disadvantage:

This solution breaks Literate Programming tangling concept by introduced un-reimplemented variable ~dir~.

>
> I'll post a new patch with a different approach in a little bit.
>
> On Mon, Oct 4, 2021 at 5:06 PM Christopher M. Miles <numbchild@gmail.com> wrote:
>
>  Ihor Radchenko <yantar92@gmail.com> writes: 
>
>  Greg Minshall <minshall@umich.edu> writes: 
>
>  i can imagine wanting to have input files and output files in separate directories. (for ease in "make
>  clean", if for no other conceptual reason.) (but, probably i don't understand.) 
>
>  I agree with this thought. We should separate two directories. 
>
>  Makes sense. Currently, there is :dir header arg to set working directory (aka input files directory). Maybe we
>  can introduce something like :results-dir header arg to set the output directory? It's value can be a directory
>  path or symbol 'attach. 
>
>  `:results file :results-dir 'attach` will be equivalent of `:results file attach` in the patch proposed by Ryan
>  Scott. 
>
>  WDYT? 
>
>  I agree with this idea. Use :results-dir 'attach is better. 
>
>  Will the patch be updated? 
>
>  Best, Ihor 
>
>  <#secure method=pgpmime mode=sign>
>  -- 
>  [ stardiviner ]
>         I try to make every word tell the meaning that I want to express.
>
>         Blog: https://stardiviner.github.io/
>         IRC(freenode): stardiviner, Matrix: stardiviner
>         GPG: F09F650D7D674819892591401B5DF1C95AE89AC3



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

[-- Attachment #2: Type: text/plain, Size: 282 bytes --]


<#secure method=pgpmime mode=sign>
-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

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

end of thread, other threads:[~2021-10-08  1:34 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26  8:48 New source block results option for attaching file to node Ryan Scott
2021-08-31 11:15 ` Timothy
2021-08-31 19:43   ` Ryan Scott
2021-09-01 14:45     ` Ihor Radchenko
2021-09-01 20:01       ` Ryan Scott
2021-09-02  7:40         ` [PATCH] " Ryan Scott
2021-09-02 13:44           ` Greg Minshall
2021-09-03  3:10             ` Ihor Radchenko
2021-09-03  3:28               ` Ryan Scott
2021-09-05 13:22                 ` Ihor Radchenko
2021-09-05 13:56                   ` Ryan Scott
2021-09-10  1:04                     ` Ryan Scott
2021-09-10  6:26                       ` Timothy
2021-10-02  8:32                       ` Ihor Radchenko
2021-10-02  9:39                         ` Ryan Scott
2021-10-05  0:04               ` Christopher M. Miles
2021-10-05  1:05                 ` Ryan Scott
2021-10-08  1:22                   ` Christopher M. Miles

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 NNTP newsgroup(s).