From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Drag images from Firefox to org-mode Date: Thu, 17 Oct 2013 14:04:10 +0200 Message-ID: References: Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Content-Type: multipart/signed; boundary="Apple-Mail=_126156C5-8F37-41FD-A0A4-812D4163BC14"; protocol="application/pgp-signature"; micalg=pgp-sha1 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWmJT-000594-Ft for emacs-orgmode@gnu.org; Thu, 17 Oct 2013 08:04:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VWmJK-0006Jj-UK for emacs-orgmode@gnu.org; Thu, 17 Oct 2013 08:04:23 -0400 Received: from mail-ea0-x22e.google.com ([2a00:1450:4013:c01::22e]:51521) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWmJK-0006Jc-Mz for emacs-orgmode@gnu.org; Thu, 17 Oct 2013 08:04:14 -0400 Received: by mail-ea0-f174.google.com with SMTP id z15so992578ead.5 for ; Thu, 17 Oct 2013 05:04:13 -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=_126156C5-8F37-41FD-A0A4-812D4163BC14 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 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, >=20 > Here's a little hack that I use to make my life easier: >=20 > (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)))))) >=20 > (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)))) >=20 > (setcdr (assoc "^\\(https?\\|ftp\\|file\\|nfs\\)://" = dnd-protocol-alist) 'dnd-org-insert) >=20 > (defun dnd-org-insert (uri action) > (org-store-image-clipboard uri)) >=20 > When it's a plain image, I can just drag it from the browser to = org-mode.=20 > It will be downloaded in async to a subdirectory of the current = directory and the link will be inserted=20 > at point.=20 > For stubborn images that are links I can right click to copy image = location and call > `org-store-image-clipboard' interactively. >=20 > I hope it's useful to someone and that I'm not re-implementing = standard functionality. >=20 > regards, > Oleh >=20 > regards, > Oleh --Apple-Mail=_126156C5-8F37-41FD-A0A4-812D4163BC14 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----- iQEcBAEBAgAGBQJSX9I6AAoJEO+gg/nAZuwMgtYIAIt+ko/fnN1Enzk6qa53p1AF plLeMVvhgHrvcyD+sxtF6xMl5XXOVSGjcRhYijZrTL7N6pc00mPggtsJ1NR0je/s iTTO42iYfmNMglGYidSs3mbsp4fV+a3Ncun6nnNLvH7KvwZvKUpcw+zFC0anVuRQ bPDCCjCz9iGHKNaktAFZVUI4clqHAFOhKkL+jjZ6Do6oiuDMyoTUCXl4+Tf6mbs5 9YcCjUihrjOYUN1vwEYwVCtlOIhnkQi0Vyw31jTlR9ZcaA0Kv0ZW240yYcqVE4dv 00afFcm9/xPS41uWlK91ngr3JDYXlznZBmOMMij5u8PUQ10iWDl7n0AYmicF4cc= =kmvt -----END PGP SIGNATURE----- --Apple-Mail=_126156C5-8F37-41FD-A0A4-812D4163BC14--