7

Emacs コンパイル バッファが格納する行数を制限することは可能ですか? 当社のビルド システムは、エラーが発生しなければ、製品ビルド全体で約 10,000 行の出力を生成できます。私のコンパイル バッファは ANSI カラーも解析するため、非常に遅くなる可能性があります。たとえば、2,000 行の出力をバッファリングしたいと考えています。

4

2 に答える 2

10

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.

于 2012-06-29T02:41:28.543 に答える
4

わかりました、私は座って、コンパイル フィルター フックにプラグインされる独自の関数を作成しました。これは最高のパフォーマンスを発揮するソリューションではないかもしれませんが、今のところ問題なく動作しているようです。

(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)
于 2012-06-28T07:28:20.970 に答える