当我说M-x compile
时,通常会调用make
程序。完成后,缓冲区*compilation*
通常处于不良状态:窗口的一半留空(可能需要更多输出)。使用C-l C-l
我可以移动到缓冲区的最后一行到窗口的底部 - 所以我看到了更多的实际编译过程。
是否有一种干净的方法来配置compile
,使窗口始终显示最大行数 - 至少在结束时?
答案 0 :(得分:3)
这是我想出的(把它放在你的.emacs
中)。
(defun compilation-redisplay (proc msg)
"Scroll the current window to fit the tail of the buffer
in. This only fires if `compilation-scroll-output' is true"
(when (memq (process-status proc) '(exit signal))
(let ((buffer (process-buffer proc)))
;; Check that the buffer hasn't already been killed
(unless (null (buffer-name buffer))
(with-current-buffer buffer
;; Check we're at the bottom of the buffer and that we're there
;; because compile.el put us there
(when (and compilation-scroll-output
(= (point) (point-max)))
(with-selected-window (get-buffer-window)
;; This logic is pinched from recenter-top-bottom (window.el)
(recenter
(- -1 (min (max 0 scroll-margin)
(truncate (/ (window-body-height) 4.0))))))))))))
(advice-add 'compilation-sentinel :after #'compilation-redisplay)
这个想法是它在编译过程结束时运行。然后进行一些检查以确保有一个合理的缓冲区,compilation-scroll-output
已设置,并且该点位于缓冲区的底部(如果你不想要东西跳转的话)有一个很长的编译过程,你已经开始仔细研究输出了)。最后,来自recenter-top-bottom
的代码中的中心呼叫被盗。