我能否限制在Emacs编辑缓冲区的长度?(Can I limit the length of the

2019-06-25 20:25发布

是否有可能限制线是Emacs的编译缓冲区门店数量? 我们的构建系统可以产生对整个产品产量建立的一些10000行,如果没有遇到任何错误。 由于我的编译缓冲区也ANSI解析色彩,这会造成非常,非常缓慢。 我想有只如2000输出的行缓冲。

Answer 1:

看来, comint-truncate-buffer效果一样好编译缓冲区因为它的外壳缓冲区:

(add-hook 'compilation-filter-hook 'comint-truncate-buffer)
(setq comint-buffer-maximum-size 2000)

我通过运行测试这个compile用命令perl -le 'print for 1..10000' 。 当它被完成,在编译缓冲区中的第一行是8001



Answer 2:

好吧,我坐下来写我自己的函数,它被插入到编译过滤器钩。 它可能不是最好的表演方案,但到目前为止,似乎很好地工作。

(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)


文章来源: Can I limit the length of the compilation buffer in Emacs?
标签: emacs elisp