Domanda

One can display an image in the current buffer by executing:

(insert-image (create-image "image.png"))

I would like to know how to display an image, not in the current buffer, but in the minibuffer at the bottom of the screen.

Using (select-window (active-minibuffer-window)) to select the minibuffer does not seem to work--for some reason (active-minibuffer-window) returns nil.

Any ideas? Many thanks!

Update:

Now I know how to display an image in the minibuffer:

(with-current-buffer (window-buffer (minibuffer-window))
  (insert-image (create-image "image.png")))

What I don't know is how to resize the minibuffer so that the image fits.

È stato utile?

Soluzione

OK. So after some trial and error, here's the function I wanted:

(defun my-show-image-in-minibuffer (filename)
  (let* ((img (create-image filename))
         (y   (floor (cdr (image-size img)))))
    (with-current-buffer (window-buffer (minibuffer-window))
      (setq resize-mini-windows 'grow-only)
      (setq resize-mini-windows nil)
      (delete-minibuffer-contents)
      (window-resize (minibuffer-window) y)
      (insert-image img))
    (clear-this-command-keys t)
    (read-event)
    (with-current-buffer (window-buffer (minibuffer-window))
      (delete-minibuffer-contents)
      (window-resize (minibuffer-window) (- 0 y))
      (setq resize-mini-windows 'grow-only))
    (image-flush img)
    (setq unread-command-events (list last-input-event))))

Additionally, after any key is pressed, it deletes the image and returns the minibuffer to its normal size.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top