emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Drag images from Firefox to org-mode


From: Rick Frankel
Subject: Re: [O] Drag images from Firefox to org-mode
Date: Thu, 17 Oct 2013 12:51:52 -0400
User-agent: Roundcube Webmail/0.9.0

On 2013-10-17 10:48, Nicolas Richard wrote:
Rick Frankel <address@hidden> writes:
On 2013-10-17 08:43, Nicolas Richard wrote:
Carsten Dominik <address@hidden> writes:
does anyone know how general this code is?  Does it works on
different operating systems?
We might want to include this into the Org core.

Since it is based on dnd, and since the documentation of dnd reads:
;; This file provides the generic handling of the drop part only.
;; Different DND backends (X11, W32, etc.) that handle the platform
;; specific DND parts call the functions here to do final delivery of
;; a drop.
I'd highly suspect that the code is portable.

It does make use of `wget', which may not be avalalable on all systems
(e.g., i believe os x only includes `curl' by default.) So it would
need to allow configuration of the image fetch command.


I'm sorry I missed that. Indeed, on the one "OS X" I ever tried to run
wget on, it didn't have wget.

Perhaps url-retrieve can be used instead. I have no time right now to
code it right, but here's a (synchronous) example with url + filetype +
filename all hardcoded :

(with-current-buffer
(url-retrieve-synchronously
"http://www.cnrtl.fr/images/css/bandeau.jpg";)
(delete-region
(point-min)
(progn
(re-search-forward "^$" nil 'move)
(point)))
(write-file
(expand-file-name "~/tmp/foobar.jpg"))
(pop-to-buffer
(current-buffer)))

using url-retrieve (which is asynchroneous)  might also lift the
requirement on async.el

One small problem, should be =(1+ (point))=, as the above leaves a
blank newline at the head of the jpg, making it invalid.

Here's an async implementation that seems to work ok:

#+begin_src emacs-lisp
(defun fetch-image (url &optional destdir)
(url-retrieve
url
(lambda (status url destdir)
(let ((err (plist-get status :error)))
(if err
(signal :error (cdr err))))
(delete-region
(point-min)
(progn
(re-search-forward "^$" nil 'move)
(1+ (point))))
(write-file
(expand-file-name (file-name-nondirectory url) destdir)
(pop-to-buffer
(current-buffer)))) `(,url ,destdir) nil t))
#+end_src

rick



reply via email to

[Prev in Thread] Current Thread [Next in Thread]