emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: John Kitchin <jkitchin@andrew.cmu.edu>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: org-attach a directory?
Date: Fri, 11 Jun 2021 17:10:52 +0000	[thread overview]
Message-ID: <87zgvwnx7n.fsf@posteo.net> (raw)
In-Reply-To: <CAJ51ETptxWsvPHwF4kVQTLY=RxFuCg+t41x28q9Tbejhe7L=Tg@mail.gmail.com> (John Kitchin's message of "Fri, 11 Jun 2021 12:35:39 -0400")

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."
    (mapcar #'directory-file-name (helm-read-file-name "File to keep as an attachment:"
                                                       :initial-input (or (progn
                                                                            (require 'dired-aux)
                                                       :marked-candidates t))
    ;; my addition starts here
  (setq oldfun (lambda (file &optional visit-dir method)
                 (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)))
                      ((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)
                     (cond ((eq org-attach-store-link-p 'attached)
                            (push (list (concat "attachment:" (file-name-nondirectory attach-file))
                                        (file-name-nondirectory attach-file))
                           ((eq org-attach-store-link-p t)
                            (push (list (concat "file:" file)
                                        (file-name-nondirectory file))
                           ((eq org-attach-store-link-p 'file)
                            (push (list (concat "file:" attach-file)
                                        (file-name-nondirectory attach-file))
                     (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


  reply	other threads:[~2021-06-11 17:11 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zgvwnx7n.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=jkitchin@andrew.cmu.edu \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


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