I want to temporarily insert an image and a newline in the buffer, all using put-image. That is, I want the buffer to look like this:


I want the newline to be part of the overlay.

I understand that the third parameter (STRING) in put-image can be used to achieve that effect. But I am not sure about how to set that parameter. The code I have unsuccessfully tried is this:

(put-image (create-image "image.gif") (point) #(" \n" 0 1 (display)))

For which I get the error "Odd length text property list". What am I doing wrong?

1 Answer 1


You're misinterpreting the STRING parameter here. The docs state it's a string used as the before-string property with an image on top of it. Therefore, if you do (put-image (create-image "image.gif") (point) "Some image"), "Some image" would be displayed before point weren't it for the image layered on top of it which visually replaces that text. You can check this for yourself by trying out that snippet in a graphical and textual Emacs instance and will notice the textual one will indeed display your string (but obviously not your image), sort of like alt-tags in HTML do. In fact, I assume this is the intended usecase for that parameter in put-image.

In other words, put-image is the wrong function for that level of control over overlays. Here's an example that should achieve what you're asking for:

(let ((ov (make-overlay (point) (point))))
  (overlay-put ov 'before-string (propertize " " 'display (create-image "image.gif")))
  (overlay-put ov 'after-string "\n"))

Your Answer

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

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