[comp.emacs] Why does this break!

anthony@cs.UAlberta.CA (Anthony Mutiso) (01/29/91)

Why doe the follow elisp code fail to work correct.

=========
(defun my-redisplay-process-output-filter (proc str)
  (if (eq (current-buffer) (process-buffer proc))
      (progn
	(goto-char (point-max))
	(insert str))
    (save-excursion
      (set-buffer (process-buffer proc))
      (goto-char (point-max))
      (insert str)
      (set-mark (point-max))
      (save-window-excursion
	 (select-window (get-buffer-window (process-buffer proc)))
	 (if (not (pos-visible-in-window-p (point)))
	     (recenter -1)))))
  (set-marker (process-mark proc) (point-max) (process-buffer proc))
  str)
=========

I do a 

(set-process-filter (get-buffer-process "*cmushell*")
		    (function my-redisplay-process-output-filter))
to set this function to be a process filter for a shell process
buffer. What I would like the function to do is cause all output to
the buffer to be displayed even if another buffer is the current
buffer. (For example when using tex-mode to tex a buffer, I would like
to see the output appear as it arrives, so I do not have to do a CTRL-l
to re-center the buffer (it happens auto-magically).

The above function works, (well sort of), once, then it fails. Any
attempt use the buffer, cause weird  stuff to be sent to the buffer.

In a shell buffer try the following (after setting the
process-filter):-

%> sleep 2; date<cr>

Then switch to another window and watch. This should go fine the first
time.
Switch back to the shell window and try just a <cr>. The shell will
hang for a while. You may have to do a keyboard-quit to break it and
all this weird output should come screaming  by. The output if based on
what is previously in the buffer.


Help!!! Anyone.

Related Question:

Does anyone have an elisp function that does what I am trying to
implement? Namley scroll shell output as it arrives!

Thanks

Anthony
--
Anthony Mutiso (403-492-2821)                   anthony@cs.ualberta.ca
Department of Computing Science.                anthony@alberta.UUCP
University of Alberta                           anthony%alberta@ualtamts.bitnet
Edmonton, Alberta. CANADA                       toni@ualtamts.bitnet