[gnu.emacs.help] CMU Process Modes addenda 2.01b

shivers@A.GP.CS.CMU.EDU (Olin Shivers) (10/24/90)

BUFFER LIMITS:
Some operating systems choke when a large chunk of text is sent
down a pipe or a pty. In previous versions of the CMU process
modes, this would cause large text sends to subprocesses to hang
emacs and the subprocess. This has been fixed in release 2, so you
can now happily stuff entire file buffers to a subprocess if you like.
See the variable
    comint-input-chunk-size
and the function
    comint-send-string
for more information. This feature has been in place since release 2.00;
I mention it now to draw the attention of potential users who have
been unable to use these modes on their machines for this reason.


ALLEGRO COMMON LISP:
Decstation/Ultrix users have been reporting problems running Allegro Common
Lisp under cmulisp.el or ilisp.el. The symptom is that lisp croaks immediately
after being started up by emacs. I am told this is an Ultrix bug, and the
workaround is to change ilisp-program or inferior-lisp-program to be:
    (setq ilisp-program "/bin/sh -c /usr/lisp/bin/cl")
(or wherever your copy of the executable happens to live).

I have no idea why this bug occurs or why invoking cl via /bin/sh fixes it.
I'm just relaying the information. This bug was reported by several people,
and the fix reported by Brian Dennis.


BACKGROUND:
There is a bug in background.el that fails to correctly set the working
directory in some cases. The fixed version is installed at CMU in the
distribution directory that can be accessed via anonymous ftp. The entire
package is short, so it is appended to this msg in its entirety. The bug was
reported by Piet van Oostrum.
    -Olin
===============================================================================
;; Fun with background jobs.
;; Copyright (C) 1988 Joe Keane <jk3k+@andrew.cmu.edu>
;; Refer to the GNU Emacs General Public License for copyright info.

;; - Adapted to use comint and cleaned up somewhat. Olin Shivers 5/90
;; - Background failed to set the process buffer's working directory
;;   in some cases. Fixed. Olin 6/14/90
;; - Background failed to strip leading cd's off the command string
;;   after performing them. This screwed up relative pathnames.
;;   Furthermore, the proc buffer's default dir wasn't initialised 
;;   to the user's buffer's default dir before doing the leading cd.
;;   This also screwed up relative pathnames if the proc buffer already
;;   existed and was set to a different default dir. Hopefully we've
;;   finally got it right. The pwd is now reported in the buffer
;;   just to let the user know. Bug reported by Piet Van Oostrum.
;;   Olin 10/19/90

(provide 'background)
(require 'comint)

;; user variables
(defvar background-show t
  "*If non-nil, background jobs' buffers are shown when they're started.")
(defvar background-select nil
  "*If non-nil, background jobs' buffers are selected when they're started.")

(defun background (command)
  "Run COMMAND in the background like csh.  
A message is displayed when the job starts and finishes.  The buffer is in
comint mode, so you can send input and signals to the job.  The process object
is returned if anyone cares.  See also comint-mode and the variables
background-show and background-select."
  (interactive "s%% ")
  (let ((job-number 1)
	(job-name "%1")
	(dir default-directory))
    (while (process-status job-name)
      (setq job-name (concat "%" (setq job-number (1+ job-number)))))
    (if background-select (pop-to-buffer job-name)
      (if background-show (with-output-to-temp-buffer job-name)) ; cute
      (set-buffer (get-buffer-create job-name)))
    (erase-buffer)
    (setq default-directory dir) ; Do this first, in case cd is relative path.
    (cond ((string-match "^cd[\t ]+\\([^\t ;]+\\)[\t ]*;[\t ]*" command)
	   (setq default-directory
		 (file-name-as-directory
		  (expand-file-name
		   (substring command (match-beginning 1) (match-end 1)))))
	   (setq command (substring command (match-end 0)))))
    (insert "--- working directory: " default-directory
	    "\n% " command ?\n)
    (let ((proc (get-buffer-process
		 (comint-exec job-name job-name shell-file-name
			      nil (list "-c" command)))))
      (comint-mode)
      ;; COND because the proc may have died before the G-B-P is called.
      (cond (proc (set-process-sentinel proc 'background-sentinel)
		  (message "[%d] %d" job-number (process-id proc))))
      (setq mode-name "Background")
      proc)))

(defun background-sentinel (process msg)
  "Called when a background job changes state."
  (let ((msg (cond ((string= msg "finished\n") "Done")
		   ((string-match "^exited" msg)
		    (concat "Exit " (substring msg 28 -1)))
		   ((zerop (length msg)) "Continuing")
		   (t (concat (upcase (substring msg 0 1))
			      (substring msg 1 -1))))))
    (message "[%s] %s %s" (substring (process-name process) 1)
	                  msg
			  (nth 2 (process-command process)))
    (if (null (buffer-name (process-buffer process)))
	(set-process-buffer process nil) ; WHY? Olin.
	(if (memq (process-status process) '(signal exit))
	    (save-excursion
	      (set-buffer (process-buffer process))
	      (let ((at-end (eobp)))
		(save-excursion
		  (goto-char (point-max))
		  (insert ?\n msg ? 
			  (substring (current-time-string) 11 19) ?\n))
		(if at-end (goto-char (point-max))))
	      (set-buffer-modified-p nil))))))