M-x编译更好的最终状态

时间:2015-12-06 21:58:43

标签: emacs

当我说M-x compile时,通常会调用make程序。完成后,缓冲区*compilation*通常处于不良状态:窗口的一半留空(可能需要更多输出)。使用C-l C-l我可以移动到缓冲区的最后一行到窗口的底部 - 所以我看到了更多的实际编译过程。

是否有一种干净的方法来配置compile,使窗口始终显示最大行数 - 至少在结束时?

1 个答案:

答案 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的代码中的中心呼叫被盗。