From: dwork@angelo.amd.com (Jeff Dwork)
Newsgroups: gnu.emacs.help
Subject: Re: Wish list of common but obsure Emacs commands
Date: 6 Oct 92 19:40:29 GMT
Organization: Advanced Micro Devices, Santa Clara, CA

In article <DODD.92Oct6045215@mycenae.cchem> dodd@mycenae.cchem (Lawrence R. Dodd) writes:
>
>>>>>> "Warren" == Warren F. Kuhfeld <saswfk@thurstne.unx.sas.com> writes:
>
>  Warren> |> >     6. If I already have a window in shell-mode called
>  Warren> |> >        *shell*, create an independent shell. Do this some
>  Warren> |> >        easy way without requiring *shell* and the second
>  Warren> |> >        window be renamed.
>
>  Warren> I never bring up *shell* but instead use a function that brings
>  Warren> up each new shell with a different name.
>
>cmushell used to be able to create multiple cmushell buffers but somewhere
>along in its development this got disabled.  Anyone know why?

I use the following which I modified from multi-shell.el (in the elisp
archive in ~/misc/multi-shell.el.Z):
----------------------- cut here -------------------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;    Multiple Simultaneous shell 
;;    Tracking shell - track the directory of buffer every time
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Modified 06/17/91 - Jeff Dwork
;;
;; Copyright (C) Aamod Sane (sane@cs.uiuc.edu)
;; Author: Aamod Sane
;; This file is not part of GNU Emacs yet.
;; The FSF copyright below applies to this file.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY.  No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing.  Refer to the GNU Emacs General Public
;; License for full details.

;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License.   A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities.  It should be in a
;; file named COPYING.  Among other things, the copyright notice
;; and this notice must be preserved on all copies.

;; Modified by Jeff Dwork (jeff.dwork@amd.com) - 06/17/91
;; This version names the shells '*cmushell*', '*cmushell*<2>', etc.
;; It also switches-to-buffer when shell is created.

(require 'cmushell)

(defun multi-shell(&optional n)
  "Each time you invoke this, a new shell will be popped.
See the documentation for cmushell for other details."
  (interactive)
  (let* ((name (if (null n) "cmushell" n)) 
	 (buf (generate-new-buffer (concat "*" name "*"))) 
	 (bufnam (buffer-name buf)))
    (cond ((not (comint-check-proc bufnam))
	   (let* ((prog (or explicit-shell-file-name
			    (getenv "ESHELL")
			    (getenv "SHELL")
			    "/bin/sh"))		     
		  (name (file-name-nondirectory prog))
		  (startfile (concat "~/.emacs_" name))
		  (xargs-name (intern-soft (concat "explicit-" name "-args"))))
	     (save-excursion 
	       (set-buffer (apply 'multi-comint bufnam prog
				  (if (file-exists-p startfile) startfile)
				  (if (and xargs-name (boundp xargs-name))
				      (symbol-value xargs-name)
				    '("-i"))))
	       (cmushell-mode)))))
    (switch-to-buffer bufnam)))


(defun multi-comint (name program &optional startfile &rest switches)
  (let* ((buffer (get-buffer-create name))
	 (proc (get-buffer-process buffer)))
    ;; If no process, or nuked process, crank up a new one and put buffer in
    ;; comint mode. Otherwise, leave buffer and existing process alone.
    (cond ((or (not proc) (not (memq (process-status proc) '(run stop))))
	   (save-excursion
	     (set-buffer buffer)
	     (comint-mode)) ; Install local vars, mode, keymap, ...
	   (comint-exec buffer name program startfile switches)))
    buffer))

(defconst tracking-shell-default-directory "~")
(defconst tracking-shell-name "*Tracking-Shell*")
(defconst tracking-shell-name-nostar "Tracking-Shell")

(defvar tracking-shell-other-window t
  "*Whether tracking shell should appear in current window or not")

;; When invoked from a buffer, Tracking-Shell cd's to that buffers directory.
;; Thus to do something in the current directory of a buffer, pop up
;; a tracking-shell, do whatever, and close the shell. Automatic cd'ing
;; allows direct usage of shell commands; complicated key sequences are
;; not neccessary for file manipulation.

(defun tracking-shell()
  "When invoked from a buffer, if Tracking-Shell does
not exist, it is created. If it exists, a cd is sent to the shell
to synchronize the directory to that of the buffer in which this function is
called. See the documentation of cmushell for other details."
  (interactive)
  (cond ((not (comint-check-proc tracking-shell-name))
	 (let* ((prog (or explicit-shell-file-name
			  (getenv "ESHELL")
			  (getenv "SHELL")
			  "/bin/sh"))		     
		(name (file-name-nondirectory prog))
		(startfile (concat "~/.emacs_" name))
		(xargs-name (intern-soft (concat "explicit-" name "-args"))))
	   (set-buffer (apply 'make-comint tracking-shell-name-nostar prog
			      (if (file-exists-p startfile) startfile)
			      (if (and xargs-name (boundp xargs-name))
				  (symbol-value xargs-name)
				'("-i"))))
	   (cmushell-mode)))
	(t 
	 (let* ((bfn (buffer-file-name)) 
		(dir (if (null bfn) 
			 tracking-shell-default-directory 
		       (file-name-directory bfn))))
	   (comint-send-string 
	    (get-buffer-process tracking-shell-name)
	    (concat "cd " dir "\n"))
	   (save-excursion
	     (set-buffer tracking-shell-name)
	     (cd dir)))))
  (if tracking-shell-other-window
      (switch-to-buffer-other-window tracking-shell-name)
  (switch-to-buffer tracking-shell-name)))

;; example of using tracking shell
;; (global-set-key "\C-c\C-s" 'tracking-shell)
;;            Open tracking shell window
;; (global-set-key "\C-c\C-t" 'delete-window) ;; could use C-x 0
;;           Close tracking shell window

(provide 'multishell)
----------------------- cut here -------------------------------------


--
Jeff Dwork			|  408-987-2362   |   jeff.dwork@amd.com
Advanced Micro Devices, M/S 45	|---------------------------------------
PO Box 3453			|  The above opionions are mine,
Sunnyvale, Ca 94088		|  not AMD's.