(mpuz-try-letter): Use read-char to read digit.
[bpt/emacs.git] / lisp / shell.el
index 0473d36..88e62c6 100644 (file)
@@ -1,12 +1,14 @@
-;;; shell.el --- general command interpreter in a window stuff
+;;; shell.el --- specialized comint.el for running the shell.
+;;; Copyright (C) 1988 Free Software Foundation, Inc.
 
-;;; Copyright Olin Shivers (1988).
+;; Author: Olin Shivers <shivers@cs.cmu.edu>
+;; Keywords: processes
 
 ;;; This file is part of GNU Emacs.
 
 ;;; GNU Emacs is free software; you can redistribute it and/or modify
 ;;; it under the terms of the GNU General Public License as published by
-;;; the Free Software Foundation; either version 1, or (at your option)
+;;; the Free Software Foundation; either version 2, or (at your option)
 ;;; any later version.
 
 ;;; GNU Emacs is distributed in the hope that it will be useful,
@@ -18,6 +20,8 @@
 ;;; along with GNU Emacs; see the file COPYING.  If not, write to
 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
+;;; Commentary:
+
 ;;; The changelog is at the end of file.
 
 ;;; Please send me bug reports, bug fixes, and extensions, so that I can
 ;;; Maybe I should ensure the process mark is in the window when I send
 ;;; text to the process? Switch selectable?
 
-(require 'comint)
 ;; YOUR .EMACS FILE
 ;;=============================================================================
 ;; Some suggestions for your .emacs file.
 ;;
-;; ; If cmushell lives in some non-standard directory, you must tell emacs
+;; ; If shell lives in some non-standard directory, you must tell emacs
 ;; ; where to get it. This may or may not be necessary.
 ;; (setq load-path (cons (expand-file-name "~jones/lib/emacs") load-path))
 ;;
-;; ; Autoload cmushell from file cmushell.el
-;; (autoload 'cmushell "cmushell"
+;; ; Autoload shell from file shell.el
+;; (autoload 'shell "shell"
 ;;           "Run an inferior shell process."
 ;;           t)
 ;;
-;; ; Define C-c t to run my favorite command in cmushell mode:
-;; (setq cmushell-load-hook
+;; ; Define C-c t to run my favorite command in shell mode:
+;; (setq shell-load-hook
 ;;       '((lambda () 
-;;           (define-key cmushell-mode-map "\C-ct" 'favorite-cmd))))
+;;           (define-key shell-mode-map "\C-ct" 'favorite-cmd))))
 
 \f
 ;;; Brief Command Documentation:
 ;;; ===========================================================================
 ;;; 
 
+;;; Code:
+
+(require 'comint)
+
 ;;;###autoload
 (defconst shell-prompt-pattern "^[^#$%>]*[#$%>] *"
   "Regexp to match prompts in the inferior shell.
@@ -173,6 +180,9 @@ Value is a list of strings, which may be nil.")
   "List of directories saved by pushd in this buffer's shell.
 Thus, this does not include the shell's current directory.")
 
+(defvar shell-last-dir nil
+  "Keep track of last directory for ksh `cd -' command.")
+
 (defvar shell-dirstack-query "dirs"
   "Command used by shell-resync-dirlist to query shell.")
 
@@ -222,6 +232,7 @@ to match their respective commands."
   (use-local-map shell-mode-map)
   (make-local-variable 'shell-dirstack)
   (setq shell-dirstack nil)
+  (setq shell-last-dir nil)
   (make-local-variable 'shell-dirtrackp)
   (setq shell-dirtrackp t)
   (setq comint-input-sentinel 'shell-directory-tracker)
@@ -233,19 +244,19 @@ to match their respective commands."
   "Run an inferior shell, with I/O through buffer *shell*.
 If buffer exists but shell process is not running, make new shell.
 If buffer exists and shell process is running, 
- just switch to buffer *shell*.
+ just switch to buffer `*shell*'.
 Program used comes from variable explicit-shell-file-name,
  or (if that is nil) from the ESHELL environment variable,
  or else from SHELL if there is no ESHELL.
-If a file ~/.emacs_SHELLNAME exists, it is given as initial input
+If a file `~/.emacs_SHELLNAME' exists, it is given as initial input
  (Note that this may lose due to a timing error if the shell
   discards input when it starts up.)
-The buffer is put in shell-mode, giving commands for sending input
-and controlling the subjobs of the shell.  See shell-mode.
-See also variable shell-prompt-pattern.
+The buffer is put in Shell mode, giving commands for sending input
+and controlling the subjobs of the shell.  See `shell-mode'.
+See also the variable `shell-prompt-pattern'.
 
 The shell file name (sans directories) is used to make a symbol name
-such as `explicit-csh-arguments'.  If that symbol is a variable,
+such as `explicit-csh-args'.  If that symbol is a variable,
 its value is used as a list of arguments when invoking the shell.
 Otherwise, one argument `-i' is passed to the shell.
 
@@ -382,11 +393,15 @@ Environment variables are expanded, see function substitute-in-file-name."
 
 ;;; cd [dir]
 (defun shell-process-cd (arg)
-  (condition-case nil (progn (cd (if (zerop (length arg)) (getenv "HOME")
-                                    arg))
-                            (shell-dirstack-message))
-          (error (message "Couldn't cd."))))
-
+  (condition-case nil 
+      (let ((new-dir (cond
+                      ((zerop (length arg)) (getenv "HOME"))
+                      ((string-equal "-" arg) shell-last-dir)
+                      (t arg))))
+       (setq shell-last-dir default-directory)
+       (cd new-dir)
+       (shell-dirstack-message))
+    (error (message "Couldn't cd."))))
 
 ;;; pushd [+n | dir]
 (defun shell-process-pushd (arg)
@@ -571,7 +586,7 @@ This is a good place to put keybindings.")
 ;;;   The variables and functions that were changed to have "cmushell-" 
 ;;;   prefixes are:
 ;;;       shell-directory-stack (v), shell-directory-tracker (f)
-;;;   This should not affect users, only elisp hackers. Hopefully
+;;;   This should not affect users, only Emacs Lisp hackers. Hopefully
 ;;;   one day shell.el will just go away, and we can drop all this
 ;;;   "cmushell" bullshit.
 ;;; - Upgraded process sends to use comint-send-string instead of
@@ -605,6 +620,10 @@ This is a good place to put keybindings.")
 ;;; Jim Blandy 10/30/91
 ;;; - Removed the "cmu" prefix from names, renamed file to shell.el,
 ;;;   to become the standard shell package.
+;;;
+;;; Eric Raymond 3/23/93
+;;; - Merged in Brent Benson's patch to handle cd -.  Made some more
+;;;   cmushell -> shell changes.
 
 (provide 'shell)