-;;; shell.el --- general command interpreter in a window stuff
+;;; shell.el --- specialized comint.el for running the shell.
+;;; Copyright (C) 1988, 1993 Free Software Foundation, Inc.
;; Author: Olin Shivers <shivers@cs.cmu.edu>
-;; Last-Modified: 16 Mar 1992
-
-;;; Copyright Olin Shivers (1988).
+;; Keywords: processes
;;; This file is part of GNU Emacs.
;;=============================================================================
;; 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:
;;; cmushell-mode-map, that sort of thing. All the names have been carefully
;;; chosen so that shell.el and cmushell.el won't tromp on each other.
\f
-;;; Customisation and Buffer Variables
+;;; Customization and Buffer Variables
;;; ===========================================================================
;;;
(require 'comint)
;;;###autoload
-(defconst shell-prompt-pattern "^[^#$%>]*[#$%>] *"
+(defvar shell-prompt-pattern "^[^#$%>]*[#$%>] *"
"Regexp to match prompts in the inferior shell.
Defaults to \"^[^#$%>]*[#$%>] *\", which works pretty well.
-This variable is used to initialise comint-prompt-regexp in the
+This variable is used to initialise `comint-prompt-regexp' in the
shell buffer.
-This is a fine thing to set in your .emacs file.")
+This is a fine thing to set in your `.emacs' file.")
(defvar shell-popd-regexp "popd"
"*Regexp to match subshell commands equivalent to popd.")
"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.")
+ "Command used by `shell-resync-dir' to query the shell.")
(defvar shell-mode-map '())
(cond ((not shell-mode-map)
(define-key shell-mode-map "\M-?" 'comint-dynamic-list-completions)))
(defvar shell-mode-hook '()
- "*Hook for customising shell mode")
+ "*Hook for customising Shell mode.")
\f
;;; Basic Procedures
M-x dirtrack-toggle turns directory tracking on and off.
\\{shell-mode-map}
-Customisation: Entry to this mode runs the hooks on comint-mode-hook and
-shell-mode-hook (in that order).
+Customization: Entry to this mode runs the hooks on `comint-mode-hook' and
+`shell-mode-hook' (in that order).
-Variables shell-cd-regexp, shell-pushd-regexp and shell-popd-regexp are used
-to match their respective commands."
+Variables `shell-cd-regexp', `shell-pushd-regexp' and `shell-popd-regexp'
+are used to match their respective commands."
(interactive)
(comint-mode)
(setq comint-prompt-regexp shell-prompt-pattern)
(setq major-mode 'shell-mode)
- (setq mode-name "shell")
+ (setq mode-name "Shell")
(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)
"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*.
-Program used comes from variable explicit-shell-file-name,
+ 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.
;;; changes the current directory of the shell buffer accordingly.
;;;
;;; This is basically a fragile hack, although it's more accurate than
-;;; the released version in shell.el. It has the following failings:
+;;; the version in Emacs 18's shell.el. It has the following failings:
;;; 1. It doesn't know about the cdpath shell variable.
;;; 2. It only spots the first command in a command sequence. E.g., it will
;;; miss the cd in "ls; cd foo"
You may toggle this tracking on and off with M-x dirtrack-toggle.
If emacs gets confused, you can resync with the shell with M-x dirs.
-See variables shell-cd-regexp, shell-pushd-regexp, and shell-popd-regexp.
-Environment variables are expanded, see function substitute-in-file-name."
+See variables `shell-cd-regexp', `shell-pushd-regexp', and `shell-popd-regexp'.
+Environment variables are expanded, see function `substitute-in-file-name'."
(condition-case err
(cond (shell-dirtrackp
(string-match "^\\s *" str) ; skip whitespace
;;; 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)
(if shell-dirtrackp "ON" "OFF")))
;;; For your typing convenience:
-(fset 'dirtrack-toggle 'shell-dirtrack-toggle)
+(defalias 'dirtrack-toggle 'shell-dirtrack-toggle)
(defun shell-resync-dirs ()
"Resync the buffer's idea of the current directory stack.
This command queries the shell with the command bound to
-shell-dirstack-query (default \"dirs\"), reads the next
+`shell-dirstack-query' (default \"dirs\"), reads the next
line output and parses it to form the new directory stack.
DON'T issue this command unless the buffer is at a shell prompt.
Also, note that if some other subprocess decides to do output
(error (message "Couldn't cd.")))))))
;;; For your typing convenience:
-(fset 'dirs 'shell-resync-dirs)
+(defalias 'dirs 'shell-resync-dirs)
;;; Show the current dirstack on the message line.
-;;; Do the user's customisation...
+;;; Do the user's customization...
;;;===============================
(defvar shell-load-hook nil
"This hook is run when shell is loaded in.
(run-hooks 'shell-load-hook)
-;;; Change Log
-;;; ===========================================================================
-;;; Olin 8/88
-;;; Created.
-;;;
-;;; Olin 5/26/90
-;;; - Split cmulisp and cmushell modes into separate files.
-;;; Not only is this a good idea, it's apparently the way it'll be rel 19.
-;;; - Souped up the directory tracking; it now can handle pushd, pushd +n,
-;;; and popd +n.
-;;; - Added cmushell-dirtrack-toggle command to toggle the directory
-;;; tracking that cmushell tries to do. This is useful, for example,
-;;; when you are running ftp -- it prevents the ftp "cd" command from
-;;; spoofing the tracking machinery. This command is also named
-;;; dirtrack-toggle, so you need only type M-x dirtrack to run it.
-;;; - Added cmushell-resync-dirs command. This queries the shell
-;;; for the current directory stack, and resets the buffer's stack
-;;; accordingly. This command is also named dirs, so you need only type
-;;; M-x dirs to run it.
-;;; - Bits of the new directory tracking code were adapted from source
-;;; contributed by Vince Broman, Jeff Peck, and Barry Warsaw.
-;;; - See also the improvements made to comint.el at the same time.
-;;; - Renamed several variables. Mostly this comprised changing "shell"
-;;; to "cmushell" in the names. The only variables that are not prefixed
-;;; with "cmushell-" are the ones that are common with shell.el:
-;;; explicit-shell-file-name shell-prompt-pattern explicit-csh-args
-;;; and shell-cd/popd/pushd-regexp
-;;; 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 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
-;;; process-send-string.
-;;;
-;;; Olin 6/14/90
-;;; - If your shell is named <shellname>, and a variable named
-;;; explicit-<shellname>-args exists, cmushell is supposed
-;;; to use its value as the arglist to the shell invocation.
-;;; E.g., if you define explicit-csh-args to be
-;;; ("-ifx"), then when cmushell cranks up a csh, it execs it
-;;; as "csh -ifx". This is what is documented. What has actually
-;;; been the case is that the variable checked is
-;;; explicit-<shellname>-arguments, not explicit-<shellname>-args.
-;;; The documentation has been changed to conform to the code (for
-;;; backwards compatibility with shell.el). This bug is inherited from
-;;; the same bug in shell.el.
-;;; This bug reported by Stephen Anderson.
-;;;
-;;; Olin 9/5/90
-;;; - Arguments to cd, popd, and pushd now have their env vars expanded
-;;; out by the tracking machinery. So if you say "cd $SRCDIR/funs", the
-;;; $SRCDIR var will be replaced by its value *in emacs' process
-;;; environment*. If this is different from the shell's binding of the
-;;; variable, you lose. Several users needed this feature, fragile
-;;; though it may be. The fix was contributed by sk@thp.Uni-Koeln.DE.
-;;;
-;;; Olin 3/12/91
-;;; - Moved comint-dynamic-complete (filename completion) from M-tab to tab.
-;;;
-;;; Jim Blandy 10/30/91
-;;; - Removed the "cmu" prefix from names, renamed file to shell.el,
-;;; to become the standard shell package.
-
(provide 'shell)
;;; shell.el ends here