emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-attach a directory?
@ 2021-06-08 15:49 John Kitchin
  2021-06-08 16:21 ` Henrik Frisk
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: John Kitchin @ 2021-06-08 15:49 UTC (permalink / raw)
  To: org-mode-email

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

Is it possible to attach a directory to an org heading?

I have only seen how to attach a file so far.

John

-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

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

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

* Re: org-attach a directory?
  2021-06-08 15:49 org-attach a directory? John Kitchin
@ 2021-06-08 16:21 ` Henrik Frisk
  2021-06-08 20:41   ` John Kitchin
  2021-06-09  1:38 ` Ihor Radchenko
  2021-06-11  1:43 ` stardiviner
  2 siblings, 1 reply; 20+ messages in thread
From: Henrik Frisk @ 2021-06-08 16:21 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode-email

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

Den tis 8 juni 2021 kl 17:56 skrev John Kitchin <jkitchin@andrew.cmu.edu>:

> Is it possible to attach a directory to an org heading?
>
>
> Yes, you do arg-attach-set-directory. After that you need to sync it to
make the files in the directory visible: org-attach-sync

It's quite neat, I use it all the time.

/Henrik

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

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

* Re: org-attach a directory?
  2021-06-08 16:21 ` Henrik Frisk
@ 2021-06-08 20:41   ` John Kitchin
  2021-06-09  1:38     ` [patch] " Juan Manuel Macías
  0 siblings, 1 reply; 20+ messages in thread
From: John Kitchin @ 2021-06-08 20:41 UTC (permalink / raw)
  To: Henrik Frisk; +Cc: org-mode-email

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

I am not sure that is what I meant, it looks like that specifies/changes
the attachment directory for a heading.

I want to attach all the files in a directory on my desktop to the
attachment directory, something that is more like
org-attach-attach-mv-directory  (that is not an existing command, but what
I was thinking of doing). Did I misunderstand what org-attach-set-directory
does?

John

-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Tue, Jun 8, 2021 at 12:21 PM Henrik Frisk <frisk.h@gmail.com> wrote:

>
>
> Den tis 8 juni 2021 kl 17:56 skrev John Kitchin <jkitchin@andrew.cmu.edu>:
>
>> Is it possible to attach a directory to an org heading?
>>
>>
>> Yes, you do arg-attach-set-directory. After that you need to sync it to
> make the files in the directory visible: org-attach-sync
>
> It's quite neat, I use it all the time.
>
> /Henrik
>

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

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

* [patch] Re: org-attach a directory?
  2021-06-08 20:41   ` John Kitchin
@ 2021-06-09  1:38     ` Juan Manuel Macías
  0 siblings, 0 replies; 20+ messages in thread
From: Juan Manuel Macías @ 2021-06-09  1:38 UTC (permalink / raw)
  To: John Kitchin; +Cc: orgmode

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

Hi John,

John Kitchin writes:

> I want to attach all the files in a directory on my desktop to the
> attachment directory, something that is more like
> org-attach-attach-mv-directory  (that is not an existing command, but
> what I was thinking of doing). Did I misunderstand what
> org-attach-set-directory does?

