emacs - Emacs 中发生模式 Hook 的奇怪行为

标签 emacs elisp

我正在尝试调整 occurr-mode 缓冲区窗口的大小以适应其缓冲区的内容。

参见Resize occur window in Emacs了解更多信息。

我添加了以下钩子(Hook):

(add-hook 'occur-mode-hook
       (lambda ()
         (save-selected-window
           (pop-to-buffer "*Occur*")
       (message-box "ok")
       (fit-window-to-buffer nil 10))))

然后我有以下缓冲窗口:

enter image description here

我现在执行(occurr "test"),这给了我第一个

enter image description here

按下“确定”按钮后,我得到

enter image description here

请注意,出现的窗口的高度已缩小到框架底部的一行。这显然不是我想要的..

我现在在“t.txt”缓冲区中再次输入(occurr "test"),在消息框中按“ok”后,我得到以下内容:

enter image description here

所以现在它突然完美了。为什么第一次不起作用?

最佳答案

这有效:

(defadvice occur (after occur-advice activate)
  "Resize window."
  (save-selected-window
    (pop-to-buffer "*Occur*")
    (fit-window-to-buffer nil 10)))

关于emacs - Emacs 中发生模式 Hook 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20919308/

相关文章:

emacs - 在 emacs 中,如何杀死多个缓冲区而不单独打开每个缓冲区

Emacs - 如何在 BOTH - projectile 和 treemacs 中自动添加新项目?

emacs - emacs 底部命令行的高度

emacs - 在 emacs 中,*Help* 缓冲区中的 "hyperlink"是如何工作的?

php - 如何在 Emacs 中关闭 php-indent 警告

string - 将字符串转换为首字母大写 - Emacs Lisp

emacs - 确定模式行中的窗口焦点?

macos - 在Mac OS X上,Vim和Emacs的首选版本是什么?

emacs - 如何在 emacs 中将待办事项优先级组织为列?

emacs - 在 Emacs 中将字符串列表转换为扁平字符串?