Могу ли я ограничить длину буфера компиляции в Emacs?

Можно ли ограничить количество строк, которые хранит буфер компиляции Emacs? Наша система сборки может выдать около 10 000 строк на целые сборки продукта, если ошибок не обнаружено. Так как мой буфер компиляции также анализирует цвета ANSI, это может быть очень и очень медленным. Я хотел бы иметь только, например, 2000 строк буферизованного вывода.

2 ответа

Решение

Похоже, что 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,

Хорошо, я сел и написал свою собственную функцию, которая подключается к крюку compilation-filter-hook. Возможно, это не самое эффективное решение, но пока оно работает нормально.

(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)
Другие вопросы по тегам