From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xebar Saram Subject: Re: Drag images from Firefox to org-mode Date: Wed, 16 Oct 2013 16:22:06 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b2e48ee0e152f04e8dc6df4 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWRzG-0000eI-E7 for emacs-orgmode@gnu.org; Wed, 16 Oct 2013 10:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VWRzE-0003aI-GO for emacs-orgmode@gnu.org; Wed, 16 Oct 2013 10:22:10 -0400 Received: from mail-ob0-x22d.google.com ([2607:f8b0:4003:c01::22d]:45797) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWRzE-0003a4-9K for emacs-orgmode@gnu.org; Wed, 16 Oct 2013 10:22:08 -0400 Received: by mail-ob0-f173.google.com with SMTP id vb8so615502obc.4 for ; Wed, 16 Oct 2013 07:22:07 -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: Torsten Wagner Cc: org mode , Oleh --047d7b2e48ee0e152f04e8dc6df4 Content-Type: text/plain; charset=ISO-8859-1 Thx Oleh ,This is really amazing! Ive been waiting for ages for something like this. a few questions (well ok"requests" :)..) if you dont mind. please bare in mind i have zero coding skills (or understanding so my questions may be stupid :)) 1.i use alot of images and :in alot of headings and sub headings and the current method creates tens of folders. can you make an option to store all images in a central location, IE ~/org/images? also Torstens suggestion of adding a date to the file name makes alot of sense :) 2.can you add an option to add a local file (IE drag a jpg/png from a folder) or even better yet build into the script a screenshot ability function (using scrot etc) like in the following script: http://lists.gnu.org/archive/html/emacs-orgmode/2013-05/msg00873.html 3.maybe perhaps a text scraper that would do the same for formatted text, so one would mark a section in the browser, and drag it into org (and the script would automagicly would get rid of the html yuckyness << notice my highly technical coding terms and knowledge) best and thanks alot! Z On Wed, Oct 16, 2013 at 4:48 PM, Torsten Wagner wrote: > This looks like a nice feature! > Maybe you could add to save the address and date the picture was taken, > thus, one could easily refer to the image origin. That is sometimes of > importance. > > Thanks for sharing > > Torsten > > > > On 16 October 2013 12:04, 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 >> > > --047d7b2e48ee0e152f04e8dc6df4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thx O= leh ,This is really amazing!

Ive been waiting for= ages for something like this. a few questions (well ok "requests" :)..) if you dont mind. please bare in mind i have zero coding skills (or understanding = so my questions may be stupid :))

1.i use alot of ima= ges and :in alot of headings and sub headings= and the current method creates tens of folders. can you make an option to = store all images in a central location, IE ~/org/images? also Torstens suggestion of adding a date to the file name ma= kes alot of sense :)

2.can you add an option to add a local file (IE drag a = jpg/png from a = folder) or even better yet build into the script a screenshot ability funct= ion (using scrot etc) like in the following s= cript:

http://l= ists.gnu.org/archive/html/emacs-orgmode/2013-05/msg00873.html

=

3.maybe perhaps a text scraper that wo= uld do the same for formatted text, so one would mark a section in the brow= ser, and drag it into org (and the script would auto= magicly would get rid of the html yuckyness << notice my highly technical coding terms and knowledge)

best and th= anks alot!
Z

On W= ed, Oct 16, 2013 at 4:48 PM, Torsten Wagner <= span dir=3D"ltr"><torsten.wagner= @gmail.com> wrote:
This looks like a nice feature!=
Maybe you could add to save the address and date the picture was= taken, thus, one could easily refer to the image origin. That is sometimes= of importance.
=A0
Thanks for sharing
Torsten


On 16 October 2013 12:04, Oleh <ohwoe= owho@gmail.com> wrote:
Hi all,

Here's a l= ittle 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 &qu= ot;wget \"%s\" -P \"%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
<= div>=A0 =A0 =A0 =A0 =A0(org-display-inline-images))))))

(defun org-store-image-clipboard (link)
=A0 &= quot;Save image at address LINK to current directory's subdirectory DIR= .
DIR is the name of the current level 0 heading."
=A0 (interactive (list (current-kill 0)))
=A0 (let ((filename (ca= r (last (split-string link "/"))))
=A0 =A0 =A0 =A0 (dir= (save-excursion
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(org-up-heading-a= ll (1- (org-current-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 (nu= ll (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 (inser= t (format "[[./%s/%s]]" dir filename))
=A0 =A0 =A0 (org= -display-inline-images))))

(setcdr (assoc "^\\(https?\\|ftp\\|file\\|nfs\\):/= /" dnd-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 f= rom the browser to org-mode.=A0
It will be downloaded in async to= a subdirectory of the current directory and the link will be inserted=A0
at point.=A0
For stubborn images that are links I can right = click to copy image location and call
`org-store-image-clipboard&= #39; interactively.

I hope it's useful to some= one and that I'm not re-implementing standard functionality.

regards,
Oleh

regard= s,
Oleh


--047d7b2e48ee0e152f04e8dc6df4--