* 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ messages in thread
end of thread, other threads:[~2021-06-15 20:21 UTC | newest] Thread overview: 10+ 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
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).