From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Drag images from Firefox to org-mode Date: Fri, 18 Oct 2013 11:28:46 +0200 Message-ID: References: Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Content-Type: multipart/signed; boundary="Apple-Mail=_AAFC247D-5730-41ED-9D8B-F48419FF9BD2"; protocol="application/pgp-signature"; micalg=pgp-sha1 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34046) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX6MZ-0006cG-6y for emacs-orgmode@gnu.org; Fri, 18 Oct 2013 05:29:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VX6MT-0004Ox-K3 for emacs-orgmode@gnu.org; Fri, 18 Oct 2013 05:28:55 -0400 Received: from mail-ee0-x22b.google.com ([2a00:1450:4013:c00::22b]:52425) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX6MT-0004On-9F for emacs-orgmode@gnu.org; Fri, 18 Oct 2013 05:28:49 -0400 Received: by mail-ee0-f43.google.com with SMTP id e52so1827288eek.30 for ; Fri, 18 Oct 2013 02:28:48 -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: Oleh Cc: org mode --Apple-Mail=_AAFC247D-5730-41ED-9D8B-F48419FF9BD2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 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, >=20 > The dependencies are async, dnd and wget. >=20 > In case dnd doesn't work, there's a fallback to clipboard via > `current-kill'. >=20 > I've just added a custom variable that takes either 'wget or 'curl as > the download method. >=20 > 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. >=20 > The updates are at https://github.com/abo-abo/org-download >=20 > regards, > Oleh >=20 >=20 >=20 > On Thu, Oct 17, 2013 at 2:04 PM, Carsten Dominik = wrote: > Hi Oleh and others, >=20 > 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. >=20 > - Carsten >=20 > On Oct 16, 2013, at 12:04 PM, Oleh wrote: >=20 > > 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 >=20 >=20 --Apple-Mail=_AAFC247D-5730-41ED-9D8B-F48419FF9BD2 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJSYP9OAAoJEO+gg/nAZuwMMVkIAKROKlCVg32/2fAFUWGKUMpv gT1NKBtMSf7hVlqre6IWey58Od4/aZd74c9CIEatObev10o0TffCUNpatg7pDFiF KlNOyOMo36O4u9t0SCiDYfb50QvEUe1Zr6oL3G1k4GU/xiyrbFwWEVFJa7bVsb0c fAJZcQs6JuAQaPg7ViFN2nViCtydSh6AMDrom0odJpQctzxQ8k/8qC5Q3xGCJ9m5 gx9ME0opubh4BNe3LszHqPvjuyShJ+zybsCaHqVNUDaw8E8jd+Ajm/42U47nWy+Y dLUYTRwxQv5IFi+t3T11Y2H5TfbP9mlOZHSqPtsFvlwOm1f0rX7FYo7284Tg1mk= =2Y1q -----END PGP SIGNATURE----- --Apple-Mail=_AAFC247D-5730-41ED-9D8B-F48419FF9BD2--