commit 734e22acfad4154b4fb92226a3825b46d74e7d10 parent 39e810e114553fdf09785d2a81923103f689e907 Author: Oleh Krehel <ohwoeowho@gmail.com> Date: Mon, 20 Jun 2016 15:07:38 +0200 org-download.el (org-download-dnd): Fall back for non-images * org-download.el (org-download-dnd-fallback): New defun. Fixes #33 Diffstat:
| M | org-download.el | | | 20 | ++++++++++++-------- |
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/org-download.el b/org-download.el @@ -378,22 +378,26 @@ When TIMES isn't nil, delete only TIMES links." (when (file-exists-p str) (delete-file str)))))) +(defun org-download-dnd-fallback (uri action) + (let ((dnd-protocol-alist + (rassq-delete-all + 'org-download-dnd + (copy-alist dnd-protocol-alist)))) + (dnd-handle-one-url nil action uri))) + (defun org-download-dnd (uri action) "When in `org-mode' and URI points to image, download it. Otherwise, pass URI and ACTION back to dnd dispatch." (cond ((eq major-mode 'org-mode) - ;; probably shouldn't redirect - (unless (org-download-image uri) - (message "not an image URL"))) + (condition-case nil + (org-download-image uri) + (error + (org-download-dnd-fallback uri action)))) ((eq major-mode 'dired-mode) (org-download-dired uri)) ;; redirect to someone else (t - (let ((dnd-protocol-alist - (rassq-delete-all - 'org-download-dnd - (copy-alist dnd-protocol-alist)))) - (dnd-handle-one-url nil action uri))))) + (org-download-dnd-fallback uri action)))) (defun org-download-dired (uri) "Download URI to current directory."