Resize occur window in Emacs

寵の児 提交于 2019-12-10 19:10:56

问题


When entering occur mode for example (occur "test") the frame splits into two windows as shown below:

As seen the Occur buffer is taking up too much space on the frame, since there is only two matches (for the text "test"). I would like to shrink that window accordingly.

I tried the following code:

(defun test-occur ()
  (interactive)
  (occur "test")
  (save-window-excursion
    (other-window 1)
    (let (( win (selected-window))
      (n (count-lines (point-min) (point-max)))
      (h (window-body-height)))
      (let ((delta (- (- h n) 3)))
    (window-resize win (- 0 delta) nil)))))

But it does not work (nothing happens with the Occur window)..


回答1:


Just do this:

 (add-hook 'occur-hook
       (lambda ()
         (save-selected-window
           (pop-to-buffer "*Occur*")
           (fit-window-to-buffer))))


来源:https://stackoverflow.com/questions/20913293/resize-occur-window-in-emacs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!