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 <ohwoeowho@gmail.com> 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