调整迷你缓冲区的大小以适合那里显示的图像

时间:2014-04-17 02:50:21

标签: emacs elisp

可以通过执行以下命令在当前缓冲区中显示图像:

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

我想知道如何显示图像,而不是在当前缓冲区中,而是在屏幕底部的迷你缓冲区中。

使用(select-window (active-minibuffer-window))选择迷你缓冲区似乎不起作用 - 由于某种原因,(active-minibuffer-window)会返回nil

有什么想法吗?非常感谢!

更新

现在我知道如何在迷你缓冲区中显示图像:

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

我不知道的是如何调整迷你缓冲区的大小以使图像适合。

1 个答案:

答案 0 :(得分:1)

行。经过一些试验和错误,这是我想要的功能:

(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))))

此外,按任意键后,它会删除图像并将迷你缓冲区恢复为正常大小。