9

It seems like this should be pretty straightforward since Emacs knows how to display images.

In a buffer, let's say I have a URL to an image like:

http://centre.nikkeiplace.org/wp-content/uploads/2012/07/aikido11.jpg

I'd like to put the caret on that url, call a function like expand-image-from-url and have it render the image in-line.

Is this something that's easily possible?

1 Answer 1

12

If you don't mind the image being displayed in a different buffer, just do

M-x ffap 

If you insist on the image appearing in the current buffer, you'll need to do just a little more work:

(require 'url) (defun insert-image-from-url (&optional url) (interactive) (unless url (setq url (url-get-url-at-point))) (unless url (error "Couldn't find URL.")) (let ((buffer (url-retrieve-synchronously url))) (unwind-protect (let ((data (with-current-buffer buffer (goto-char (point-min)) (search-forward "\n\n") (buffer-substring (point) (point-max))))) (insert-image (create-image data nil t))) (kill-buffer buffer)))) 
5
  • That's the thing, I want it displayed inline in the same buffer. Commented May 2, 2015 at 21:30
  • 1
    You're a tough customer. Edited with some sample code. Commented May 2, 2015 at 21:33
  • Very nice! One thing to note: I had to grab some of the 'thingatpt' packages to get it to work. I suppose url-get-url-at-point is not a built-in command. Commented May 2, 2015 at 23:00
  • 1
    You just need (require 'url). Commented May 2, 2015 at 23:03
  • Thank you! Works perfectly. Commented May 2, 2019 at 19:05

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.