From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rick Frankel Subject: Re: Drag images from Firefox to org-mode Date: Thu, 17 Oct 2013 12:51:52 -0400 Message-ID: <8bb344a96ebde88ceca14f1b523bd5a8@mail.rickster.com> References: <871u3krrt3.fsf@yahoo.fr> <87r4bkq7g7.fsf@yahoo.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWqno-0006zI-T7 for emacs-orgmode@gnu.org; Thu, 17 Oct 2013 12:52:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VWqnk-0006hd-45 for emacs-orgmode@gnu.org; Thu, 17 Oct 2013 12:52:00 -0400 Received: from [204.62.15.78] (port=55201 helo=mail.rickster.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWqnk-0006hX-08 for emacs-orgmode@gnu.org; Thu, 17 Oct 2013 12:51:56 -0400 In-Reply-To: <87r4bkq7g7.fsf@yahoo.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org On 2013-10-17 10:48, Nicolas Richard wrote: > Rick Frankel writes: > On 2013-10-17 08:43, Nicolas Richard wrote: > Carsten Dominik 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