comparison lisp/shell.el @ 2609:af46e8faaa32

(shell-prompt-pattern): Undo last change.
author Richard M. Stallman <rms@gnu.org>
date Thu, 29 Apr 1993 14:23:22 +0000
parents 2e9095b5b23d
children fe1623f77956
comparison
equal deleted inserted replaced
2608:cd5e799be39b 2609:af46e8faaa32
1 ;;; shell.el --- specialized comint.el for running the shell. 1 ;;; shell.el --- specialized comint.el for running the shell.
2 ;;; Copyright (C) 1988 Free Software Foundation, Inc. 2 ;;; Copyright (C) 1988, 1993 Free Software Foundation, Inc.
3 3
4 ;; Author: Olin Shivers <shivers@cs.cmu.edu> 4 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
5 ;; Keywords: processes 5 ;; Keywords: processes
6 6
7 ;;; This file is part of GNU Emacs. 7 ;;; This file is part of GNU Emacs.
142 ;;; Code: 142 ;;; Code:
143 143
144 (require 'comint) 144 (require 'comint)
145 145
146 ;;;###autoload 146 ;;;###autoload
147 (defconst shell-prompt-pattern "^[^#$%>;]*[#$%>;] *" 147 (defconst shell-prompt-pattern "^[^#$%>]*[#$%>] *"
148 "Regexp to match prompts in the inferior shell. 148 "Regexp to match prompts in the inferior shell.
149 Defaults to \"^[^#$%>]*[#$%>] *\", which works pretty well. 149 Defaults to \"^[^#$%>]*[#$%>] *\", which works pretty well.
150 This variable is used to initialise comint-prompt-regexp in the 150 This variable is used to initialise `comint-prompt-regexp' in the
151 shell buffer. 151 shell buffer.
152 152
153 This is a fine thing to set in your .emacs file.") 153 This is a fine thing to set in your `.emacs' file.")
154 154
155 (defvar shell-popd-regexp "popd" 155 (defvar shell-popd-regexp "popd"
156 "*Regexp to match subshell commands equivalent to popd.") 156 "*Regexp to match subshell commands equivalent to popd.")
157 157
158 (defvar shell-pushd-regexp "pushd" 158 (defvar shell-pushd-regexp "pushd"
182 182
183 (defvar shell-last-dir nil 183 (defvar shell-last-dir nil
184 "Keep track of last directory for ksh `cd -' command.") 184 "Keep track of last directory for ksh `cd -' command.")
185 185
186 (defvar shell-dirstack-query "dirs" 186 (defvar shell-dirstack-query "dirs"
187 "Command used by shell-resync-dirlist to query shell.") 187 "Command used by `shell-resync-dir' to query the shell.")
188 188
189 (defvar shell-mode-map '()) 189 (defvar shell-mode-map '())
190 (cond ((not shell-mode-map) 190 (cond ((not shell-mode-map)
191 (setq shell-mode-map (full-copy-sparse-keymap comint-mode-map)) 191 (setq shell-mode-map (full-copy-sparse-keymap comint-mode-map))
192 (define-key shell-mode-map "\t" 'comint-dynamic-complete) 192 (define-key shell-mode-map "\t" 'comint-dynamic-complete)
193 (define-key shell-mode-map "\M-?" 'comint-dynamic-list-completions))) 193 (define-key shell-mode-map "\M-?" 'comint-dynamic-list-completions)))
194 194
195 (defvar shell-mode-hook '() 195 (defvar shell-mode-hook '()
196 "*Hook for customising shell mode") 196 "*Hook for customising Shell mode.")
197 197
198 198
199 ;;; Basic Procedures 199 ;;; Basic Procedures
200 ;;; =========================================================================== 200 ;;; ===========================================================================
201 ;;; 201 ;;;
217 M-x dirs queries the shell and resyncs Emacs' idea of what the current 217 M-x dirs queries the shell and resyncs Emacs' idea of what the current
218 directory stack is. 218 directory stack is.
219 M-x dirtrack-toggle turns directory tracking on and off. 219 M-x dirtrack-toggle turns directory tracking on and off.
220 220
221 \\{shell-mode-map} 221 \\{shell-mode-map}
222 Customization: Entry to this mode runs the hooks on comint-mode-hook and 222 Customization: Entry to this mode runs the hooks on `comint-mode-hook' and
223 shell-mode-hook (in that order). 223 `shell-mode-hook' (in that order).
224 224
225 Variables shell-cd-regexp, shell-pushd-regexp and shell-popd-regexp are used 225 Variables `shell-cd-regexp', `shell-pushd-regexp' and `shell-popd-regexp'
226 to match their respective commands." 226 are used to match their respective commands."
227 (interactive) 227 (interactive)
228 (comint-mode) 228 (comint-mode)
229 (setq comint-prompt-regexp shell-prompt-pattern) 229 (setq comint-prompt-regexp shell-prompt-pattern)
230 (setq major-mode 'shell-mode) 230 (setq major-mode 'shell-mode)
231 (setq mode-name "Shell") 231 (setq mode-name "Shell")
243 (defun shell () 243 (defun shell ()
244 "Run an inferior shell, with I/O through buffer *shell*. 244 "Run an inferior shell, with I/O through buffer *shell*.
245 If buffer exists but shell process is not running, make new shell. 245 If buffer exists but shell process is not running, make new shell.
246 If buffer exists and shell process is running, 246 If buffer exists and shell process is running,
247 just switch to buffer `*shell*'. 247 just switch to buffer `*shell*'.
248 Program used comes from variable explicit-shell-file-name, 248 Program used comes from variable `explicit-shell-file-name',
249 or (if that is nil) from the ESHELL environment variable, 249 or (if that is nil) from the ESHELL environment variable,
250 or else from SHELL if there is no ESHELL. 250 or else from SHELL if there is no ESHELL.
251 If a file `~/.emacs_SHELLNAME' exists, it is given as initial input 251 If a file `~/.emacs_SHELLNAME' exists, it is given as initial input
252 (Note that this may lose due to a timing error if the shell 252 (Note that this may lose due to a timing error if the shell
253 discards input when it starts up.) 253 discards input when it starts up.)
332 default directory to track these commands. 332 default directory to track these commands.
333 333
334 You may toggle this tracking on and off with M-x dirtrack-toggle. 334 You may toggle this tracking on and off with M-x dirtrack-toggle.
335 If emacs gets confused, you can resync with the shell with M-x dirs. 335 If emacs gets confused, you can resync with the shell with M-x dirs.
336 336
337 See variables shell-cd-regexp, shell-pushd-regexp, and shell-popd-regexp. 337 See variables `shell-cd-regexp', `shell-pushd-regexp', and `shell-popd-regexp'.
338 Environment variables are expanded, see function substitute-in-file-name." 338 Environment variables are expanded, see function `substitute-in-file-name'."
339 (condition-case err 339 (condition-case err
340 (cond (shell-dirtrackp 340 (cond (shell-dirtrackp
341 (string-match "^\\s *" str) ; skip whitespace 341 (string-match "^\\s *" str) ; skip whitespace
342 (let ((bos (match-end 0)) 342 (let ((bos (match-end 0))
343 (x nil)) 343 (x nil))
458 458
459 459
460 (defun shell-resync-dirs () 460 (defun shell-resync-dirs ()
461 "Resync the buffer's idea of the current directory stack. 461 "Resync the buffer's idea of the current directory stack.
462 This command queries the shell with the command bound to 462 This command queries the shell with the command bound to
463 shell-dirstack-query (default \"dirs\"), reads the next 463 `shell-dirstack-query' (default \"dirs\"), reads the next
464 line output and parses it to form the new directory stack. 464 line output and parses it to form the new directory stack.
465 DON'T issue this command unless the buffer is at a shell prompt. 465 DON'T issue this command unless the buffer is at a shell prompt.
466 Also, note that if some other subprocess decides to do output 466 Also, note that if some other subprocess decides to do output
467 immediately after the query, its output will be taken as the 467 immediately after the query, its output will be taken as the
468 new directory stack -- you lose. If this happens, just do the 468 new directory stack -- you lose. If this happens, just do the
554 "This hook is run when shell is loaded in. 554 "This hook is run when shell is loaded in.
555 This is a good place to put keybindings.") 555 This is a good place to put keybindings.")
556 556
557 (run-hooks 'shell-load-hook) 557 (run-hooks 'shell-load-hook)
558 558
559 ;;; Change Log
560 ;;; ===========================================================================
561 ;;; Olin 8/88
562 ;;; Created.
563 ;;;
564 ;;; Olin 5/26/90
565 ;;; - Split cmulisp and cmushell modes into separate files.
566 ;;; Not only is this a good idea, it's apparently the way it'll be rel 19.
567 ;;; - Souped up the directory tracking; it now can handle pushd, pushd +n,
568 ;;; and popd +n.
569 ;;; - Added cmushell-dirtrack-toggle command to toggle the directory
570 ;;; tracking that cmushell tries to do. This is useful, for example,
571 ;;; when you are running ftp -- it prevents the ftp "cd" command from
572 ;;; spoofing the tracking machinery. This command is also named
573 ;;; dirtrack-toggle, so you need only type M-x dirtrack to run it.
574 ;;; - Added cmushell-resync-dirs command. This queries the shell
575 ;;; for the current directory stack, and resets the buffer's stack
576 ;;; accordingly. This command is also named dirs, so you need only type
577 ;;; M-x dirs to run it.
578 ;;; - Bits of the new directory tracking code were adapted from source
579 ;;; contributed by Vince Broman, Jeff Peck, and Barry Warsaw.
580 ;;; - See also the improvements made to comint.el at the same time.
581 ;;; - Renamed several variables. Mostly this comprised changing "shell"
582 ;;; to "cmushell" in the names. The only variables that are not prefixed
583 ;;; with "cmushell-" are the ones that are common with shell.el:
584 ;;; explicit-shell-file-name shell-prompt-pattern explicit-csh-args
585 ;;; and shell-cd/popd/pushd-regexp
586 ;;; The variables and functions that were changed to have "cmushell-"
587 ;;; prefixes are:
588 ;;; shell-directory-stack (v), shell-directory-tracker (f)
589 ;;; This should not affect users, only Emacs Lisp hackers. Hopefully
590 ;;; one day shell.el will just go away, and we can drop all this
591 ;;; "cmushell" bullshit.
592 ;;; - Upgraded process sends to use comint-send-string instead of
593 ;;; process-send-string.
594 ;;;
595 ;;; Olin 6/14/90
596 ;;; - If your shell is named <shellname>, and a variable named
597 ;;; explicit-<shellname>-args exists, cmushell is supposed
598 ;;; to use its value as the arglist to the shell invocation.
599 ;;; E.g., if you define explicit-csh-args to be
600 ;;; ("-ifx"), then when cmushell cranks up a csh, it execs it
601 ;;; as "csh -ifx". This is what is documented. What has actually
602 ;;; been the case is that the variable checked is
603 ;;; explicit-<shellname>-arguments, not explicit-<shellname>-args.
604 ;;; The documentation has been changed to conform to the code (for
605 ;;; backwards compatibility with shell.el). This bug is inherited from
606 ;;; the same bug in shell.el.
607 ;;; This bug reported by Stephen Anderson.
608 ;;;
609 ;;; Olin 9/5/90
610 ;;; - Arguments to cd, popd, and pushd now have their env vars expanded
611 ;;; out by the tracking machinery. So if you say "cd $SRCDIR/funs", the
612 ;;; $SRCDIR var will be replaced by its value *in emacs' process
613 ;;; environment*. If this is different from the shell's binding of the
614 ;;; variable, you lose. Several users needed this feature, fragile
615 ;;; though it may be. The fix was contributed by sk@thp.Uni-Koeln.DE.
616 ;;;
617 ;;; Olin 3/12/91
618 ;;; - Moved comint-dynamic-complete (filename completion) from M-tab to tab.
619 ;;;
620 ;;; Jim Blandy 10/30/91
621 ;;; - Removed the "cmu" prefix from names, renamed file to shell.el,
622 ;;; to become the standard shell package.
623 ;;;
624 ;;; Eric Raymond 3/23/93
625 ;;; - Merged in Brent Benson's patch to handle cd -. Made some more
626 ;;; cmushell -> shell changes.
627
628 (provide 'shell) 559 (provide 'shell)
629 560
630 ;;; shell.el ends here 561 ;;; shell.el ends here