annotate lisp/shell.el @ 2135:0634d08c28d1

(syms_of_xmenu): Set up Qmenu_enable. (single_keymap_panes): Test menu-enable property of symbol to decide whether to include it in the menu.
author Richard M. Stallman <rms@gnu.org>
date Thu, 11 Mar 1993 08:09:52 +0000
parents dd8e5024b4f9
children bb1ff4e31fb6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
925
6295ac3be480 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 844
diff changeset
1 ;;; shell.el --- specialized comint.el for running the shell.
6295ac3be480 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 844
diff changeset
2 ;;; Copyright (C) 1988 Free Software Foundation, Inc.
844
bf829a2d63b4 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
3
787
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
4 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
814
38b2499cb3e9 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
5 ;; Keywords: processes
787
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
6
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
7 ;;; This file is part of GNU Emacs.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
8
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
9 ;;; GNU Emacs is free software; you can redistribute it and/or modify
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
10 ;;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 787
diff changeset
11 ;;; the Free Software Foundation; either version 2, or (at your option)
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
12 ;;; any later version.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
13
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
14 ;;; GNU Emacs is distributed in the hope that it will be useful,
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
15 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
17 ;;; GNU General Public License for more details.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
18
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
19 ;;; You should have received a copy of the GNU General Public License
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
20 ;;; along with GNU Emacs; see the file COPYING. If not, write to
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
21 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
22
787
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
23 ;;; Commentary:
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
24
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
25 ;;; The changelog is at the end of file.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
26
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
27 ;;; Please send me bug reports, bug fixes, and extensions, so that I can
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
28 ;;; merge them into the master source.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
29 ;;; - Olin Shivers (shivers@cs.cmu.edu)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
30
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
31 ;;; This file defines a a shell-in-a-buffer package (shell mode) built
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
32 ;;; on top of comint mode. This is actually cmushell with things
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
33 ;;; renamed to replace its counterpart in Emacs 18. cmushell is more
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
34 ;;; featureful, robust, and uniform than the Emacs 18 version.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
35
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
36 ;;; Since this mode is built on top of the general command-interpreter-in-
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
37 ;;; a-buffer mode (comint mode), it shares a common base functionality,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
38 ;;; and a common set of bindings, with all modes derived from comint mode.
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
39 ;;; This makes these modes easier to use.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
40
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
41 ;;; For documentation on the functionality provided by comint mode, and
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
42 ;;; the hooks available for customising it, see the file comint.el.
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
43 ;;; For further information on shell mode, see the comments below.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
44
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
45 ;;; Needs fixin:
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
46 ;;; When sending text from a source file to a subprocess, the process-mark can
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
47 ;;; move off the window, so you can lose sight of the process interactions.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
48 ;;; Maybe I should ensure the process mark is in the window when I send
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
49 ;;; text to the process? Switch selectable?
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
50
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
51 ;; YOUR .EMACS FILE
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
52 ;;=============================================================================
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
53 ;; Some suggestions for your .emacs file.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
54 ;;
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
55 ;; ; If cmushell lives in some non-standard directory, you must tell emacs
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
56 ;; ; where to get it. This may or may not be necessary.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
57 ;; (setq load-path (cons (expand-file-name "~jones/lib/emacs") load-path))
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
58 ;;
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
59 ;; ; Autoload cmushell from file cmushell.el
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
60 ;; (autoload 'cmushell "cmushell"
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
61 ;; "Run an inferior shell process."
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
62 ;; t)
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
63 ;;
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
64 ;; ; Define C-c t to run my favorite command in cmushell mode:
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
65 ;; (setq cmushell-load-hook
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
66 ;; '((lambda ()
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
67 ;; (define-key cmushell-mode-map "\C-ct" 'favorite-cmd))))
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
68
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
69
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
70 ;;; Brief Command Documentation:
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
71 ;;;============================================================================
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
72 ;;; Comint Mode Commands: (common to shell and all comint-derived modes)
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
73 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
74 ;;; m-p comint-previous-input Cycle backwards in input history
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
75 ;;; m-n comint-next-input Cycle forwards
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
76 ;;; m-c-r comint-previous-input-matching Search backwards in input history
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
77 ;;; return comint-send-input
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
78 ;;; c-a comint-bol Beginning of line; skip prompt.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
79 ;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
80 ;;; c-c c-u comint-kill-input ^u
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
81 ;;; c-c c-w backward-kill-word ^w
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
82 ;;; c-c c-c comint-interrupt-subjob ^c
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
83 ;;; c-c c-z comint-stop-subjob ^z
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
84 ;;; c-c c-\ comint-quit-subjob ^\
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
85 ;;; c-c c-o comint-kill-output Delete last batch of process output
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
86 ;;; c-c c-r comint-show-output Show last batch of process output
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
87 ;;; send-invisible Read line w/o echo & send to proc
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
88 ;;; comint-continue-subjob Useful if you accidentally suspend
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
89 ;;; top-level job.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
90 ;;; comint-mode-hook is the comint mode hook.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
91
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
92 ;;; Shell Mode Commands:
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
93 ;;; shell Fires up the shell process.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
94 ;;; tab comint-dynamic-complete Complete a partial file name
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
95 ;;; m-? comint-dynamic-list-completions List completions in help buffer
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
96 ;;; dirs Resync the buffer's dir stack.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
97 ;;; dirtrack-toggle Turn dir tracking on/off.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
98 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
99 ;;; The shell mode hook is shell-mode-hook
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
100 ;;; The shell-load-hook is run after this file is loaded.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
101 ;;; comint-prompt-regexp is initialised to shell-prompt-pattern, for backwards
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
102 ;;; compatibility.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
103
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
104 ;;; Read the rest of this file for more information.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
105
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
106 ;;; SHELL.EL COMPATIBILITY
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
107 ;;; Notes from when this was called cmushell, and was not the standard emacs
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
108 ;;; shell package.
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
109 ;;;============================================================================
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
110 ;;; In brief: this package should have no trouble coexisting with shell.el.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
111 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
112 ;;; Most customising variables -- e.g., explicit-shell-file-name -- are the
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
113 ;;; same, so the users shouldn't have much trouble. Hooks have different
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
114 ;;; names, however, so you can customise shell mode differently from cmushell
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
115 ;;; mode. You basically just have to remember to type M-x cmushell instead of
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
116 ;;; M-x shell.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
117 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
118 ;;; It would be nice if this file was completely plug-compatible with the old
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
119 ;;; shell package -- if you could just name this file shell.el, and have it
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
120 ;;; transparently replace the old one. But you can't. Several other packages
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
121 ;;; (tex-mode, background, dbx, gdb, kermit, monkey, prolog, telnet) are also
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
122 ;;; clients of shell mode. These packages assume detailed knowledge of shell
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
123 ;;; mode internals in ways that are incompatible with cmushell mode (mostly
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
124 ;;; because of cmushell mode's greater functionality). So, unless we are
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
125 ;;; willing to port all of these packages, we can't have this file be a
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
126 ;;; complete replacement for shell.el -- that is, we can't name this file
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
127 ;;; shell.el, and its main entry point (shell), because dbx.el will break
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
128 ;;; when it loads it in and tries to use it.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
129 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
130 ;;; There are two ways to fix this. One: rewrite these other modes to use the
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
131 ;;; new package. This is a win, but can't be assumed. The other, backwards
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
132 ;;; compatible route, is to make this package non-conflict with shell.el, so
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
133 ;;; both files can be loaded in at the same time. And *that* is why some
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
134 ;;; functions and variables have different names: (cmushell),
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
135 ;;; cmushell-mode-map, that sort of thing. All the names have been carefully
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
136 ;;; chosen so that shell.el and cmushell.el won't tromp on each other.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
137
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
138 ;;; Customisation and Buffer Variables
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
139 ;;; ===========================================================================
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
140 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
141
787
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
142 ;;; Code:
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
143
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
144 (require 'comint)
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
145
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
146 ;;;###autoload
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
147 (defconst shell-prompt-pattern "^[^#$%>]*[#$%>] *"
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
148 "Regexp to match prompts in the inferior shell.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
149 Defaults to \"^[^#$%>]*[#$%>] *\", which works pretty well.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
150 This variable is used to initialise comint-prompt-regexp in the
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
151 shell buffer.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
152
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
153 This is a fine thing to set in your .emacs file.")
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
154
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
155 (defvar shell-popd-regexp "popd"
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
156 "*Regexp to match subshell commands equivalent to popd.")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
157
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
158 (defvar shell-pushd-regexp "pushd"
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
159 "*Regexp to match subshell commands equivalent to pushd.")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
160
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
161 (defvar shell-cd-regexp "cd"
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
162 "*Regexp to match subshell commands equivalent to cd.")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
163
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
164 (defvar explicit-shell-file-name nil
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
165 "*If non-nil, is file name to use for explicitly requested inferior shell.")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
166
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
167 (defvar explicit-csh-args
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
168 (if (eq system-type 'hpux)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
169 ;; -T persuades HP's csh not to think it is smarter
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
170 ;; than us about what terminal modes to use.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
171 '("-i" "-T")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
172 '("-i"))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
173 "*Args passed to inferior shell by M-x shell, if the shell is csh.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
174 Value is a list of strings, which may be nil.")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
175
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
176 ;;; All the above vars aren't prefixed "cmushell-" to make them
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
177 ;;; backwards compatible w/shell.el and old .emacs files.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
178
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
179 (defvar shell-dirstack nil
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
180 "List of directories saved by pushd in this buffer's shell.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
181 Thus, this does not include the shell's current directory.")
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
182
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
183 (defvar shell-dirstack-query "dirs"
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
184 "Command used by shell-resync-dirlist to query shell.")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
185
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
186 (defvar shell-mode-map '())
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
187 (cond ((not shell-mode-map)
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
188 (setq shell-mode-map (full-copy-sparse-keymap comint-mode-map))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
189 (define-key shell-mode-map "\t" 'comint-dynamic-complete)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
190 (define-key shell-mode-map "\M-?" 'comint-dynamic-list-completions)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
191
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
192 (defvar shell-mode-hook '()
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
193 "*Hook for customising shell mode")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
194
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
195
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
196 ;;; Basic Procedures
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
197 ;;; ===========================================================================
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
198 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
199
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
200 (defun shell-mode ()
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
201 "Major mode for interacting with an inferior shell.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
202 Return after the end of the process' output sends the text from the
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
203 end of process to the end of the current line.
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
204 Return before end of process output copies the current line (except
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
205 for the prompt) to the end of the buffer and sends it.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
206 M-x send-invisible reads a line of text without echoing it, and sends it to
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
207 the shell. This is useful for entering passwords.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
208
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
209 If you accidentally suspend your process, use \\[comint-continue-subjob]
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
210 to continue it.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
211
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
212 cd, pushd and popd commands given to the shell are watched by Emacs to keep
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
213 this buffer's default directory the same as the shell's working directory.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
214 M-x dirs queries the shell and resyncs Emacs' idea of what the current
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
215 directory stack is.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
216 M-x dirtrack-toggle turns directory tracking on and off.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
217
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
218 \\{shell-mode-map}
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
219 Customisation: Entry to this mode runs the hooks on comint-mode-hook and
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
220 shell-mode-hook (in that order).
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
221
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
222 Variables shell-cd-regexp, shell-pushd-regexp and shell-popd-regexp are used
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
223 to match their respective commands."
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
224 (interactive)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
225 (comint-mode)
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
226 (setq comint-prompt-regexp shell-prompt-pattern)
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
227 (setq major-mode 'shell-mode)
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
228 (setq mode-name "shell")
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
229 (use-local-map shell-mode-map)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
230 (make-local-variable 'shell-dirstack)
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
231 (setq shell-dirstack nil)
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
232 (make-local-variable 'shell-dirtrackp)
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
233 (setq shell-dirtrackp t)
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
234 (setq comint-input-sentinel 'shell-directory-tracker)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
235 (run-hooks 'shell-mode-hook))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
236
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
237
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
238 ;;;###autoload
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
239 (defun shell ()
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
240 "Run an inferior shell, with I/O through buffer *shell*.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
241 If buffer exists but shell process is not running, make new shell.
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
242 If buffer exists and shell process is running,
1076
8a936037cedc entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 925
diff changeset
243 just switch to buffer `*shell*'.
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
244 Program used comes from variable explicit-shell-file-name,
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
245 or (if that is nil) from the ESHELL environment variable,
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
246 or else from SHELL if there is no ESHELL.
1076
8a936037cedc entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 925
diff changeset
247 If a file `~/.emacs_SHELLNAME' exists, it is given as initial input
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
248 (Note that this may lose due to a timing error if the shell
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
249 discards input when it starts up.)
1076
8a936037cedc entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 925
diff changeset
250 The buffer is put in Shell mode, giving commands for sending input
8a936037cedc entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 925
diff changeset
251 and controlling the subjobs of the shell. See `shell-mode'.
8a936037cedc entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 925
diff changeset
252 See also the variable `shell-prompt-pattern'.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
253
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
254 The shell file name (sans directories) is used to make a symbol name
1801
dd8e5024b4f9 (shell): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 1076
diff changeset
255 such as `explicit-csh-args'. If that symbol is a variable,
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
256 its value is used as a list of arguments when invoking the shell.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
257 Otherwise, one argument `-i' is passed to the shell.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
258
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
259 \(Type \\[describe-mode] in the shell buffer for a list of commands.)"
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
260 (interactive)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
261 (cond ((not (comint-check-proc "*shell*"))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
262 (let* ((prog (or explicit-shell-file-name
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
263 (getenv "ESHELL")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
264 (getenv "SHELL")
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
265 "/bin/sh"))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
266 (name (file-name-nondirectory prog))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
267 (startfile (concat "~/.emacs_" name))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
268 (xargs-name (intern-soft (concat "explicit-" name "-args"))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
269 (set-buffer (apply 'make-comint "shell" prog
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
270 (if (file-exists-p startfile) startfile)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
271 (if (and xargs-name (boundp xargs-name))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
272 (symbol-value xargs-name)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
273 '("-i"))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
274 (shell-mode))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
275 (switch-to-buffer "*shell*"))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
276
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
277
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
278 ;;; Directory tracking
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
279 ;;; ===========================================================================
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
280 ;;; This code provides the shell mode input sentinel
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
281 ;;; SHELL-DIRECTORY-TRACKER
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
282 ;;; that tracks cd, pushd, and popd commands issued to the shell, and
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
283 ;;; changes the current directory of the shell buffer accordingly.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
284 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
285 ;;; This is basically a fragile hack, although it's more accurate than
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
286 ;;; the released version in shell.el. It has the following failings:
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
287 ;;; 1. It doesn't know about the cdpath shell variable.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
288 ;;; 2. It only spots the first command in a command sequence. E.g., it will
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
289 ;;; miss the cd in "ls; cd foo"
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
290 ;;; 3. More generally, any complex command (like ";" sequencing) is going to
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
291 ;;; throw it. Otherwise, you'd have to build an entire shell interpreter in
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
292 ;;; emacs lisp. Failing that, there's no way to catch shell commands where
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
293 ;;; cd's are buried inside conditional expressions, aliases, and so forth.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
294 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
295 ;;; The whole approach is a crock. Shell aliases mess it up. File sourcing
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
296 ;;; messes it up. You run other processes under the shell; these each have
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
297 ;;; separate working directories, and some have commands for manipulating
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
298 ;;; their w.d.'s (e.g., the lcd command in ftp). Some of these programs have
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
299 ;;; commands that do *not* affect the current w.d. at all, but look like they
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
300 ;;; do (e.g., the cd command in ftp). In shells that allow you job
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
301 ;;; control, you can switch between jobs, all having different w.d.'s. So
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
302 ;;; simply saying %3 can shift your w.d..
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
303 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
304 ;;; The solution is to relax, not stress out about it, and settle for
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
305 ;;; a hack that works pretty well in typical circumstances. Remember
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
306 ;;; that a half-assed solution is more in keeping with the spirit of Unix,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
307 ;;; anyway. Blech.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
308 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
309 ;;; One good hack not implemented here for users of programmable shells
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
310 ;;; is to program up the shell w.d. manipulation commands to output
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
311 ;;; a coded command sequence to the tty. Something like
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
312 ;;; ESC | <cwd> |
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
313 ;;; where <cwd> is the new current working directory. Then trash the
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
314 ;;; directory tracking machinery currently used in this package, and
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
315 ;;; replace it with a process filter that watches for and strips out
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
316 ;;; these messages.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
317
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
318 ;;; REGEXP is a regular expression. STR is a string. START is a fixnum.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
319 ;;; Returns T if REGEXP matches STR where the match is anchored to start
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
320 ;;; at position START in STR. Sort of like LOOKING-AT for strings.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
321 (defun shell-front-match (regexp str start)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
322 (eq start (string-match regexp str start)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
323
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
324 (defun shell-directory-tracker (str)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
325 "Tracks cd, pushd and popd commands issued to the shell.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
326 This function is called on each input passed to the shell.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
327 It watches for cd, pushd and popd commands and sets the buffer's
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
328 default directory to track these commands.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
329
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
330 You may toggle this tracking on and off with M-x dirtrack-toggle.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
331 If emacs gets confused, you can resync with the shell with M-x dirs.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
332
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
333 See variables shell-cd-regexp, shell-pushd-regexp, and shell-popd-regexp.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
334 Environment variables are expanded, see function substitute-in-file-name."
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
335 (condition-case err
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
336 (cond (shell-dirtrackp
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
337 (string-match "^\\s *" str) ; skip whitespace
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
338 (let ((bos (match-end 0))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
339 (x nil))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
340 (cond ((setq x (shell-match-cmd-w/optional-arg shell-popd-regexp
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
341 str bos))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
342 (shell-process-popd (substitute-in-file-name x)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
343 ((setq x (shell-match-cmd-w/optional-arg shell-pushd-regexp
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
344 str bos))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
345 (shell-process-pushd (substitute-in-file-name x)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
346 ((setq x (shell-match-cmd-w/optional-arg shell-cd-regexp
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
347 str bos))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
348 (shell-process-cd (substitute-in-file-name x)))))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
349 (error (message (car (cdr err))))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
350
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
351
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
352 ;;; Try to match regexp CMD to string, anchored at position START.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
353 ;;; CMD may be followed by a single argument. If a match, then return
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
354 ;;; the argument, if there is one, or the empty string if not. If
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
355 ;;; no match, return nil.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
356
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
357 (defun shell-match-cmd-w/optional-arg (cmd str start)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
358 (and (shell-front-match cmd str start)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
359 (let ((eoc (match-end 0))) ; end of command
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
360 (cond ((shell-front-match "\\s *\\(\;\\|$\\)" str eoc)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
361 "") ; no arg
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
362 ((shell-front-match "\\s +\\([^ \t\;]+\\)\\s *\\(\;\\|$\\)"
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
363 str eoc)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
364 (substring str (match-beginning 1) (match-end 1))) ; arg
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
365 (t nil))))) ; something else.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
366 ;;; The first regexp is [optional whitespace, (";" or the end of string)].
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
367 ;;; The second regexp is [whitespace, (an arg), optional whitespace,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
368 ;;; (";" or end of string)].
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
369
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
370
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
371 ;;; popd [+n]
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
372 (defun shell-process-popd (arg)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
373 (let ((num (if (zerop (length arg)) 0 ; no arg means +0
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
374 (shell-extract-num arg))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
375 (if (and num (< num (length shell-dirstack)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
376 (if (= num 0) ; condition-case because the CD could lose.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
377 (condition-case nil (progn (cd (car shell-dirstack))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
378 (setq shell-dirstack
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
379 (cdr shell-dirstack))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
380 (shell-dirstack-message))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
381 (error (message "Couldn't cd.")))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
382 (let* ((ds (cons nil shell-dirstack))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
383 (cell (nthcdr (- num 1) ds)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
384 (rplacd cell (cdr (cdr cell)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
385 (setq shell-dirstack (cdr ds))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
386 (shell-dirstack-message)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
387 (message "Bad popd."))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
388
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
389
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
390 ;;; cd [dir]
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
391 (defun shell-process-cd (arg)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
392 (condition-case nil (progn (cd (if (zerop (length arg)) (getenv "HOME")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
393 arg))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
394 (shell-dirstack-message))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
395 (error (message "Couldn't cd."))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
396
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
397
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
398 ;;; pushd [+n | dir]
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
399 (defun shell-process-pushd (arg)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
400 (if (zerop (length arg))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
401 ;; no arg -- swap pwd and car of shell stack
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
402 (condition-case nil (if shell-dirstack
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
403 (let ((old default-directory))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
404 (cd (car shell-dirstack))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
405 (setq shell-dirstack
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
406 (cons old (cdr shell-dirstack)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
407 (shell-dirstack-message))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
408 (message "Directory stack empty."))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
409 (message "Couldn't cd."))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
410
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
411 (let ((num (shell-extract-num arg)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
412 (if num ; pushd +n
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
413 (if (> num (length shell-dirstack))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
414 (message "Directory stack not that deep.")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
415 (let* ((ds (cons default-directory shell-dirstack))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
416 (dslen (length ds))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
417 (front (nthcdr num ds))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
418 (back (reverse (nthcdr (- dslen num) (reverse ds))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
419 (new-ds (append front back)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
420 (condition-case nil
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
421 (progn (cd (car new-ds))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
422 (setq shell-dirstack (cdr new-ds))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
423 (shell-dirstack-message))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
424 (error (message "Couldn't cd.")))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
425
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
426 ;; pushd <dir>
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
427 (let ((old-wd default-directory))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
428 (condition-case nil
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
429 (progn (cd arg)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
430 (setq shell-dirstack
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
431 (cons old-wd shell-dirstack))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
432 (shell-dirstack-message))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
433 (error (message "Couldn't cd."))))))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
434
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
435 ;; If STR is of the form +n, for n>0, return n. Otherwise, nil.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
436 (defun shell-extract-num (str)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
437 (and (string-match "^\\+[1-9][0-9]*$" str)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
438 (string-to-int str)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
439
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
440
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
441 (defun shell-dirtrack-toggle ()
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
442 "Turn directory tracking on and off in a shell buffer."
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
443 (interactive)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
444 (setq shell-dirtrackp (not shell-dirtrackp))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
445 (message "directory tracking %s."
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
446 (if shell-dirtrackp "ON" "OFF")))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
447
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
448 ;;; For your typing convenience:
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
449 (fset 'dirtrack-toggle 'shell-dirtrack-toggle)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
450
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
451
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
452 (defun shell-resync-dirs ()
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
453 "Resync the buffer's idea of the current directory stack.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
454 This command queries the shell with the command bound to
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
455 shell-dirstack-query (default \"dirs\"), reads the next
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
456 line output and parses it to form the new directory stack.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
457 DON'T issue this command unless the buffer is at a shell prompt.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
458 Also, note that if some other subprocess decides to do output
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
459 immediately after the query, its output will be taken as the
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
460 new directory stack -- you lose. If this happens, just do the
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
461 command again."
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
462 (interactive)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
463 (let* ((proc (get-buffer-process (current-buffer)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
464 (pmark (process-mark proc)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
465 (goto-char pmark)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
466 (insert shell-dirstack-query) (insert "\n")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
467 (sit-for 0) ; force redisplay
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
468 (comint-send-string proc shell-dirstack-query)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
469 (comint-send-string proc "\n")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
470 (set-marker pmark (point))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
471 (let ((pt (point))) ; wait for 1 line
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
472 ;; This extra newline prevents the user's pending input from spoofing us.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
473 (insert "\n") (backward-char 1)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
474 (while (not (looking-at ".+\n"))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
475 (accept-process-output proc)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
476 (goto-char pt)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
477 (goto-char pmark) (delete-char 1) ; remove the extra newline
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
478 ;; That's the dirlist. grab it & parse it.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
479 (let* ((dl (buffer-substring (match-beginning 0) (- (match-end 0) 1)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
480 (dl-len (length dl))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
481 (ds '()) ; new dir stack
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
482 (i 0))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
483 (while (< i dl-len)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
484 ;; regexp = optional whitespace, (non-whitespace), optional whitespace
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
485 (string-match "\\s *\\(\\S +\\)\\s *" dl i) ; pick off next dir
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
486 (setq ds (cons (substring dl (match-beginning 1) (match-end 1))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
487 ds))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
488 (setq i (match-end 0)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
489 (let ((ds (reverse ds)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
490 (condition-case nil
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
491 (progn (cd (car ds))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
492 (setq shell-dirstack (cdr ds))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
493 (shell-dirstack-message))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
494 (error (message "Couldn't cd.")))))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
495
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
496 ;;; For your typing convenience:
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
497 (fset 'dirs 'shell-resync-dirs)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
498
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
499
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
500 ;;; Show the current dirstack on the message line.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
501 ;;; Pretty up dirs a bit by changing "/usr/jqr/foo" to "~/foo".
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
502 ;;; (This isn't necessary if the dirlisting is generated with a simple "dirs".)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
503 ;;; All the commands that mung the buffer's dirstack finish by calling
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
504 ;;; this guy.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
505 (defun shell-dirstack-message ()
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
506 (let ((msg "")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
507 (ds (cons default-directory shell-dirstack)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
508 (while ds
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
509 (let ((dir (car ds)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
510 (if (string-match (format "^%s\\(/\\|$\\)" (getenv "HOME")) dir)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
511 (setq dir (concat "~/" (substring dir (match-end 0)))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
512 (if (string-equal dir "~/") (setq dir "~"))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
513 (setq msg (concat msg dir " "))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
514 (setq ds (cdr ds))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
515 (message msg)))
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
516
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
517
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
518
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
519 ;;; Interfacing to client packages (and converting them)
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
520 ;;; Notes from when this was called cmushell, and was not the standard emacs
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
521 ;;; shell package. Many of the conversions discussed here have been done.
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
522 ;;;============================================================================
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
523 ;;; Several gnu packages (tex-mode, background, dbx, gdb, kermit, prolog,
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
524 ;;; telnet are some) use the shell package as clients. Most of them would
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
525 ;;; be better off using the comint package directly, but they predate it.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
526 ;;; The catch is that most of these packages (dbx, gdb, prolog, telnet)
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
527 ;;; assume total knowledge of all the local variables that shell mode
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
528 ;;; functions depend on. So they (kill-all-local-variables), then create
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
529 ;;; the few local variables that shell.el functions depend on. Alas,
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
530 ;;; cmushell.el functions depend on a different set of vars (for example,
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
531 ;;; the input history ring is a local variable in cmushell.el's shell mode,
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
532 ;;; whereas there is no input history ring in shell.el's shell mode).
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
533 ;;; So we have a situation where the greater functionality of cmushell.el
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
534 ;;; is biting us -- you can't just replace shell will cmushell.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
535 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
536 ;;; Altering these packages to use comint mode directly should *greatly*
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
537 ;;; improve their functionality, and is actually pretty easy. It's
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
538 ;;; mostly a matter of renaming a few variable names. See comint.el for more.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
539 ;;; -Olin
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
540
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
541
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
542
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
543 ;;; Do the user's customisation...
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
544 ;;;===============================
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
545 (defvar shell-load-hook nil
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
546 "This hook is run when shell is loaded in.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
547 This is a good place to put keybindings.")
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
548
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
549 (run-hooks 'shell-load-hook)
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
550
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
551 ;;; Change Log
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
552 ;;; ===========================================================================
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
553 ;;; Olin 8/88
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
554 ;;; Created.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
555 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
556 ;;; Olin 5/26/90
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
557 ;;; - Split cmulisp and cmushell modes into separate files.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
558 ;;; Not only is this a good idea, it's apparently the way it'll be rel 19.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
559 ;;; - Souped up the directory tracking; it now can handle pushd, pushd +n,
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
560 ;;; and popd +n.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
561 ;;; - Added cmushell-dirtrack-toggle command to toggle the directory
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
562 ;;; tracking that cmushell tries to do. This is useful, for example,
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
563 ;;; when you are running ftp -- it prevents the ftp "cd" command from
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
564 ;;; spoofing the tracking machinery. This command is also named
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
565 ;;; dirtrack-toggle, so you need only type M-x dirtrack to run it.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
566 ;;; - Added cmushell-resync-dirs command. This queries the shell
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
567 ;;; for the current directory stack, and resets the buffer's stack
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
568 ;;; accordingly. This command is also named dirs, so you need only type
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
569 ;;; M-x dirs to run it.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
570 ;;; - Bits of the new directory tracking code were adapted from source
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
571 ;;; contributed by Vince Broman, Jeff Peck, and Barry Warsaw.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
572 ;;; - See also the improvements made to comint.el at the same time.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
573 ;;; - Renamed several variables. Mostly this comprised changing "shell"
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
574 ;;; to "cmushell" in the names. The only variables that are not prefixed
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
575 ;;; with "cmushell-" are the ones that are common with shell.el:
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
576 ;;; explicit-shell-file-name shell-prompt-pattern explicit-csh-args
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
577 ;;; and shell-cd/popd/pushd-regexp
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
578 ;;; The variables and functions that were changed to have "cmushell-"
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
579 ;;; prefixes are:
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
580 ;;; shell-directory-stack (v), shell-directory-tracker (f)
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 787
diff changeset
581 ;;; This should not affect users, only Emacs Lisp hackers. Hopefully
252
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
582 ;;; one day shell.el will just go away, and we can drop all this
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
583 ;;; "cmushell" bullshit.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
584 ;;; - Upgraded process sends to use comint-send-string instead of
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
585 ;;; process-send-string.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
586 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
587 ;;; Olin 6/14/90
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
588 ;;; - If your shell is named <shellname>, and a variable named
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
589 ;;; explicit-<shellname>-args exists, cmushell is supposed
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
590 ;;; to use its value as the arglist to the shell invocation.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
591 ;;; E.g., if you define explicit-csh-args to be
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
592 ;;; ("-ifx"), then when cmushell cranks up a csh, it execs it
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
593 ;;; as "csh -ifx". This is what is documented. What has actually
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
594 ;;; been the case is that the variable checked is
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
595 ;;; explicit-<shellname>-arguments, not explicit-<shellname>-args.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
596 ;;; The documentation has been changed to conform to the code (for
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
597 ;;; backwards compatibility with shell.el). This bug is inherited from
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
598 ;;; the same bug in shell.el.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
599 ;;; This bug reported by Stephen Anderson.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
600 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
601 ;;; Olin 9/5/90
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
602 ;;; - Arguments to cd, popd, and pushd now have their env vars expanded
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
603 ;;; out by the tracking machinery. So if you say "cd $SRCDIR/funs", the
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
604 ;;; $SRCDIR var will be replaced by its value *in emacs' process
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
605 ;;; environment*. If this is different from the shell's binding of the
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
606 ;;; variable, you lose. Several users needed this feature, fragile
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
607 ;;; though it may be. The fix was contributed by sk@thp.Uni-Koeln.DE.
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
608 ;;;
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
609 ;;; Olin 3/12/91
1ef0a9b58e63 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
610 ;;; - Moved comint-dynamic-complete (filename completion) from M-tab to tab.
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
611 ;;;
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
612 ;;; Jim Blandy 10/30/91
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
613 ;;; - Removed the "cmu" prefix from names, renamed file to shell.el,
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
614 ;;; to become the standard shell package.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
615
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
616 (provide 'shell)
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
617
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 252
diff changeset
618 ;;; shell.el ends here