emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Drag images from Firefox to org-mode


From: Torsten Wagner
Subject: Re: [O] Drag images from Firefox to org-mode
Date: Wed, 16 Oct 2013 15:48:58 +0200

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 <address@hidden> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]