[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: org-attach a directory?
From: |
Juan Manuel Macías |
Subject: |
Re: org-attach a directory? |
Date: |
Fri, 11 Jun 2021 17:10:52 +0000 |
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
>
--
- org-attach a directory?, John Kitchin, 2021/06/08
- Re: org-attach a directory?, Ypo, 2021/06/09
- Re: org-attach a directory?, John Kitchin, 2021/06/09
- Re: org-attach a directory?, Ypo, 2021/06/09
- Re: org-attach a directory?, Ypo, 2021/06/09
- Re: org-attach a directory?, Christian Barthel, 2021/06/10
- Re: org-attach a directory?, John Kitchin, 2021/06/10
- Re: org-attach a directory?, Christian Barthel, 2021/06/10
- Re: org-attach a directory?, Juan Manuel Macías, 2021/06/10