0

the main question is in the title

Also:

  • if it is impossible, why? Can we solve the problem?
  • if it is possible, how?

I made some tests by adding directly a folder in the attachment folder, then I inserted a link towards this folder thanks to [[Attachment:nameofdirectory/][descriptionhere]]. This link works, but why the functionality to add a folder is not available ?

Thanks in advance

3
  • If you use the move or symlink mtehod, you should be able to attach a directory (always subject to the underlying permissions). copy does not work because the underlying implementation uses copy-file which cannot copy a directory; link does not work because of hardlink limitations.
    – NickD
    Jun 4, 2022 at 1:14
  • Thanks for your answer. A symlink is not why I search (if it's possible), ans the "move" method don't work too, I have this error : "org-attach-attach : File already exists: /home/name/whereIsTheHealine/data/XX/XXXX-...-XXX". Possible to change the fonction with the method "copy" (to call, for exemple "copy-directory")
    – Cletip
    Jun 5, 2022 at 19:57
  • Edit : same error with symlink. Version of org mode (maybe the problem) : 9.5.3. Emacs 27.1
    – Cletip
    Jun 5, 2022 at 20:47

1 Answer 1

0

After discussions with developers of org mode, it is normally possible (with an update of org-mode). However, you can just copy and paste this function in your configuration for it to work (normally).

(defun org-attach-attach (file &optional visit-dir method)
"Move/copy/link FILE 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'."
    (interactive
     (list
      (read-file-name "File to keep as an attachment: "
                      (or (progn
                            (require 'dired-aux)
                            (dired-dwim-target-directory))
                          default-directory))
      current-prefix-arg
      nil))
    (setq method (or method org-attach-method))
    (when (file-directory-p file)
      (setq file (directory-file-name file)))
    (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)
              (copy-directory file attach-file nil nil t)
            (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 %S is now an attachment" basename)))))
2
  • Can you highlight how the function you posted is different from what Org mode distributes? Also please add a link to the discussion you had on the Org mode mailing list.
    – NickD
    Jul 8, 2022 at 20:03
  • Normally it is the same function. Sorry if I misspoke: if you don't want to / can't update org-mode, just copy and paste this function into the emacs configuration file (and load it after loading org-mode of course) The link for the discussion is here, but the discussion is not complete (not exactly why).
    – Cletip
    Jul 12, 2022 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.