Function: org--dnd-attach-file

org--dnd-attach-file is a byte-compiled function defined in org.el.gz.

Signature

(org--dnd-attach-file URL ACTION SEPARATOR)

Documentation

Attach filename given by URL using method pertaining to ACTION.

If ACTION is move, use mv attach method. If copy, use cp attach method. If ask, ask the user. If private, use the method denoted in org-yank-dnd-default-attach-method. The action private is always returned.

SEPARATOR is the string to insert after each link.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org--dnd-attach-file (url action separator)
  "Attach filename given by URL using method pertaining to ACTION.
If ACTION is `move', use `mv' attach method.
If `copy', use `cp' attach method.
If `ask', ask the user.
If `private', use the method denoted in `org-yank-dnd-default-attach-method'.
The action `private' is always returned.

SEPARATOR is the string to insert after each link."
  (require 'mailcap)
  (require 'org-attach)
  (let* ((filename (dnd-get-local-file-name url))
         (mimetype (mailcap-file-name-to-mime-type filename))
         (separatep (and (string-prefix-p "image/" mimetype)
                         (not (eq 'attach org-yank-image-save-method))))
         (method (pcase action
                   ('copy 'cp)
                   ('move 'mv)
                   ('ask (org--dnd-rmc
                          "Attach using method"
                          '((?c "copy" cp)
                            (?m "move" mv)
                            (?l "hard link" ln)
                            (?s "symbolic link" lns))))
                   ('private (or org-yank-dnd-default-attach-method
                                 org-attach-method)))))
    (if separatep
        (progn
          (unless (file-directory-p org-yank-image-save-method)
            (make-directory org-yank-image-save-method t))
          (funcall
           (pcase method
             ('cp #'copy-file)
             ('mv #'rename-file)
             ('ln #'add-name-to-file)
             ('lns #'make-symbolic-link))
           filename
           (expand-file-name (file-name-nondirectory filename)
                             org-yank-image-save-method)))
      (org-attach-attach filename nil method))
    (insert
     (org-link-make-string
      (concat (if separatep
                  "file:"
                "attachment:")
              (if separatep
                  (expand-file-name (file-name-nondirectory filename)
                                    org-yank-image-save-method)
                (file-name-nondirectory filename))))
     separator)
    'private))