TransWikia.com

Fixed length buffer for shell

Emacs Asked on September 2, 2021

I launch a shell in my session with M-x shell and then I launch a python script that produces a lot of output to stdout—so many lines of output that my emacs session beomes quite slow.

Is there a command I can run to ask my buffer to be fixed length and automatically delete lines older than N? I have tried looking this up, but don’t even know what terms to use in my query beyond "automatically delete," "circular buffer" and "fixed length" which were not helpful.

One Answer

comint-buffer-maximum-size is a variable defined in ‘comint.el’.
Its value is 1024

Documentation:
The maximum size in lines for Comint buffers.
Comint buffers are truncated from the top to be no greater than this number, if
the function ‘comint-truncate-buffer’ is on ‘comint-output-filter-functions’.

You can customize this variable.
(defun my-shell-mode-hook ()
  "Custom `shell-mode' behaviours."
  (add-hook 'comint-output-filter-functions 'comint-truncate-buffer nil :local))

(add-hook 'shell-mode-hook 'my-shell-mode-hook)

Answered by phils on September 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP