1

I know there's org-toggle-inline-images function, is there something like org-toggle-inline-image-at-point?

1 Answer 1

2

There is no function that's exactly like that.

However if you examine the source code of org-inline-images, you'll see the function org-display-inline-images which takes beg and end, the point that begin and end a region, as arguments. In org-toggle-inline-images, beg and end were omitted so they defaulted to the entire buffer. If you were to use org-display-inline-images on a region containing only one link, it would do what you want.

To undisplay the images you could just call org-toggle-inline-images (it should toggle off because it checks to see if there's any overlays in the global variable org-inline-image-overlays and there will be because org-display-inline-images adds to this variable).

This is very quick code to do this. I've tested it and it works for me.

(defun +org-toggle-inline-image-at-point ()
  "Toggle inline image at point."
  (interactive)
  (if-let* ((bounds (and (not org-inline-image-overlays)
                         (org-in-regexp org-link-any-re nil t)))
            (beg (car bounds))
            (end (cdr bounds)))
      (org-display-inline-images nil nil beg end)
    (org-toggle-inline-images)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.