From: Steve Haflich

Subject: Re: xemacs lisp listener buffer max size

Date: 1997-10-7 14:52

   From: Roy Turner <umcs.maine.edu at rmt>
   
   dryan> Exactly the problem.  We have an application that must run continuously
   dryan> for *months* while still displaying output to the buffer (thus we 
   dryan> can't completely turn off output), yet not eventually die because 
   dryan> a buffer fills up.
   
   This would be a kludge, but what about either an Emacs Lisp function or a ACL
   function that periodically woke up and cleared out all but the last x lines of
   the buffer?

This proposal is simple, provided one is willing to do a little elisp
programming, but consider this thought experiment:

(defun tailify-buffer (lines)
  "Truncate the current buffer to the last n LINES."
  (interactive  "nNumber of lines: ")
  (let (beg end)
    (save-excursion
      (end-of-buffer)
      (forward-line (- lines))
      (setq end (point))
      (beginning-of-buffer)
      (setq beg (point)))
    (delete-region beg end)))

 You somehow cause this to be invoked to kill all but the last N lines
of the buffer.  The unneeded output disappears.
 You make that buffer current and type C-_ (or M-x undo) and the
deleted output reappears.

Emacs is very reticent to throw anything away.  (Undo information is
separate from the kill ring.  delete-region does not interact with the
kill ring.)  You can control this, assuming you don't really need undo
to be available in this buffer.  See buffer-disable-undo.

I believe to buffer-disable-undo appearently flushes all undo
information (but check -- undo informtion is kept in a buffer-local
variable -- see buffer-local-variables).  It need be called just once,
but is probably harmless to call repeatedly.

tailify-buffer can be invoked interactively or programmatically.  If
you want it to be interactive the question is where to put the call.

See the emacs-lisp source file fi-subproc.el.  There is an
undocumented hook variable fi::subprocess-filter-insert-output-hook
which I believe is unused except by the "presenting listener" in
Composer.  It could probably be used in the initial lisp listener to
call tailify-buffer, something like this, after the ACL has started in
the buffer:

(save-excursion
  (set-buffer "*common-lisp*")
  (buffer-disable-undo)
  ;; This will be called each time CL output is inserted into the buffer,
  ;; just before the output is inserted.
  (setq fi::subprocess-filter-insert-output-hook 'tailify-1000))

(defun tailify-1000 ()
  (tailify 1000))

None of this is checked, and anyone who uses it would have to take the
responsibility for debugging it, supporting it, and keeping up with
future versions.