Function: org-attach-attach

org-attach-attach is an interactive and byte-compiled function defined in org-attach.el.gz.

Signature

(org-attach-attach FILE &optional VISIT-DIR METHOD)

Documentation

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.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-attach.el.gz
(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 1))
       ((eq method 'url)
        (if (org--should-fetch-remote-resource-p file)
            (url-copy-file file attach-file)
          (error "The remote resource %S is considered unsafe, and will not be downloaded."
                 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)))))