wehrad · 2022-03-13 11:07
Hi everyone,
​
I would like to automatically refresh my \*Python\* (ipython) buffer when longer than x lines, without refreshing the variables.
​
I had:
`(add-hook 'comint-output-filter-functions 'comint-truncate-buffer)`
​
But it doesn't look like it's doing anything... Any help is much appreciated! Thank you a lot!
7890yuiop · 2022-03-15 07:33
You want to *clear* the buffer? Erase it? That sounds bananas. The normal approach is to set a maximum number of lines, and remove old lines from the beginning of the buffer as necessary to maintain that maximum (without affecting the new lines being appended at the end of the buffer).
> I had:
> `(add-hook 'comint-output-filter-functions 'comint-truncate-buffer)`
> But it doesn't look like it's doing anything...
The purpose of that is what I described above -- remove lines from the beginning of the buffer.
n.b. If that *is* what you want, but you only want it for python, then you'll want something like this:
(add-hook 'inferior-python-mode-hook #'my-inferior-python-mode-hook)
(defun my-inferior-python-mode-hook ()
"Custom `inferior-python-mode' behaviours."
;; (setq-local comint-buffer-maximum-size 1024) ;; maximum lines
(add-hook 'comint-output-filter-functions 'comint-truncate-buffer nil :local))
Edit: In fact see `C-h f inferior-python-mode` which explains that it clobbers `comint-output-filter-functions` buffer-locally, so you actually *need* to do something like I've showed.
wehrad · 2022-03-16 13:50
Perfect, this is exactly what I needed! Thank you a lot!