是否可以限制Emacs编译缓冲区存储的行数?如果没有遇到错误,我们的构建系统可以在整个产品构建中产生大约10,000行输出。由于我的编译缓冲区也会解析ANSI颜色,因此非常非常慢。我想只有例如缓冲了2,000行输出。
答案 0 :(得分:9)
似乎comint-truncate-buffer
对于编译缓冲区的效果与对shell缓冲区的效果一样:
(add-hook 'compilation-filter-hook 'comint-truncate-buffer)
(setq comint-buffer-maximum-size 2000)
我通过使用命令compile
运行perl -le 'print for 1..10000'
来测试此问题。完成后,编译缓冲区中的第一行是8001
。
答案 1 :(得分:3)
好的,我坐下来编写了自己的函数,插入到编译过滤器钩子中。它可能不是性能最佳的解决方案,但到目前为止似乎工作正常。
(defcustom my-compilation-buffer-length 2500
"The maximum number of lines that the compilation buffer is allowed to store")
(defun my-limit-compilation-buffer ()
"This function limits the length of the compilation buffer.
It uses the variable my-compilation-buffer-length to determine
the maximum allowed number of lines. It will then delete the first
N+50 lines of the buffer, where N is the number of lines that the
buffer is longer than the above mentioned variable allows."
(toggle-read-only)
(buffer-disable-undo)
(let ((num-lines (count-lines (point-min) (point-max))))
(if (> num-lines my-compilation-buffer-length)
(let ((beg (point)))
(goto-char (point-min))
(forward-line (+ (- num-lines my-compilation-buffer-length) 250))
(delete-region (point-min) (point))
(goto-char beg)
)
)
)
(buffer-enable-undo)
(toggle-read-only)
)
(add-hook 'compilation-filter-hook 'my-limit-compilation-buffer)