As far as I know, that option is not possible. And it's something that
I've always missed in org-attach. I've written this possible patch, with
two new attach methods/commands to copy or move a directory ("C" and
"M"). I guess it would be better to use `read-file-name' and
`read-directory-name' according to each case, but I can't think of how
to solve that. Anyway, `read-file-name' may also apply here for
directories.

(Little tested).

Best regards,

Juan Manuel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Org-attach.el-Add-two-new-methods-for-cp-or-mv-directories.patch --]
[-- Type: text/x-patch, Size: 4462 bytes --]

From 5a2f59a74c9b3f8ff1cf25777067780400f9043f Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
Date: Wed, 9 Jun 2021 03:03:50 +0200
Subject: [PATCH] Org-attach.el: Add two new methods for copying or moving
 directories

* lisp/org-attach.el (org-attach-commands): add two new attachments
commands
(org-attach-attach): add two new attachment methods, argument `file'
is ranamed as `target'
(org-attach-attach-cp-dir): copy a directory
(org-attach-attach-mv-dir): move (rename) a directory
---
 lisp/org-attach.el | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 715fe3e93..50b1dca3b 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -199,6 +199,10 @@ git-functionality from this file.")
      "Attach a file using copy method.")
     ((?m ?\C-m) org-attach-attach-mv
      "Attach a file using move method.")
+    ((?C ?\C-C) org-attach-attach-cp-dir
+     "Attach a directory using copy dir method.")
+    ((?M ?\C-M) org-attach-attach-mv-dir
+     "Attach a directory using move dir method.")
     ((?l ?\C-l) org-attach-attach-ln
      "Attach a file using link method.")
     ((?y ?\C-y) org-attach-attach-lns
@@ -489,8 +493,8 @@ if it would overwrite an existing filename."
     (with-temp-file output
       (insert-buffer-substring buffer-name))))
 
-(defun org-attach-attach (file &optional visit-dir method)
-  "Move/copy/link FILE into the attachment directory of the current outline node.
+(defun org-attach-attach (target &optional visit-dir method)
+  "Move/copy/link TARGET into the attachment directory of the current outline node.
 If VISIT-DIR is non-nil, visit the directory with dired.
 METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
 `org-attach-method'."
@@ -504,15 +508,20 @@ METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
     current-prefix-arg
     nil))
   (setq method (or method org-attach-method))
