I'm working on an Emacs mode for people learning Japanese. The point is to help them learn the stroke orders of various Japanese characters (especially kanji) by running a set of functions which extract the character at point and if it is a Japanese character, displaying an image with the stroke order. I have worked out almost all the details, but I have a question about displaying images. I'd like to be able to display the image object (obtained by create-image
) in a popup menu anchored at point. Any hints on doing that? Alternatively I'd like to create a new temporary buffer displaying the image. I've tried using insert-image
with the image object, but all I see in the resulting buffer is an empty rectangle where the image should be. How can I make a buffer with a visible image? Any help greatly appreciated.
Putting an image in a tooltip might help, as a start.
I do that in Dired+ -- see the code for diredp-mouseover-help
and diredp-image-dired-create-thumb
. This is the core of it:
Unless image-dired-thumb-name
says there is already a thumbnail for the image file, use image-dired-create-thumb
to create one. This is the main part of diredp-image-dired-create-thumb
.
Display either the full image or a thumbnail in a tooltip on mouseover:
(let ((img-file (if (eq 'full diredp-image-preview-in-tooltip) file (diredp-image-dired-create-thumb file)))) (propertize " " 'display (create-image img-file)))
A next step could be to put a keymap
or local-map
property on the image, with, say, a mouse-1
binding that acts as the choice action for that image choice. Just a thought - haven't tried it.
You would presumably want to put multiple images in the same tooltip, each with a different action function. Haven't tried that, but you might experiment.
HTH.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With