org-download

a fork of abo-abo's org-download
git clone https://git.trogloxene.org/org-download.git
Log | Files | Refs | README

commit 5764c703562683ccae16ee06141f7f0779cd72bd
parent 3f568b163a8a26f22a9b2d9a90b85fcea89c67f2
Author: Oleh Krehel <ohwoeowho@gmail.com>
Date:   Tue, 27 Mar 2018 23:23:32 +0200

org-download.el (org-download--write-image): Extract

* org-download.el (org-download--image/url-retrieve):
(org-download-dired): Use `org-download--write-image'.

Diffstat:
MREADME.md | 6++++++
Morg-download.el | 38+++++++++++++++++++-------------------
2 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/README.md b/README.md @@ -52,3 +52,9 @@ optionally add a timestamp to the file name. Customize `org-download-backend` to choose between `url-retrieve` (the default) or `wget` or `curl`. + +## Drag-and-drop to `dired` + +```elisp +(add-hook 'dired-mode-hook 'org-download-enable) +``` diff --git a/org-download.el b/org-download.el @@ -246,24 +246,27 @@ COMMAND is a format-style string with two slots for LINK and FILENAME." (with-current-buffer cur-buf (org-display-inline-images)))))) +(defun org-download--write-image (status filename) + ;; Write current buffer to FILENAME + (let ((err (plist-get status :error))) + (when err + (error + "HTTP error %s" + (downcase (nth 2 (assq (nth 2 err) url-http-codes)))))) + (delete-region + (point-min) + (progn + (re-search-forward "\n\n" nil 'move) + (point))) + (let ((coding-system-for-write 'no-conversion)) + (write-region nil nil filename nil nil nil 'confirm))) + (defun org-download--image/url-retrieve (link filename) "Save LINK to FILENAME using `url-retrieve'." (url-retrieve link (lambda (status filename buffer) - ;; Write current buffer to FILENAME - ;; and update inline images in BUFFER - (let ((err (plist-get status :error))) - (if err (error - "\"%s\" %s" link - (downcase (nth 2 (assq (nth 2 err) url-http-codes)))))) - (delete-region - (point-min) - (progn - (re-search-forward "\n\n" nil 'move) - (point))) - (let ((coding-system-for-write 'no-conversion)) - (write-region nil nil filename nil nil nil 'confirm)) + (org-download--write-image status filename) (with-current-buffer buffer (org-display-inline-images))) (list @@ -495,12 +498,9 @@ Otherwise, pass URI and ACTION back to dnd dispatch." (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))) + (org-download--write-image status filename) + (dired (file-name-directory filename)) + (revert-buffer)) (list (expand-file-name filename)) t t)))