[comp.emacs] Garbaged input in shell buffer

dave@ttrnds.UUCP (David M. Karr) (02/03/90)

Ok, I've had enough of this bug.  I am using Gnuemacs(18.55).  I have
modified my shell package to implement some slightly strange (to other
people) features.  I have a feeling that something I have done is the
cause of the problem I am having.

    My modifications:

    	1.  Bell characters are all removed from the shell output.  I use
    	    a shell filter to do this.  They are replaced with one
    	    ring of the terminal bell.
    	2.  Normally, the cursor follows the output coming into the
    	    shell buffer.  I set it so that if the cursor is sitting
    	    at the beginning of the prompt line, it doesn't get thrown
    	    to the end of the shell output.  That way I can easily see
    	    the first few lines of output.

    My bug:

    First of all, I have two buffers open.  One is the shell buffer
and the other is anything else (not the shell buffer).  In the shell
buffer, I type a command that generates a lot of output quickly (I use
"ls -lt" as my test case).  Just after pressing return to send the
command, I switch to the other buffer.  If I don't switch buffers, the
cursor ends up at the end of the "ls" output and nothing is wrong.
When I switch buffers, the shell buffer stops scrolling after the
output from "ls" hits the bottom of the window.  Then I switch back to
the shell buffer and go to the end of the buffer.  The output is fine
at this point.  I then type any command (I use "cd" as my test case)
and press return.  At that point it seems like it is taking longer
than it should for the cursor to go to the next line and start doing
something.  I then press ^G to abort what it was doing.  It then spews
out dozens of lines where it thought that I typed in pieces of the
"ls" output as commands to the shell.  For instance, I get lots of
stuff like this: "[52;cheetos] drwxrwsr-x: Command not found.".  The
string "[52;cheetos]" is my prompt.

    As a result of this, I hesitate to switch out of the shell buffer
when I have output coming to it.

    Any ideas?
-- 
----------------------------------------
David Karr    dave@ttrnds.UUCP  or  ...amc-gw!ttrnds!dave
Teltrend Corp., 12034 115th Ave. NE, Kirkland, WA 98034 (206)820-6500
"The above statements do not necessarily reflect the opinions of my employer."

dave@ttrnds.UUCP (David M. Karr) (02/07/90)

Some people asked me to just include here my filters and stuff that I
use with my shell buffer so they can try it themselves to see what
happens.  Well, here it is.  Some of it probably isn't important, but
who knows?

(defun shell-backward-command ()
  "Search backwards for the previous command line and go to the end of
that line."
  (interactive)
  (beginning-of-line)
  (re-search-backward shell-prompt-pattern nil t)
  (end-of-line))

(defun shell-forward-command ()
  "Search forwards for the next command line and go to the end of
that line."
  (interactive)
  (end-of-line)
  (re-search-forward shell-prompt-pattern nil t)
  (end-of-line))

(defun ssd-for-lfd ()
  "Instead of just doing shell-send-input, this calls that and then goes to the
beginning of the previous line."
  (interactive)
  (shell-send-input)
  (previous-line 1)
  (beginning-of-line)
  (line-to-top))

(defun shell-filter (proc string)
  "Replace CTL-G(s) in shell output with a single call to ding."
  (save-excursion
    (set-buffer (process-buffer proc))
    (setq nomove (looking-at shell-prompt-pattern))
;    (setq savepoint (point))
    (goto-char (point-max))
    (save-excursion (insert string))
    (while (re-search-forward "\\([]+\\)[^]*" nil t)
      (ding)
      (delete-region (match-beginning 1) (match-end 1)))
;    (goto-char savepoint)
    )
  (move-marker (process-mark proc) (point-max))
  (if (and (not nomove) (eq (current-buffer) (process-buffer proc)))
;  (if (not nomove)
      (goto-char (point-max)))
  )

(setq shell-mode-hook
      '(lambda ()
	 (setq mode-line-format
	       (list "%b--" (getenv "HOST")
		     'default-directory "---%M---%3p---%[(%m: %s)%]%-"))
	 (local-set-key "\^j" 'ssd-for-lfd)
	 (local-set-key "\C-c\C-p" 'shell-backward-command)
	 (local-set-key "\C-c\C-n" 'shell-forward-command)
	 (define-key shell-mode-map "\C-i" 'shell-expand-file-name)
	 (setq shell-prompt-pattern "^\\[[0-9][0-9]*;[a-z][a-z]*\\] ")
	 (setq shell-pushd-regexp "pushd\\|\+")
	 (setq shell-popd-regexp "popd\\|\-")
	 (set-process-filter
	  (get-process (substring (buffer-name) 1 -1)) 'shell-filter)))
-- 
----------------------------------------
David Karr    dave@ttrnds.UUCP  or  ...amc-gw!ttrnds!dave
Teltrend Corp., 12034 115th Ave. NE, Kirkland, WA 98034 (206)820-6500
"The above statements do not necessarily reflect the opinions of my employer."