-  (let ((basename (file-name-nondirectory file)))
+  (let ((basename (if (or (eq method 'mv-dir)
+			  (eq method 'cp-dir))
+		      target
+		    (file-name-nondirectory target))))
     (let* ((attach-dir (org-attach-dir 'get-create))
            (attach-file (expand-file-name basename attach-dir)))
       (cond
-       ((eq method 'mv) (rename-file file attach-file))
-       ((eq method 'cp) (copy-file file attach-file))
-       ((eq method 'ln) (add-name-to-file file attach-file))
-       ((eq method 'lns) (make-symbolic-link file attach-file))
-       ((eq method 'url) (url-copy-file file attach-file)))
+       ((eq method 'mv) (rename-file target attach-file))
+       ((eq method 'cp) (copy-file target attach-file))
+       ((eq method 'mv-dir) (rename-file target (concat attach-dir "/")))
+       ((eq method 'cp-dir) (copy-directory target (concat attach-dir "/")))
+       ((eq method 'ln) (add-name-to-file target attach-file))
+       ((eq method 'lns) (make-symbolic-link target attach-file))
+       ((eq method 'url) (url-copy-file target attach-file)))
       (run-hook-with-args 'org-attach-after-change-hook attach-dir)
       (org-attach-tag)
       (cond ((eq org-attach-store-link-p 'attached)
@@ -520,8 +529,8 @@ METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
 			 (file-name-nondirectory attach-file))
 		   org-stored-links))
             ((eq org-attach-store-link-p t)
-             (push (list (concat "file:" file)
-			 (file-name-nondirectory file))
+             (push (list (concat "file:" target)
+			 (file-name-nondirectory target))
 		   org-stored-links))
 	    ((eq org-attach-store-link-p 'file)
 	     (push (list (concat "file:" attach-file)
@@ -539,6 +548,14 @@ METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
   "Attach a file by moving (renaming) it."
   (interactive)
   (let ((org-attach-method 'mv)) (call-interactively 'org-attach-attach)))
+(defun org-attach-attach-cp-dir ()
+  "Attach a directory by copying it."
+  (interactive)
+  (let ((org-attach-method 'cp-dir)) (call-interactively 'org-attach-attach)))
+(defun org-attach-attach-mv-dir ()
+  "Attach a directory by moving (renaming) it."
+  (interactive)
+  (let ((org-attach-method 'mv-dir)) (call-interactively 'org-attach-attach)))
 (defun org-attach-attach-ln ()
   "Attach a file by creating a hard link to it.
 Beware that this does not work on systems that do not support hard links.
-- 
2.31.1


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

* Re: org-attach a directory?
  2021-06-08 15:49 org-attach a directory? John Kitchin
  2021-06-08 16:21 ` Henrik Frisk
@ 2021-06-09  1:38 ` Ihor Radchenko
  2021-06-11  1:43 ` stardiviner
  2 siblings, 0 replies; 20+ messages in thread
From: Ihor Radchenko @ 2021-06-09  1:38 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode-email

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> Is it possible to attach a directory to an org heading?
>
> I have only seen how to attach a file so far.

I use the code below to attach directories and allow multiple selection
while attaching files. Also, if more people are interested in this kind
of functionality, I can write a simple patch. It's just a matter of
applying #'directory-file-name to the selected file name in the
interactive spec of the org-attach-attach.

(defvar yant/org-attach-default-source "~/Downloads/"
  "Default directory to attach the files from.")

(define-advice org-attach-attach (:around (oldfun files &rest args) start-from-default-directory)
  "Look for new attachments from `yant/org-attach-default-source' directory instead of `default-directory'."
  (interactive
   (list
    (mapcar #'directory-file-name (helm-read-file-name "File to keep as an attachment:"
						       :initial-input (or (progn
									    (require 'dired-aux)
									    (dired-dwim-target-directory))
									  (and yant/org-attach-default-source
									       (f-slash yant/org-attach-default-source))
									  default-directory)
						       :marked-candidates t))
    current-prefix-arg
    nil))
  (unless (listp files) (setq files (list files)))
  (mapc (lambda (file) (apply oldfun file args)) files))

Best,
Ihor


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

* Re: org-attach a directory?
@ 2021-06-09 19:35 Ypo
  2021-06-09 23:39 ` John Kitchin
  0 siblings, 1 reply; 20+ messages in thread
From: Ypo @ 2021-06-09 19:35 UTC (permalink / raw)
  To: jkitchin, Org-mode

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

Firstly you set the folder where your files are as attachment DIRectory.

Then, you set your target attachment DIRectory (always using the attachment commands).

After doing this, you will be offered the option to copy and delete all the files from the former to the target folder.

Hugs

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

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

* Re: org-attach a directory?
  2021-06-09 19:35 Ypo
@ 2021-06-09 23:39 ` John Kitchin
  2021-06-10  3:54   ` Ypo
  2021-06-10  3:56   ` Ypo
  0 siblings, 2 replies; 20+ messages in thread
From: John Kitchin @ 2021-06-09 23:39 UTC (permalink / raw)
  To: Ypo; +Cc: Org-mode

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

can you give an example of those commands, I tried the key commands

C-c C-a which opens the dispatcher
s to set a directory
then C-c C-a z to sync, but it did not do anything but add a :DIR:
property. it didn't move or copy files anywhere.

Here is the code I am currently using that basically does what I want.

(defun scimax-org-attach-attach-directory-cp (dir)
  "Copy DIR as an attachment to the current heading."
  (interactive "DDir: ")
  (copy-directory dir (file-name-as-directory (org-attach-dir 'get-create)))
  (org-attach-sync)
  (org-entry-put (point) "ATTACHMENTS"
(concat
 (org-entry-get (point) "ATTACHMENTS")
 (format " [[attachment:%s]]" (car (last (f-split dir)))))))


(defun scimax-org-attach-attach-directory-mv (dir)
  "Move DIR as an attachment to the current heading."
  (interactive "DDir: ")
  (scimax-org-attach-attach-directory-cp dir)
  (delete-directory dir t t))


John

-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Wed, Jun 9, 2021 at 3:35 PM Ypo <ypuntot@gmail.com> wrote:

> Firstly you set the folder where your files are as attachment DIRectory.
>
> Then, you set your target attachment DIRectory (always using the
> attachment commands).
>
> After doing this, you will be offered the option to copy and delete all
> the files from the former to the target folder.
>
> Hugs
>

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

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

* Re: org-attach a directory?
  2021-06-09 23:39 ` John Kitchin
@ 2021-06-10  3:54   ` Ypo
  2021-06-10  3:56   ` Ypo
  1 sibling, 0 replies; 20+ messages in thread
From: Ypo @ 2021-06-10  3:54 UTC (permalink / raw)
  To: John Kitchin; +Cc: Org-mode

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

Hi John :-)

Take a look:

https://mega.nz/file/hKgECBqY#8UVEURWQBvDpno9DPEk8gb8E-zxAJq3F3E8Y9I9xRFk


El 10/06/2021 a las 1:39, John Kitchin escribió:
> can you give an example of those commands, I tried the key commands
>
> C-c C-a which opens the dispatcher
> s to set a directory
> then C-c C-a z to sync, but it did not do anything but add a :DIR: 
> property. it didn't move or copy files anywhere.
>
> Here is the code I am currently using that basically does what I want.
>
> (defun scimax-org-attach-attach-directory-cp (dir)
>   "Copy DIR as an attachment to the current heading."
>   (interactive "DDir: ")
>   (copy-directory dir (file-name-as-directory (org-attach-dir 
> 'get-create)))
>   (org-attach-sync)
>   (org-entry-put (point) "ATTACHMENTS"
> (concat
>  (org-entry-get (point) "ATTACHMENTS")
>  (format " [[attachment:%s]]" (car (last (f-split dir)))))))
>
>
> (defun scimax-org-attach-attach-directory-mv (dir)
>   "Move DIR as an attachment to the current heading."
>   (interactive "DDir: ")
>   (scimax-org-attach-attach-directory-cp dir)
>   (delete-directory dir t t))
>
>
> John
>
> -----------------------------------
> Professor John Kitchin (he/him/his)
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu <http://kitchingroup.cheme.cmu.edu>
>
>
>
> On Wed, Jun 9, 2021 at 3:35 PM Ypo <ypuntot@gmail.com 
> <mailto:ypuntot@gmail.com>> wrote:
>
>     Firstly you set the folder where your files are as attachment
>     DIRectory.
>
>     Then, you set your target attachment DIRectory (always using the
>     attachment commands).
>
>     After doing this, you will be offered the option to copy and
>     delete all the files from the former to the target folder.
>
>     Hugs
>

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

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

* Re: org-attach a directory?
  2021-06-09 23:39 ` John Kitchin
  2021-06-10  3:54   ` Ypo
@ 2021-06-10  3:56   ` Ypo
  2021-06-10 12:37     ` Christian Barthel
  1 sibling, 1 reply; 20+ messages in thread
From: Ypo @ 2021-06-10  3:56 UTC (permalink / raw)
  To: John Kitchin; +Cc: Org-mode

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

C-c C-a

s

(not "S" like in the video, but "s")

El 10/06/2021 a las 1:39, John Kitchin escribió:
> can you give an example of those commands, I tried the key commands
>
> C-c C-a which opens the dispatcher
> s to set a directory
> then C-c C-a z to sync, but it did not do anything but add a :DIR: 
> property. it didn't move or copy files anywhere.
>
> Here is the code I am currently using that basically does what I want.
>
> (defun scimax-org-attach-attach-directory-cp (dir)
>   "Copy DIR as an attachment to the current heading."
>   (interactive "DDir: ")
>   (copy-directory dir (file-name-as-directory (org-attach-dir 
> 'get-create)))
>   (org-attach-sync)
>   (org-entry-put (point) "ATTACHMENTS"
> (concat
>  (org-entry-get (point) "ATTACHMENTS")
>  (format " [[attachment:%s]]" (car (last (f-split dir)))))))
>
>
> (defun scimax-org-attach-attach-directory-mv (dir)
>   "Move DIR as an attachment to the current heading."
>   (interactive "DDir: ")
>   (scimax-org-attach-attach-directory-cp dir)
>   (delete-directory dir t t))
>
>
> John
>
> -----------------------------------
> Professor John Kitchin (he/him/his)
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu <http://kitchingroup.cheme.cmu.edu>
>
>
>
> On Wed, Jun 9, 2021 at 3:35 PM Ypo <ypuntot@gmail.com 
> <mailto:ypuntot@gmail.com>> wrote:
>
>     Firstly you set the folder where your files are as attachment
>     DIRectory.
>
>     Then, you set your target attachment DIRectory (always using the
>     attachment commands).
>
>     After doing this, you will be offered the option to copy and
>     delete all the files from the former to the target folder.
>
>     Hugs
>

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

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

* Re: org-attach a directory?
  2021-06-10  3:56   ` Ypo
@ 2021-06-10 12:37     ` Christian Barthel
  2021-06-10 12:39       ` John Kitchin
  2021-06-10 14:01       ` Juan Manuel Macías
  0 siblings, 2 replies; 20+ messages in thread
From: Christian Barthel @ 2021-06-10 12:37 UTC (permalink / raw)
  To: Ypo; +Cc: Org-mode, John Kitchin

On Thu, Jun 10 2021, Ypo wrote:

> C-c C-a
>
> s
>
> (not "S" like in the video, but "s")

Thanks, that is an interesting workaround:
Setting the directory twice and using the copy/delete action
accordingly.

Does anyone know if there is a workaround to attach a file and
delete the old one (or move the file) or do I need to write a
small elisp function for that?

-- 
Christian Barthel


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

* Re: org-attach a directory?
  2021-06-10 12:37     ` Christian Barthel
@ 2021-06-10 12:39       ` John Kitchin
  2021-06-10 12:54         ` Christian Barthel
  2021-06-10 14:01       ` Juan Manuel Macías
  1 sibling, 1 reply; 20+ messages in thread
From: John Kitchin @ 2021-06-10 12:39 UTC (permalink / raw)
  To: Christian Barthel; +Cc: Ypo, Org-mode

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

isn't that just org-attach-attach-mv? or what happens if you set
org-attach-method to mv?

John

-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Thu, Jun 10, 2021 at 8:37 AM Christian Barthel <bch@online.de> wrote:

> On Thu, Jun 10 2021, Ypo wrote:
>
> > C-c C-a
> >
> > s
> >
> > (not "S" like in the video, but "s")
>
> Thanks, that is an interesting workaround:
> Setting the directory twice and using the copy/delete action
> accordingly.
>
> Does anyone know if there is a workaround to attach a file and
> delete the old one (or move the file) or do I need to write a
> small elisp function for that?
>
> --
> Christian Barthel
>

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

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

* Re: org-attach a directory?
  2021-06-10 12:39       ` John Kitchin
@ 2021-06-10 12:54         ` Christian Barthel
  0 siblings, 0 replies; 20+ messages in thread
From: Christian Barthel @ 2021-06-10 12:54 UTC (permalink / raw)
  To: John Kitchin; +Cc: Ypo, Org-mode

On Thu, Jun 10 2021, John Kitchin wrote:

> isn't that just org-attach-attach-mv? or what happens if you set
> org-attach-method to mv?

Ah right.  I always just looked only at the *Org Attach* buffer
and haven't seen a move method.  The echo area lists a few more
commands:  it seems that doing `org-attach' and `m' (move?) does
exactly what I need.  Thanks!

-- 
Christian Barthel


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

* Re: org-attach a directory?
  2021-06-10 12:37     ` Christian Barthel
  2021-06-10 12:39       ` John Kitchin
@ 2021-06-10 14:01       ` Juan Manuel Macías
  2021-06-10 16:13         ` Juan Manuel Macías
  1 sibling, 1 reply; 20+ messages in thread
From: Juan Manuel Macías @ 2021-06-10 14:01 UTC (permalink / raw)
  To: Christian Barthel, John Kitchin, Ihor Radchenko; +Cc: orgmode

This only works when you create the attach folder manually, but not when
you want org-attach to generate the attach directory for the current
node.

If I have to stay with a workaround that covers many scenarios, I would
stay with Ihor's snippet, which seems to me simpler than the patch that
I suggested before, and you don't need to define new attach
commands/methods. I would vote for a patch in that direction (Ihor's
code).

Best regards,

Juan Manuel     

Christian Barthel writes:

> On Thu, Jun 10 2021, Ypo wrote:
>
>> C-c C-a
>>
>> s
>>
>> (not "S" like in the video, but "s")
>
> Thanks, that is an interesting workaround:
> Setting the directory twice and using the copy/delete action
> accordingly.
>
> Does anyone know if there is a workaround to attach a file and
> delete the old one (or move the file) or do I need to write a
> small elisp function for that?



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

* Re: org-attach a directory?
  2021-06-10 14:01       ` Juan Manuel Macías
@ 2021-06-10 16:13         ` Juan Manuel Macías
  0 siblings, 0 replies; 20+ messages in thread
From: Juan Manuel Macías @ 2021-06-10 16:13 UTC (permalink / raw)
  To: orgmode

You could also modify some line in org-attach-attach, for example:

...
((eq method 'cp) (if (file-directory-p file)
                            (copy-directory file attach-file)
                          (copy-file file attach-file)))
...

Best regards,

Juan Manuel 

Juan Manuel Macías writes:

> If I have to stay with a workaround that covers many scenarios, I would
> stay with Ihor's snippet, which seems to me simpler than the patch that
> I suggested before, and you don't need to define new attach
> commands/methods. I would vote for a patch in that direction (Ihor's
> code).



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

* Re: org-attach a directory?
@ 2021-06-10 16:50 Ypo
  0 siblings, 0 replies; 20+ messages in thread
From: Ypo @ 2021-06-10 16:50 UTC (permalink / raw)
  To: bch, Org-mode

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

In case you don't know it, take a look at the inheritance option for attachments. Very very very useful: You can use the same DIRectory with many subtrees without being necessary to attach the directory to each of them.

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

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

* Re: org-attach a directory?
  2021-06-08 15:49 org-attach a directory? John Kitchin
  2021-06-08 16:21 ` Henrik Frisk
  2021-06-09  1:38 ` Ihor Radchenko
@ 2021-06-11  1:43 ` stardiviner
  2021-06-11 16:35   ` John Kitchin
  2 siblings, 1 reply; 20+ messages in thread
From: stardiviner @ 2021-06-11  1:43 UTC (permalink / raw)
  To: John Kitchin; +Cc: Org-mode

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

I want this feature patch too. Hope Org Mode can add this. I remember old version org-mode can do this. But later delete this feature? I forget what version is.

I suggest to add this feature.

> On Jun 8, 2021, at 11:49 PM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
> 
> Is it possible to attach a directory to an org heading?
> 
> I have only seen how to attach a file so far.
> 
> John
> 
> -----------------------------------
> Professor John Kitchin (he/him/his)
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu <http://kitchingroup.cheme.cmu.edu/>
> 


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

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

* Re: org-attach a directory?
  2021-06-11  1:43 ` stardiviner
@ 2021-06-11 16:35   ` John Kitchin
  2021-06-11 17:10     ` Juan Manuel Macías
                       ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: John Kitchin @ 2021-06-11 16:35 UTC (permalink / raw)
  To: stardiviner; +Cc: Org-mode

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

I discovered another way to do this that is already built in with
`org-attach-dired-to-subtree` that would help sometimes.

You split your window, open dired in one of them, mark some files, and then
run that command in the dired window.

John

-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Thu, Jun 10, 2021 at 10:04 PM stardiviner <numbchild@gmail.com> wrote:

> I want this feature patch too. Hope Org Mode can add this. I remember old
> version org-mode can do this. But later delete this feature? I forget what
> version is.
>
> I suggest to add this feature.
>
> On Jun 8, 2021, at 11:49 PM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
>
> Is it possible to attach a directory to an org heading?
>
> I have only seen how to attach a file so far.
>
> John
>
> -----------------------------------
> Professor John Kitchin (he/him/his)
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>
>
>

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

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

* Re: org-attach a directory?
  2021-06-11 16:35   ` John Kitchin
@ 2021-06-11 17:10     ` Juan Manuel Macías
  2021-06-15 12:45     ` stardiviner
  2021-06-15 20:22     ` Henrik Frisk
  2 siblings, 0 replies; 20+ messages in thread
From: Juan Manuel Macías @ 2021-06-11 17:10 UTC (permalink / raw)
  To: John Kitchin; +Cc: orgmode

I have put the Ihor's snippet in my init file. I find it very useful,
and everything is done from a simple Helm session. The only case it
doesn't work is when I just want to copy a directory --not a file--
(instead of moving or giving it a symbolic link). So I have done this
little modification (just added a conditional to the old function when
the method attach is 'cp: if attachment is a file, run `copy-file'. If
it is a directory, run `copy-directory'. Then just call the org-attach
dispatcher as always: C-c C-a and select an attach method:

(define-advice org-attach-attach (:around (oldfun files &rest args) start-from-default-directory)
  "Code shared by Ihor Radchenko, slightly modified and adapted to my use."
  (interactive
   (list
    (mapcar #'directory-file-name (helm-read-file-name "File to keep as an attachment:"
                                                       :initial-input (or (progn
                                                                            (require 'dired-aux)
                                                                            (dired-dwim-target-directory))
                                                                          default-directory)
                                                       :marked-candidates t))
    current-prefix-arg
    nil))
    ;; my addition starts here
  (setq oldfun (lambda (file &optional visit-dir method)
                 (interactive)
                 (setq method (or method org-attach-method))
                 (let ((basename (file-name-nondirectory file)))
                   (let* ((attach-dir (org-attach-dir 'get-create))
                          (attach-file (expand-file-name basename attach-dir)))
                     (cond
                      ((eq method 'mv) (rename-file file attach-file))
                      ((eq method 'cp) (if (file-directory-p file) (ref:lin-attach)
                                           (copy-directory file attach-file)
                                         (copy-file file attach-file)))
                      ((eq method 'ln) (add-name-to-file file attach-file))
                      ((eq method 'lns) (make-symbolic-link file attach-file))
                      ((eq method 'url) (url-copy-file file attach-file)))
                     (run-hook-with-args 'org-attach-after-change-hook attach-dir)
                     (org-attach-tag)
                     (cond ((eq org-attach-store-link-p 'attached)
                            (push (list (concat "attachment:" (file-name-nondirectory attach-file))
                                        (file-name-nondirectory attach-file))
                                  org-stored-links))
                           ((eq org-attach-store-link-p t)
                            (push (list (concat "file:" file)
                                        (file-name-nondirectory file))
                                  org-stored-links))
                           ((eq org-attach-store-link-p 'file)
                            (push (list (concat "file:" attach-file)
                                        (file-name-nondirectory attach-file))
                                  org-stored-links)))
                     (if visit-dir
                         (dired attach-dir)
                       (message "File or directory %S is now an
  attachment" basename))))))
  ;; my addition ends here
  (unless (listp files) (setq files (list files)))
  (mapc (lambda (file) (apply oldfun file args)) files))

John Kitchin writes:

> I discovered another way to do this that is already built in with
> `org-attach-dired-to-subtree` that would help sometimes.
>
> You split your window, open dired in one of them, mark some files, and
> then run that command in the dired window.
>
> John
>
> -----------------------------------
> Professor John Kitchin (he/him/his)
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>
> On Thu, Jun 10, 2021 at 10:04 PM stardiviner <numbchild@gmail.com>
> wrote:
>
>     I want this feature patch too. Hope Org Mode can add this. I
>     remember old version org-mode can do this. But later delete this
>     feature? I forget what version is.
>
>     I suggest to add this feature.
>
>         On Jun 8, 2021, at 11:49 PM, John Kitchin
>         <jkitchin@andrew.cmu.edu> wrote:
>
>         Is it possible to attach a directory to an org heading?
>
>         I have only seen how to attach a file so far.
>
>         John
>
>         -----------------------------------
>         Professor John Kitchin (he/him/his)
>         Doherty Hall A207F
>         Department of Chemical Engineering
>         Carnegie Mellon University
>         Pittsburgh, PA 15213
>         412-268-7803
>         @johnkitchin
>         http://kitchingroup.cheme.cmu.edu
>

--


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

* Re: org-attach a directory?
  2021-06-11 16:35   ` John Kitchin
  2021-06-11 17:10     ` Juan Manuel Macías
@ 2021-06-15 12:45     ` stardiviner
  2021-06-15 20:22     ` Henrik Frisk
  2 siblings, 0 replies; 20+ messages in thread
From: stardiviner @ 2021-06-15 12:45 UTC (permalink / raw)
  To: John Kitchin; +Cc: Org-mode

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



> On Jun 12, 2021, at 12:35 AM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
> 
> I discovered another way to do this that is already built in with `org-attach-dired-to-subtree` that would help sometimes. 
> 
> You split your window, open dired in one of them, mark some files, and then run that command in the dired window.
> 
> John

Thanks John.

I tried your methods. But this need to mark multiple regular files. Instead of a directory. It needs to leave Org file buffer. What if I have multiple Org buffer presents. It might cause chaos. I don’t think it’s a good solution to attach directory. But learn a new command. Still good.

> 
> -----------------------------------
> Professor John Kitchin (he/him/his)
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu <http://kitchingroup.cheme.cmu.edu/>
> 
> 
> 
> On Thu, Jun 10, 2021 at 10:04 PM stardiviner <numbchild@gmail.com <mailto:numbchild@gmail.com>> wrote:
> I want this feature patch too. Hope Org Mode can add this. I remember old version org-mode can do this. But later delete this feature? I forget what version is.
> 
> I suggest to add this feature.
> 
>> On Jun 8, 2021, at 11:49 PM, John Kitchin <jkitchin@andrew.cmu.edu <mailto:jkitchin@andrew.cmu.edu>> wrote:
>> 
>> Is it possible to attach a directory to an org heading?
>> 
>> I have only seen how to attach a file so far.
>> 
>> John
>> 
>> -----------------------------------
>> Professor John Kitchin (he/him/his)
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu <http://kitchingroup.cheme.cmu.edu/>
>> 
> 


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

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

* Re: org-attach a directory?
  2021-06-11 16:35   ` John Kitchin
  2021-06-11 17:10     ` Juan Manuel Macías
  2021-06-15 12:45     ` stardiviner
@ 2021-06-15 20:22     ` Henrik Frisk
  2 siblings, 0 replies; 20+ messages in thread
From: Henrik Frisk @ 2021-06-15 20:22 UTC (permalink / raw)
  To: John Kitchin; +Cc: Org-mode

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

Den fre 11 juni 2021 18:37John Kitchin <jkitchin@andrew.cmu.edu> skrev:

> I discovered another way to do this that is already built in with
> `org-attach-dired-to-subtree` that would help sometimes.
>
> You split your window, open dired in one of them, mark some files, and
> then run that command in the dired window.
>
> John
>
>> Should have thought of this when you first asked if i had understood your
question. This is a very useful function.

/Henrik

>
>>
>>

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

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

end of thread, other threads:[~2021-06-15 20:21 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-08 15:49 org-attach a directory? John Kitchin
2021-06-08 16:21 ` Henrik Frisk
2021-06-08 20:41   ` John Kitchin
2021-06-09  1:38     ` [patch] " Juan Manuel Macías
2021-06-09  1:38 ` Ihor Radchenko
2021-06-11  1:43 ` stardiviner
2021-06-11 16:35   ` John Kitchin
2021-06-11 17:10     ` Juan Manuel Macías
2021-06-15 12:45     ` stardiviner
2021-06-15 20:22     ` Henrik Frisk
  -- strict thread matches above, loose matches on Subject: below --
2021-06-09 19:35 Ypo
2021-06-09 23:39 ` John Kitchin
2021-06-10  3:54   ` Ypo
2021-06-10  3:56   ` Ypo
2021-06-10 12:37     ` Christian Barthel
2021-06-10 12:39       ` John Kitchin
2021-06-10 12:54         ` Christian Barthel
2021-06-10 14:01       ` Juan Manuel Macías
2021-06-10 16:13         ` Juan Manuel Macías
2021-06-10 16:50 Ypo

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