且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Emacs中出现模式挂钩的奇怪行为

更新时间:2022-10-14 19:24:42

这样做:

 (defadvice occurred(after occurrence-advice activate)
调整大小窗口
(save-selected-window
(pop-to-buffer * Occur *)
(fit-window-to-buffer nil 10))


I am trying to resize the occur-mode buffer window to fit the contents of its buffer.

See Resize occur window in Emacs for more information.

I have added the following hook:

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

Then I have the following buffer window:

and I now execute (occur "test") which gives me first

and after pressing the "ok" button I get

Notice that the occur window has shrunk to a single line in height at the bottom of the frame. This was obviously not what I wanted..

I now enter (occur "test") once more in the "t.txt" buffer, and after pressing "ok" to the message-box I get the following:

So now it suddenly works perfectly. Why is this not working the first time?

This works:

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