Xref: utzoo comp.emacs:9639 gnu.emacs.help:455 gnu.emacs.sources:77 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!hp4nl!ruuinf!piet From: piet@cs.ruu.nl (Piet van Oostrum) Newsgroups: comp.emacs,gnu.emacs.help,gnu.emacs.sources Subject: Re: Automatic cd for M-x shell Message-ID: <4415@ruuinf.cs.ruu.nl> Date: 30 Nov 90 10:09:20 GMT References: <1990Nov26.210601.13376@julius.cs.uiuc.edu> Sender: news@ruuinf.cs.ruu.nl Reply-To: piet@cs.ruu.nl (Piet van Oostrum) Followup-To: comp.emacs Organization: Dept of Computer Science, Utrecht University, The Netherlands Lines: 64 In-reply-to: sane@cs.uiuc.edu (Aamod Sane) >>>>> In message <1990Nov26.210601.13376@julius.cs.uiuc.edu>, sane@cs.uiuc.edu (Aamod Sane) (AS) writes: AS> Whenever I pop up M-x shell from within a buffer, I would like AS> to cd to the current directory of the buffer. Now, when I start AS> up, only then the buffer directory is consulted. AS> But a existing shell is not sent cd to current buffer directory AS> while coming up using M-x shell. This may not be exactly what you ask for, but it is what I use: A shell-like command that creates a shell per directory where you call it. I hate cd-ing all over the place because (1) I get lost, (2) Usually I am doing unrelated things in different directories. The following mode creates a shell buffer in the directory of the current buffer, or it prompts for a directory if you give a prefix argument. If a shell already is running for this directory it pops to the existing one. The name of the shell and the directory name are remembered in the buffer name. NOTE: I use this with the cmushell mode. If you want to use it with the traditional shell mode, you will have to make some slight modifications. Use it with (autoload 'sh "sh" "Shell mode with buffer per directory" t) ---------------------------- sh.el ---------------------------------------- (require 'cmushell) (defun sh (dir) "Run an inferior shell. The shell runs in and the buffer name reflects DIRECTORY (default current working directory). Prompts for directory name if interactively called with prefix arg. The buffer is put in cmushell-mode, giving commands for sending input and controlling the subjobs of the shell. See cmushell-mode. See also variable comint-prompt-regexp. Note that many people's .cshrc files unconditionally clear the prompt. If yours does, you will probably want to change it." (interactive (list (if current-prefix-arg (read-file-name "sh in dir: " nil default-directory t)))) (setq dir (file-name-as-directory (expand-file-name (or dir default-directory)))) (let* ((prog (or explicit-shell-file-name (getenv "ESHELL") (getenv "SHELL") "/bin/sh")) (name (file-name-nondirectory prog)) (bufname (concat name "-" dir)) (startfile (concat "~/.emacs_" name)) (xargs-name (intern-soft (concat "explicit-" name "-args")))) (switch-to-buffer (get-buffer-create (concat "*" bufname "*"))) (setq default-directory dir) (apply 'make-comint bufname name (if (file-exists-p startfile) startfile) (if (and xargs-name (boundp xargs-name)) (symbol-value xargs-name) '("-i")))) (cmushell-mode)) ------------------------------------------------------------------------ -- Piet* van Oostrum, Dept of Computer Science, Utrecht University, Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands. Telephone: +31 30 531806 Uucp: uunet!mcsun!ruuinf!piet Telefax: +31 30 513791 Internet: piet@cs.ruu.nl (*`Pete')