From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleh Subject: Re: Drag images from Firefox to org-mode Date: Fri, 18 Oct 2013 11:33:14 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b624d34a5f6e104e9009f9c Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX6Qr-0000fs-8Z for emacs-orgmode@gnu.org; Fri, 18 Oct 2013 05:33:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VX6Qm-0005sz-0m for emacs-orgmode@gnu.org; Fri, 18 Oct 2013 05:33:21 -0400 Received: from mail-we0-x22f.google.com ([2a00:1450:400c:c03::22f]:63389) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX6Ql-0005sq-Lx for emacs-orgmode@gnu.org; Fri, 18 Oct 2013 05:33:15 -0400 Received: by mail-we0-f175.google.com with SMTP id t61so3398523wes.6 for ; Fri, 18 Oct 2013 02:33:14 -0700 (PDT) In-Reply-To: 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: Carsten Dominik Cc: org mode --047d7b624d34a5f6e104e9009f9c Content-Type: text/plain; charset=ISO-8859-1 Hi Carsten, You can commit it whenever you like. I don't currently have access to Windows or OSX, so it's hard to see if the code works everywhere. regards, Oleh On Fri, Oct 18, 2013 at 11:28 AM, Carsten Dominik wrote: > Hi Oleh, > > this is very nice thank you. > > If you want, turn this into a patch to org.el. If not, I will do so later. > > - Carsten > > On Oct 18, 2013, at 11:24 AM, Oleh wrote: > > > Hi Carsten, > > > > The dependencies are async, dnd and wget. > > > > In case dnd doesn't work, there's a fallback to clipboard via > > `current-kill'. > > > > I've just added a custom variable that takes either 'wget or 'curl as > > the download method. > > > > I tried before url-retrieve, but it was giving me some garbage in > > addition to the image. So unless I know reliably the format of the > > garbage I can't use url-retrieve. But if I figure it out, I could add > > url-retrieve as the third custom method. > > > > The updates are at https://github.com/abo-abo/org-download > > > > regards, > > Oleh > > > > > > > > On Thu, Oct 17, 2013 at 2:04 PM, Carsten Dominik < > drostekirsten@gmail.com> wrote: > > Hi Oleh and others, > > > > 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. > > > > - Carsten > > > > On Oct 16, 2013, at 12:04 PM, Oleh wrote: > > > > > Hi all, > > > > > > Here's a little hack that I use to make my life easier: > > > > > > (require 'async) > > > (eval-when-compile > > > (require 'cl)) > > > (defun org-store-image (link basedir) > > > (async-start > > > `(lambda() (shell-command > > > ,(format "wget \"%s\" -P \"%s\"" > > > link > > > (expand-file-name basedir)))) > > > (lexical-let ((cur-buf (current-buffer))) > > > (lambda(x) > > > (with-current-buffer cur-buf > > > (org-display-inline-images)))))) > > > > > > (defun org-store-image-clipboard (link) > > > "Save image at address LINK to current directory's subdirectory DIR. > > > DIR is the name of the current level 0 heading." > > > (interactive (list (current-kill 0))) > > > (let ((filename (car (last (split-string link "/")))) > > > (dir (save-excursion > > > (org-up-heading-all (1- (org-current-level))) > > > (substring-no-properties > > > (org-get-heading))))) > > > (if (null (image-type-from-file-name filename)) > > > (message "not an image URL") > > > (unless (file-exists-p (expand-file-name filename dir)) > > > (org-store-image link dir)) > > > (insert (format "[[./%s/%s]]" dir filename)) > > > (org-display-inline-images)))) > > > > > > (setcdr (assoc "^\\(https?\\|ftp\\|file\\|nfs\\)://" > dnd-protocol-alist) 'dnd-org-insert) > > > > > > (defun dnd-org-insert (uri action) > > > (org-store-image-clipboard uri)) > > > > > > When it's a plain image, I can just drag it from the browser to > org-mode. > > > It will be downloaded in async to a subdirectory of the current > directory and the link will be inserted > > > at point. > > > For stubborn images that are links I can right click to copy image > location and call > > > `org-store-image-clipboard' interactively. > > > > > > I hope it's useful to someone and that I'm not re-implementing > standard functionality. > > > > > > regards, > > > Oleh > > > > > > regards, > > > Oleh > > > > > > --047d7b624d34a5f6e104e9009f9c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Carsten,

You can commit it whenever = you like.
I don't currently have access to Windows or OSX, so= it's hard=A0
to see if the code works everywhere.
=
regards,
Oleh

On Fri, Oct 18, 2013 at 11:28 AM, Carsten = Dominik <drostekirsten@gmail.com> wrote:
Hi Oleh,

this is very nice thank you.

If you want, turn this into a patch to org.el. =A0If not, I will do so late= r.

- Carsten

On Oct 18, 2013, at 11:24 AM, Oleh <ohwoeowho@gmail.com> wrote:

> Hi Carsten,
>
> The dependencies are async, dnd and wget.
>
> In case dnd doesn't work, there's a fallback to clipboard via<= br> > `current-kill'.
>
> I've just added a custom variable that takes either 'wget or &= #39;curl as
> the download method.
>
> I tried before url-retrieve, but it was giving me some garbage in
> addition to the image. So unless I know reliably the format of the
> garbage I can't use url-retrieve. But if I figure it out, I could = add
> url-retrieve as the third custom method.
>
> The updates are at https://github.com/abo-abo/org-download
>
> regards,
> Oleh
>
>
>
> On Thu, Oct 17, 2013 at 2:04 PM, Carsten Dominik <drostekirsten@gmail.com> wrote:
> Hi Oleh and others,
>
> does anyone know how general this code is? =A0Does it works on differe= nt operating systems?
> We might want to include this into the Org core.
>
> - Carsten
>
> On Oct 16, 2013, at 12:04 PM, Oleh <ohwoeowho@gmail.com> wrote:
>
> > Hi all,
> >
> > Here's a little hack that I use to make my life easier:
> >
> > (require 'async)
> > (eval-when-compile
> > =A0 (require 'cl))
> > (defun org-store-image (link basedir)
> > =A0 (async-start
> > =A0 =A0`(lambda() (shell-command
> > =A0 =A0 =A0 =A0 =A0 ,(format "wget \"%s\" -P \&quo= t;%s\""
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0link
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(expand-file-name basedir)= )))
> > =A0 =A0(lexical-let ((cur-buf (current-buffer)))
> > =A0 =A0 =A0(lambda(x)
> > =A0 =A0 =A0 =A0(with-current-buffer cur-buf
> > =A0 =A0 =A0 =A0 =A0(org-display-inline-images))))))
> >
> > (defun org-store-image-clipboard (link)
> > =A0 "Save image at address LINK to current directory's s= ubdirectory DIR.
> > DIR is the name of the current level 0 heading."
> > =A0 (interactive (list (current-kill 0)))
> > =A0 (let ((filename (car (last (split-string link "/"))= ))
> > =A0 =A0 =A0 =A0 (dir (save-excursion
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(org-up-heading-all (1- (org-curre= nt-level)))
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(substring-no-properties
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (org-get-heading)))))
> > =A0 =A0 (if (null (image-type-from-file-name filename))
> > =A0 =A0 =A0 =A0 (message "not an image URL")
> > =A0 =A0 =A0 (unless (file-exists-p (expand-file-name filename dir= ))
> > =A0 =A0 =A0 =A0 (org-store-image link dir))
> > =A0 =A0 =A0 (insert (format "[[./%s/%s]]" dir filename)= )
> > =A0 =A0 =A0 (org-display-inline-images))))
> >
> > (setcdr (assoc "^\\(https?\\|ftp\\|file\\|nfs\\)://" dn= d-protocol-alist) 'dnd-org-insert)
> >
> > (defun dnd-org-insert (uri action)
> > =A0 (org-store-image-clipboard uri))
> >
> > When it's a plain image, I can just drag it from the browser = to org-mode.
> > It will be downloaded in async to a subdirectory of the current d= irectory and the link will be inserted
> > at point.
> > For stubborn images that are links I can right click to copy imag= e location and call
> > `org-store-image-clipboard' interactively.
> >
> > I hope it's useful to someone and that I'm not re-impleme= nting standard functionality.
> >
> > regards,
> > Oleh
> >
> > regards,
> > Oleh
>
>


--047d7b624d34a5f6e104e9009f9c--