Search code examples
emacsorg-modedired

Copy links from image-dired to org-mode


I'm working with directories full of images, which are photographs of documents in an archive. I'm writing org files with notes on the content of these, and I would like to make it quicker and easier to browse the images (e.g. with image-dired) and copy links into the org-mode file alongside my notes.

My working setup looks like this:

Image browser and org in emacs

My questions are:

  • How can I automatically copy a link for the currently displayed image into org?
  • Is there any easy way to control the image-dired picture (browsing backwards and forwards, rotating) from within the org windows?
  • Are there any other modes or tools that I should be looking at?

Solution

  • Here is a little code to make working with images easier. Just copy it into your *scratch* buffer and run M-x eval-buffer.

    (defun my-next-image ()
      (interactive)
      (save-excursion 
        (with-current-buffer "*image-dired*"
          (image-dired-forward-image)
          (image-dired-display-thumbnail-original-image))))
    
    (defun my-prev-image ()
      (interactive)
      (save-excursion 
        (with-current-buffer "*image-dired*"
          (image-dired-backward-image)
          (image-dired-display-thumbnail-original-image))))
    
    (defun my-insert-current-image-path ()
      (interactive)
      (insert
       (concat
        "[["
        (save-excursion
          (with-current-buffer "*image-dired*"
            (image-dired-original-file-name)))
        "]]")))
    
    
    (define-key org-mode-map (kbd "<f9> n") 'my-next-image)
    (define-key org-mode-map (kbd "<f9> p") 'my-prev-image)
    (define-key org-mode-map (kbd "<f9> i") 'my-insert-current-image-path)
    

    Press F9 n to switch to the next image while in org mode, press F9 i to insert a link to the current image. Rebind keys to your liking.