1

Assume that I am visiting a folder (directory) on my system by M-x dired in Emacs. Also assume that I am visiting a webpage like http://www.gnu.org/software/emacs/manual/pdf/ by the default web browser of my system (say Mozilla Firefox). If I drag the link elisp.pdf from this webpage and drop it on that dired buffer, the most natural things that one wishes to happen is to save the file elisp.pdf in that folder.

What are the most natural way to achieve this in Emacs?

3
  • Have a look at org-download (visual demo here), it provides functionality that is very similar to what you describe.
    – itsjeyd
    Jan 28, 2015 at 15:03
  • @itsjeyd org-download is for moving images. For images, drag and drop to a dired works without any external package (no need to org-download). So my question remains.
    – Name
    Jan 28, 2015 at 15:11
  • @itsjeyd, you're ahead of me:). I just pushed a dired-specific feature a minute ago.
    – abo-abo
    Jan 28, 2015 at 15:13

1 Answer 1

1

I just added this feature to org-download.

Here's the implementation:

(defun org-download-dired (uri)
  "Download URI to current directory."
  (raise-frame)
  (let ((filename (file-name-nondirectory
                   (car (url-path-and-query
                         (url-generic-parse-url uri))))))
    (message "Downloading %s to %s ..."
             filename
             (expand-file-name filename))
    (url-retrieve
     uri
     (lambda (status filename)
       (let ((err (plist-get status :error)))
         (if err (error
                  "\"%s\" %s" uri
                  (downcase (nth 2 (assq (nth 2 err) url-http-codes))))))
       (let ((coding-system-for-write 'no-conversion))
         (write-region nil nil filename nil nil nil 'confirm)))
     (list
      (expand-file-name filename))
     t t)))

You just need to appropriately tie in the above function with dnd-protocol-alist. But a plain (require 'org-download) should suffice.

13
  • That's weird. Can you edebug org-download-dired?
    – abo-abo
    Jan 28, 2015 at 15:47
  • I downloaded org-download.el and I put (require 'org-download) but Emacs doesn't react in draging the link. I also put the above code in .emacs but still unsuccessful. Maybe I miss something here.
    – Name
    Jan 28, 2015 at 16:03
  • Can you eval dnd-protocol-alist?
    – abo-abo
    Jan 28, 2015 at 16:05
  • Yes it gives (("^file:///" . dired-dnd-handle-local-file) ("^file://" . dired-dnd-handle-file) ("^file:" . dired-dnd-handle-local-file) ("^\\(https?\\|ftp\\|file\\|nfs\\)://" . org-download-dnd) ("^file:///" . dnd-open-local-file) ("^file://" . dnd-open-file) ("^file:" . dnd-open-local-file) ("^\\(https?\\|ftp\\|file\\|nfs\\)://" . dnd-open-file)).
    – Name
    Jan 28, 2015 at 16:06
  • OK, it looks like org-download-dnd should be called. Is it called? What's your operating system?
    – abo-abo
    Jan 28, 2015 at 16:09

Your Answer

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

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