annotate lisp/comint/shell.el @ 163:0132846995bd r20-3b8

Import from CVS: tag r20-3b8
author cvs
date Mon, 13 Aug 2007 09:43:35 +0200
parents 43dd3413c7c7
children 15872534500d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; shell.el --- specialized comint.el for running the shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1988, 1993, 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Maintainer: Simon Marshall <simon@gnu.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: processes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
24 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Please send me bug reports, bug fixes, and extensions, so that I can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; merge them into the master source.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; - Olin Shivers (shivers@cs.cmu.edu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; - Simon Marshall (simon@gnu.ai.mit.edu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; This file defines a a shell-in-a-buffer package (shell mode) built
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; on top of comint mode. This is actually cmushell with things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; renamed to replace its counterpart in Emacs 18. cmushell is more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; featureful, robust, and uniform than the Emacs 18 version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; Since this mode is built on top of the general command-interpreter-in-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; a-buffer mode (comint mode), it shares a common base functionality,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; and a common set of bindings, with all modes derived from comint mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; This makes these modes easier to use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; For documentation on the functionality provided by comint mode, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; the hooks available for customising it, see the file comint.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; For further information on shell mode, see the comments below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; Needs fixin:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; When sending text from a source file to a subprocess, the process-mark can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; move off the window, so you can lose sight of the process interactions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; Maybe I should ensure the process mark is in the window when I send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; text to the process? Switch selectable?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; YOUR .EMACS FILE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;=============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; Some suggestions for your .emacs file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; ;; Define M-# to run some strange command:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; (eval-after-load "shell"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; '(define-key shell-mode-map "\M-#" 'shells-dynamic-spell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; Brief Command Documentation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; Comint Mode Commands: (common to shell and all comint-derived modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; m-p comint-previous-input Cycle backwards in input history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; m-n comint-next-input Cycle forwards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; m-r comint-previous-matching-input Previous input matching a regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; m-s comint-next-matching-input Next input that matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; m-c-l comint-show-output Show last batch of process output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; return comint-send-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; c-c c-a comint-bol Beginning of line; skip prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; c-c c-u comint-kill-input ^u
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;; c-c c-w backward-kill-word ^w
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;; c-c c-c comint-interrupt-subjob ^c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; c-c c-z comint-stop-subjob ^z
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; c-c c-\ comint-quit-subjob ^\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;; c-c c-o comint-kill-output Delete last batch of process output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; c-c c-r comint-show-output Show last batch of process output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;; c-c c-h comint-dynamic-list-input-ring List input history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; send-invisible Read line w/o echo & send to proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; comint-continue-subjob Useful if you accidentally suspend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; top-level job
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;; comint-mode-hook is the comint mode hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;; Shell Mode Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;; shell Fires up the shell process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;; tab comint-dynamic-complete Complete filename/command/history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;; m-? comint-dynamic-list-filename-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;; List completions in help buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;; m-c-f shell-forward-command Forward a shell command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;; m-c-b shell-backward-command Backward a shell command
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 134
diff changeset
95 ;;; shell-resync-dirs Resync the buffer's dir stack
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;; dirtrack-toggle Turn dir tracking on/off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;; comint-strip-ctrl-m Remove trailing ^Ms from output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;;; The shell mode hook is shell-mode-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;; comint-prompt-regexp is initialised to shell-prompt-pattern, for backwards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;; compatibility.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;; Read the rest of this file for more information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;; Customization and Buffer Variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (require 'comint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
113 (defgroup shell nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
114 "Running shell from within Emacs buffers"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
115 :group 'processes
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
116 :group 'unix)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
117
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
118 (defgroup shell-directories nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
119 "Directory support in shell mode"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
120 :group 'shell)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
121
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
122 (defgroup shell-faces nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
123 "Faces in shell buffers"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
124 :group 'shell)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
125
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defvar shell-prompt-pattern (purecopy "^[^#$%>\n]*[#$%>] *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "Regexp to match prompts in the inferior shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Defaults to \"^[^#$%>\\n]*[#$%>] *\", which works pretty well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 This variable is used to initialise `comint-prompt-regexp' in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 shell buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 The pattern should probably not match more than one line. If it does,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 shell-mode may become confused trying to distinguish prompt from input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 on lines which don't start with a prompt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 This is a fine thing to set in your `.emacs' file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
139 (defcustom shell-completion-fignore nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "*List of suffixes to be disregarded during file/command completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 This variable is used to initialize `comint-completion-fignore' in the shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 buffer. The default is nil, for compatibility with most shells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 Some people like (\"~\" \"#\" \"%\").
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
145 This is a fine thing to set in your `.emacs' file."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
146 :type '(repeat (string :tag "Suffix"))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
147 :group 'shell)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;jwz: turned this off; it's way too broken.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defvar shell-delimiter-argument-list nil ;'(?\| ?& ?< ?> ?\( ?\) ?\;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 "List of characters to recognise as separate arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 This variable is used to initialize `comint-delimiter-argument-list' in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 shell buffer. The default is (?\\| ?& ?< ?> ?\\( ?\\) ?\\;).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 This is a fine thing to set in your `.emacs' file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (defvar shell-file-name-quote-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (append shell-delimiter-argument-list '(?\ ?\* ?\! ?\" ?\' ?\`))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 "List of characters to quote when in a file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 This variable is used to initialize `comint-file-name-quote-list' in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 shell buffer. The default is (?\ ?\* ?\! ?\" ?\' ?\`) plus characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 in `shell-delimiter-argument-list'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 This is a fine thing to set in your `.emacs' file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (defvar shell-dynamic-complete-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 '(comint-replace-by-expanded-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 shell-dynamic-complete-environment-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 shell-dynamic-complete-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 shell-replace-by-expanded-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 comint-dynamic-complete-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "List of functions called to perform completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 This variable is used to initialise `comint-dynamic-complete-functions' in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 shell buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 This is a fine thing to set in your `.emacs' file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
178 (defcustom shell-command-regexp "[^;&|\n]+"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "*Regexp to match a single command within a pipeline.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
180 This is used for directory tracking and does not do a perfect job."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
181 :type 'regexp
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
182 :group 'shell)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
184 (defcustom shell-completion-execonly t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 "*If non-nil, use executable files only for completion candidates.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 This mirrors the optional behavior of tcsh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
188 Detecting executability of files may slow command completion considerably."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
189 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
190 :group 'shell)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
192 (defcustom shell-multiple-shells nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
193 "*If non-nil, each time shell mode is invoked, a new shell is made"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
194 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
195 :group 'shell)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
197 (defcustom shell-popd-regexp "popd"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
198 "*Regexp to match subshell commands equivalent to popd."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
199 :type 'regexp
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
200 :group 'shell-directories)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
202 (defcustom shell-pushd-regexp "pushd"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
203 "*Regexp to match subshell commands equivalent to pushd."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
204 :type 'regexp
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
205 :group 'shell-directories)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
207 (defcustom shell-pushd-tohome nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
208 "*If non-nil, make pushd with no arg behave as \"pushd ~\" (like cd).
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
209 This mirrors the optional behavior of tcsh."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
210 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
211 :group 'shell-directories)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
213 (defcustom shell-pushd-dextract nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
214 "*If non-nil, make \"pushd +n\" pop the nth dir to the stack top.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
215 This mirrors the optional behavior of tcsh."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
216 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
217 :group 'shell-directories)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
219 (defcustom shell-pushd-dunique nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
220 "*If non-nil, make pushd only add unique directories to the stack.
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
221 This mirrors the optional behavior of tcsh."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
222 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
223 :group 'shell-directories)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
225 (defcustom shell-cd-regexp "cd"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
226 "*Regexp to match subshell commands equivalent to cd."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
227 :type 'regexp
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
228 :group 'shell-directories)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
230 (defcustom explicit-shell-file-name nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
231 "*If non-nil, is file name to use for explicitly requested inferior shell."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
232 :type '(choice (const :tag "None" nil) file)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
233 :group 'shell)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
234
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
235 (defcustom explicit-csh-args
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (if (eq system-type 'hpux)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;; -T persuades HP's csh not to think it is smarter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;; than us about what terminal modes to use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 '("-i" "-T")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 '("-i"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 "*Args passed to inferior shell by M-x shell, if the shell is csh.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
242 Value is a list of strings, which may be nil."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
243 :type '(repeat (string :tag "Argument"))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
244 :group 'shell)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
246 (defcustom shell-input-autoexpand 'history
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 "*If non-nil, expand input command history references on completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 This mirrors the optional behavior of tcsh (its autoexpand and histlit).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 If the value is `input', then the expansion is seen on input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 If the value is `history', then the expansion is only when inserting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 into the buffer's input ring. See also `comint-magic-space' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 `comint-dynamic-complete'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 This variable supplies a default for `comint-input-autoexpand',
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
256 for Shell mode only."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
257 :type '(choice (const nil) (const input) (const history))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
258 :type 'shell)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (defvar shell-dirstack nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 "List of directories saved by pushd in this buffer's shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 Thus, this does not include the shell's current directory.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (defvar shell-dirtrackp t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 "Non-nil in a shell buffer means directory tracking is enabled.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (defvar shell-last-dir nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 "Keep track of last directory for ksh `cd -' command.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (defvar shell-dirstack-query nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 "Command used by `shell-resync-dirs' to query the shell.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defvar shell-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (if (not shell-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (let ((map (make-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (set-keymap-parents map (list comint-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (set-keymap-name map 'shell-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (define-key map "\C-c\C-f" 'shell-forward-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (define-key map "\C-c\C-b" 'shell-backward-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (define-key map "\t" 'comint-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (define-key map "\M-?" 'comint-dynamic-list-filename-completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;; XEmacs: this is a pretty common operation for those of us
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;; who use directory aliases ... someone shoot me if they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; don't like this binding. Another possibility is C-c C-s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; but that's way awkward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (define-key map "\M-\C-m" 'shell-resync-dirs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (setq shell-mode-map map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
289 (defcustom shell-mode-hook nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
290 "*Hook for customising Shell mode."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
291 :type 'hook
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
292 :group 'shell)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
294
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
295 ;; font-locking
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
296 (defcustom shell-prompt-face 'shell-prompt-face
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
297 "Face for shell prompts."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
298 :type 'face
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
299 :group 'shell-faces)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
300 (defcustom shell-option-face 'shell-option-face
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
301 "Face for command line options."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
302 :type 'face
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
303 :group 'shell-faces)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
304 (defcustom shell-output-face 'shell-output-face
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
305 "Face for generic shell output."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
306 :type 'face
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
307 :group 'shell-faces)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
308 (defcustom shell-output-2-face 'shell-output-2-face
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
309 "Face for grep-like output."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
310 :type 'face
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
311 :group 'shell-faces)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
312 (defcustom shell-output-3-face 'shell-output-3-face
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
313 "Face for [N] output where N is a number."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
314 :type 'face
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
315 :group 'shell-faces)
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
316
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
317 (make-face shell-prompt-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
318 (make-face shell-option-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
319 (make-face shell-output-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
320 (make-face shell-output-2-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
321 (make-face shell-output-3-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
322
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
323 (defun shell-font-lock-mode-hook ()
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
324 (or (face-differs-from-default-p shell-prompt-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
325 (copy-face 'font-lock-keyword-face shell-prompt-face))
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
326 (or (face-differs-from-default-p shell-option-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
327 (copy-face 'font-lock-comment-face shell-option-face))
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
328 (or (face-differs-from-default-p shell-output-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
329 (copy-face 'italic shell-output-face))
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
330 (or (face-differs-from-default-p shell-output-2-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
331 (copy-face 'font-lock-string-face shell-output-2-face))
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
332 (or (face-differs-from-default-p shell-output-3-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
333 (copy-face 'font-lock-string-face shell-output-3-face))
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
334 ;; we only need to do this once
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
335 (remove-hook 'font-lock-mode-hook 'shell-font-lock-mode-hook))
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
336 (add-hook 'font-lock-mode-hook 'shell-font-lock-mode-hook)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
337
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
338 (defvar shell-prompt-pattern-for-font-lock nil
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
339 "If non-nil, pattern to use to font-lock the prompt.
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
340 When nil, shell-prompt-pattern will be used. Set this to a regular
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
341 expression if you want the font-locked pattern to be different then
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
342 the shell's prompt pattern.")
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
343
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (defvar shell-font-lock-keywords
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
345 (list '(eval . (cons (if shell-prompt-pattern-for-font-lock
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
346 shell-prompt-pattern-for-font-lock
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
347 shell-prompt-pattern)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
348 shell-prompt-face))
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
349 '("[ \t]\\([+-][^ \t\n>]+\\)" 1 shell-option-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
350 '("^[^ \t\n]+:.*" . shell-output-2-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
351 '("^\\[[1-9][0-9]*\\]" . shell-output-3-face)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
352 '("^[^\n]+.*$" . shell-output-face))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 "Additional expressions to highlight in Shell mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (put 'shell-mode 'font-lock-defaults '(shell-font-lock-keywords t))
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 70
diff changeset
355
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;;; Basic Procedures
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (defun shell-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 "Major mode for interacting with an inferior shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 \\<shell-mode-map>\\[comint-send-input] after the end of the process' output sends the text from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 the end of process to the end of the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 \\[comint-send-input] before end of process output copies the current line minus the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 prompt to the end of the buffer and sends it (\\[comint-copy-old-input] just copies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 the current line).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 \\[send-invisible] reads a line of text without echoing it, and sends it to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 the shell. This is useful for entering passwords. Or, add the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 `comint-watch-for-password-prompt' to `comint-output-filter-functions'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 If you want to make multiple shell buffers, rename the `*shell*' buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 using \\[rename-buffer] or \\[rename-uniquely] and start a new shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 If you want to make shell buffers limited in length, add the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 `comint-truncate-buffer' to `comint-output-filter-functions'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 If you accidentally suspend your process, use \\[comint-continue-subjob]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 to continue it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 `cd', `pushd' and `popd' commands given to the shell are watched by Emacs to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 keep this buffer's default directory the same as the shell's working directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 While directory tracking is enabled, the shell's working directory is displayed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 by \\[list-buffers] or \\[mouse-buffer-menu] in the `File' field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 \\[shell-resync-dirs] queries the shell and resyncs Emacs' idea of what the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 current directory stack is.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 \\[shell-dirtrack-toggle] turns directory tracking on and off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 \\{shell-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 Customization: Entry to this mode runs the hooks on `comint-mode-hook' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 `shell-mode-hook' (in that order). Before each input, the hooks on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 `comint-input-filter-functions' are run. After each shell output, the hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 on `comint-output-filter-functions' are run.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 Variable `shell-multiple-shells' will automatically generate a new shell each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 time it is invoked.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 Variables `shell-cd-regexp', `shell-pushd-regexp' and `shell-popd-regexp'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 are used to match their respective commands, while `shell-pushd-tohome',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 `shell-pushd-dextract' and `shell-pushd-dunique' control the behavior of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 relevant command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 Variables `comint-completion-autolist', `comint-completion-addsuffix',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 `comint-completion-recexact' and `comint-completion-fignore' control the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 behavior of file name, command name and variable name completion. Variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 `shell-completion-execonly' controls the behavior of command name completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 Variable `shell-completion-fignore' is used to initialise the value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 `comint-completion-fignore'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 Variables `comint-input-ring-file-name' and `comint-input-autoexpand' control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 the initialisation of the input ring history, and history expansion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 Variables `comint-output-filter-functions', a hook, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 `comint-scroll-to-bottom-on-input' and `comint-scroll-to-bottom-on-output'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 control whether input and output cause the window to scroll to the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (comint-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (setq major-mode 'shell-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (setq mode-name "Shell")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (use-local-map shell-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (make-local-variable 'comint-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (setq comint-prompt-regexp shell-prompt-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (setq comint-completion-fignore shell-completion-fignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (make-local-variable 'comint-delimiter-argument-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (setq comint-delimiter-argument-list shell-delimiter-argument-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (make-local-variable 'comint-after-partial-filename-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (setq comint-after-partial-filename-command 'shell-after-partial-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (make-local-variable 'comint-get-current-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (setq comint-get-current-command 'shell-get-current-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (make-local-variable 'comint-dynamic-complete-command-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (setq comint-dynamic-complete-command-command 'shell-dynamic-complete-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (setq comint-file-name-quote-list shell-file-name-quote-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (setq comint-dynamic-complete-functions shell-dynamic-complete-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (make-local-variable 'paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (setq paragraph-start comint-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (make-local-variable 'shell-dirstack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (setq shell-dirstack nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (make-local-variable 'shell-last-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (setq shell-last-dir nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (make-local-variable 'shell-dirtrackp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (setq shell-dirtrackp t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (add-hook 'comint-input-filter-functions 'shell-directory-tracker nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (setq comint-input-autoexpand shell-input-autoexpand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (make-local-variable 'list-buffers-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (setq list-buffers-directory (expand-file-name default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; shell-dependent assignments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (let ((shell (file-name-nondirectory (car
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (process-command (get-buffer-process (current-buffer)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (setq comint-input-ring-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (or (getenv "HISTFILE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (cond ((string-equal shell "bash") "~/.bash_history")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ((string-equal shell "ksh") "~/.sh_history")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (t "~/.history"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (if (or (equal comint-input-ring-file-name "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (equal (file-truename comint-input-ring-file-name) "/dev/null"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (setq comint-input-ring-file-name nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (setq shell-dirstack-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (if (string-match "^k?sh$" shell) "pwd" "dirs")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (run-hooks 'shell-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (comint-read-input-ring t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (shell-dirstack-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (defun shell ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 "Run an inferior shell, with I/O through buffer *shell*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 If buffer exists but shell process is not running, make new shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 If buffer exists and shell process is running,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 just switch to buffer `*shell*'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 Program used comes from variable `explicit-shell-file-name',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 or (if that is nil) from the ESHELL environment variable,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 or else from SHELL if there is no ESHELL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 If a file `~/.emacs_SHELLNAME' exists, it is given as initial input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (Note that this may lose due to a timing error if the shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 discards input when it starts up.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 The buffer is put in Shell mode, giving commands for sending input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 and controlling the subjobs of the shell. See `shell-mode'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 See also the variable `shell-prompt-pattern'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 The shell file name (sans directories) is used to make a symbol name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 such as `explicit-csh-args'. If that symbol is a variable,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 its value is used as a list of arguments when invoking the shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 Otherwise, one argument `-i' is passed to the shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 \(Type \\[describe-mode] in the shell buffer for a list of commands.)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (let ((buffer "*shell*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (buffer-name (if shell-multiple-shells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 "*shell*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 "shell")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (cond ((or shell-multiple-shells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (not (comint-check-proc buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (let* ((prog (or explicit-shell-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (getenv "ESHELL")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (getenv "SHELL")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 "/bin/sh"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (name (file-name-nondirectory prog))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (startfile (concat "~/.emacs_" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (xargs-name (intern-soft (concat "explicit-" name "-args"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (setq buffer (set-buffer (apply 'make-comint buffer-name prog
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (if (file-exists-p startfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 startfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (if (and xargs-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (boundp xargs-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (symbol-value xargs-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 '("-i")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (shell-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (pop-to-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (if shell-multiple-shells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (rename-buffer (generate-new-buffer-name "*shell*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ;;; Don't do this when shell.el is loaded, only while dumping.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ;;;###autoload (add-hook 'same-window-buffer-names "*shell*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 ;;; Directory tracking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ;;; This code provides the shell mode input sentinel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ;;; SHELL-DIRECTORY-TRACKER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ;;; that tracks cd, pushd, and popd commands issued to the shell, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 ;;; changes the current directory of the shell buffer accordingly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ;;; This is basically a fragile hack, although it's more accurate than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 ;;; the version in Emacs 18's shell.el. It has the following failings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ;;; 1. It doesn't know about the cdpath shell variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;;; 2. It cannot infallibly deal with command sequences, though it does well
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;;; with these and with ignoring commands forked in another shell with ()s.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ;;; 3. More generally, any complex command is going to throw it. Otherwise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 ;;; you'd have to build an entire shell interpreter in emacs lisp. Failing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;;; that, there's no way to catch shell commands where cd's are buried
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ;;; inside conditional expressions, aliases, and so forth.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 ;;; The whole approach is a crock. Shell aliases mess it up. File sourcing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 ;;; messes it up. You run other processes under the shell; these each have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ;;; separate working directories, and some have commands for manipulating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ;;; their w.d.'s (e.g., the lcd command in ftp). Some of these programs have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ;;; commands that do *not* affect the current w.d. at all, but look like they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ;;; do (e.g., the cd command in ftp). In shells that allow you job
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ;;; control, you can switch between jobs, all having different w.d.'s. So
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ;;; simply saying %3 can shift your w.d..
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ;;; The solution is to relax, not stress out about it, and settle for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ;;; a hack that works pretty well in typical circumstances. Remember
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 ;;; that a half-assed solution is more in keeping with the spirit of Unix,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ;;; anyway. Blech.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 ;;; One good hack not implemented here for users of programmable shells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ;;; is to program up the shell w.d. manipulation commands to output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ;;; a coded command sequence to the tty. Something like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 ;;; ESC | <cwd> |
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ;;; where <cwd> is the new current working directory. Then trash the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;;; directory tracking machinery currently used in this package, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ;;; replace it with a process filter that watches for and strips out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ;;; these messages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (defun shell-directory-tracker (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 "Tracks cd, pushd and popd commands issued to the shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 This function is called on each input passed to the shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 It watches for cd, pushd and popd commands and sets the buffer's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 default directory to track these commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 You may toggle this tracking on and off with \\[shell-dirtrack-toggle].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 If emacs gets confused, you can resync with the shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 with \\[shell-resync-dirs].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 See variables `shell-cd-regexp', `shell-pushd-regexp', and `shell-popd-regexp',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 while `shell-pushd-tohome', `shell-pushd-dextract' and `shell-pushd-dunique'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 control the behavior of the relevant command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 Environment variables are expanded, see function `substitute-in-file-name'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (if shell-dirtrackp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ;; We fail gracefully if we think the command will fail in the shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (let ((start (progn (string-match "^[; \t]*" str) ; skip whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 end cmd arg1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (while (string-match shell-command-regexp str start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (setq end (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 cmd (comint-arguments (substring str start end) 0 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 arg1 (comint-arguments (substring str start end) 1 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (cond ((string-match (concat "\\`\\(" shell-popd-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 "\\)\\($\\|[ \t]\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (shell-process-popd (substitute-in-file-name arg1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 ((string-match (concat "\\`\\(" shell-pushd-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 "\\)\\($\\|[ \t]\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (shell-process-pushd (substitute-in-file-name arg1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 ((string-match (concat "\\`\\(" shell-cd-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 "\\)\\($\\|[ \t]\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (shell-process-cd (substitute-in-file-name arg1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (setq start (progn (string-match "[; \t]*" str end) ; skip again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 ;; XEmacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (message nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (display-error err t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ;; Like `cd', but prepends comint-file-name-prefix to absolute names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (defun shell-cd-1 (dir dirstack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (if shell-dirtrackp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (setq list-buffers-directory (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (expand-file-name dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (progn (if (file-name-absolute-p dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (cd-absolute (concat comint-file-name-prefix dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (cd dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (setq shell-dirstack dirstack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (shell-dirstack-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (file-error (message "Couldn't cd."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 ;;; popd [+n]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (defun shell-process-popd (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (let ((num (or (shell-extract-num arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (cond ((and num (= num 0) shell-dirstack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (shell-cd-1 (car shell-dirstack) (cdr shell-dirstack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 ((and num (> num 0) (<= num (length shell-dirstack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (let* ((ds (cons nil shell-dirstack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (cell (nthcdr (1- num) ds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (rplacd cell (cdr (cdr cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (setq shell-dirstack (cdr ds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (shell-dirstack-message)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (error "Couldn't popd")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 ;; Return DIR prefixed with comint-file-name-prefix as appropriate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (defun shell-prefixed-directory-name (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (if (= (length comint-file-name-prefix) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (if (file-name-absolute-p dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ;; The name is absolute, so prepend the prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (concat comint-file-name-prefix dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 ;; For relative name we assume default-directory already has the prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (expand-file-name dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 ;;; cd [dir]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (defun shell-process-cd (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (let ((new-dir (cond ((zerop (length arg)) (concat comint-file-name-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 "~"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ((string-equal "-" arg) shell-last-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (t (shell-prefixed-directory-name arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (setq shell-last-dir default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (shell-cd-1 new-dir shell-dirstack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 ;;; pushd [+n | dir]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (defun shell-process-pushd (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (let ((num (shell-extract-num arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (cond ((zerop (length arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 ;; no arg -- swap pwd and car of stack unless shell-pushd-tohome
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (cond (shell-pushd-tohome
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (shell-process-pushd (concat comint-file-name-prefix "~")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (shell-dirstack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (let ((old default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (shell-cd-1 (car shell-dirstack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (cons old (cdr shell-dirstack)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (message "Directory stack empty."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ((numberp num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 ;; pushd +n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (cond ((> num (length shell-dirstack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (message "Directory stack not that deep."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 ((= num 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (error (message "Couldn't cd.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (shell-pushd-dextract
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (let ((dir (nth (1- num) shell-dirstack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (shell-process-popd arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (shell-process-pushd default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (shell-cd-1 dir shell-dirstack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (let* ((ds (cons default-directory shell-dirstack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (dslen (length ds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (front (nthcdr num ds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (back (reverse (nthcdr (- dslen num) (reverse ds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (new-ds (append front back)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (shell-cd-1 (car new-ds) (cdr new-ds))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 ;; pushd <dir>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (let ((old-wd default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (shell-cd-1 (shell-prefixed-directory-name arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (if (or (null shell-pushd-dunique)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (not (member old-wd shell-dirstack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (cons old-wd shell-dirstack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 shell-dirstack)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ;; If STR is of the form +n, for n>0, return n. Otherwise, nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (defun shell-extract-num (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (and (string-match "^\\+[1-9][0-9]*$" str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (string-to-int str)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (defun shell-dirtrack-toggle ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 "Turn directory tracking on and off in a shell buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (if (setq shell-dirtrackp (not shell-dirtrackp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (setq list-buffers-directory default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (setq list-buffers-directory nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (message "Directory tracking %s" (if shell-dirtrackp "ON" "OFF")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 ;;; For your typing convenience:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 ;; XEmacs: removed this because then `M-x dir' doesn't complete to `dired'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 ;;(define-function 'dirtrack-toggle 'shell-dirtrack-toggle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (defun shell-cd (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 "Do normal `cd' to DIR, and set `list-buffers-directory'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (if shell-dirtrackp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (setq list-buffers-directory (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (expand-file-name dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (cd dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (defun shell-resync-dirs ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 "Resync the buffer's idea of the current directory stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 This command queries the shell with the command bound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 `shell-dirstack-query' (default \"dirs\"), reads the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 line output and parses it to form the new directory stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 DON'T issue this command unless the buffer is at a shell prompt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 Also, note that if some other subprocess decides to do output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 immediately after the query, its output will be taken as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 new directory stack -- you lose. If this happens, just do the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 command again."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (let* ((proc (get-buffer-process (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (pmark (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (goto-char pmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (insert shell-dirstack-query) (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (sit-for 0) ; force redisplay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (comint-send-string proc shell-dirstack-query)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (comint-send-string proc "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (set-marker pmark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (let ((pt (point))) ; wait for 1 line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;; This extra newline prevents the user's pending input from spoofing us.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (insert "\n") (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (while (not (looking-at ".+\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (accept-process-output proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (goto-char pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;; kludge to cope with shells that have "stty echo" turned on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 ;; of course this will lose if there is only one dir on the stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ;; and it is named "dirs"... -jwz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (if (looking-at "^dirs\r?\n") (delete-region (point) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (goto-char pmark) (delete-char 1) ; remove the extra newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ;; That's the dirlist. grab it & parse it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (let* ((dl (buffer-substring (match-beginning 0) (1- (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (dl-len (length dl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (ds '()) ; new dir stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (while (< i dl-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 ;; regexp = optional whitespace, (non-whitespace), optional whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (string-match "\\s *\\(\\S +\\)\\s *" dl i) ; pick off next dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (setq ds (cons (concat comint-file-name-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (substring dl (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (setq i (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (let ((ds (reverse ds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (shell-cd-1 (car ds) (cdr ds))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ;;; For your typing convenience:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 ;; XEmacs: removed this because then `M-x dir' doesn't complete to `dired'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 ;(define-function 'dirs 'shell-resync-dirs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 ;; XEmacs addition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (defvar shell-dirstack-message-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 "Hook to run after a cd, pushd or popd event")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 ;;; Show the current dirstack on the message line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 ;;; Pretty up dirs a bit by changing "/usr/jqr/foo" to "~/foo".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;;; (This isn't necessary if the dirlisting is generated with a simple "dirs".)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 ;;; All the commands that mung the buffer's dirstack finish by calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 ;;; this guy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (defun shell-dirstack-message ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (let* ((msg "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (ds (cons default-directory shell-dirstack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (home (format "^%s\\(/\\|$\\)" (regexp-quote (getenv "HOME"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (prefix (and comint-file-name-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 ;; XEmacs addition: don't turn "/foo" into "foo" !!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (not (= 0 (length comint-file-name-prefix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (format "^%s\\(/\\|$\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (regexp-quote comint-file-name-prefix)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (while ds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (let ((dir (car ds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (if (string-match home dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (setq dir (concat "~/" (substring dir (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 ;; Strip off comint-file-name-prefix if present.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (and prefix (string-match prefix dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (setq dir (substring dir (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (setcar ds dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (setq msg (concat msg dir " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (setq ds (cdr ds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 ;; XEmacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (run-hooks 'shell-dirstack-message-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (message msg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (defun shell-forward-command (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 "Move forward across ARG shell command(s). Does not cross lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 See `shell-command-regexp'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (let ((limit (save-excursion (end-of-line nil) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (if (re-search-forward (concat shell-command-regexp "\\([;&|][\t ]*\\)+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 limit 'move arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (skip-syntax-backward " "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (defun shell-backward-command (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 "Move backward across ARG shell command(s). Does not cross lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 See `shell-command-regexp'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (let ((limit (save-excursion (comint-bol nil) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (if (> limit (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (save-excursion (beginning-of-line) (setq limit (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (skip-syntax-backward " " limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (if (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (format "[;&|]+[\t ]*\\(%s\\)" shell-command-regexp) limit 'move arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (progn (goto-char (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (skip-chars-forward ";&|")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (defun shell-dynamic-complete-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 "Dynamically complete the command at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 This function is similar to `comint-dynamic-complete-filename', except that it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 searches `exec-path' (minus the trailing emacs library path) for completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 candidates. Note that this may not be the same as the shell's idea of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 path.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 Completion is dependent on the value of `shell-completion-execonly', plus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 those that effect file completion. See `shell-dynamic-complete-as-command'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 Returns t if successful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (let ((filename (comint-match-partial-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (if (and filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (save-match-data (not (string-match "[~/]" filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (eq (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (save-excursion (shell-backward-command 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (prog2 (message "Completing command name...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (shell-dynamic-complete-as-command)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (defun shell-dynamic-complete-as-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 "Dynamically complete at point as a command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 See `shell-dynamic-complete-filename'. Returns t if successful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (let* ((filename (or (comint-match-partial-filename) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (pathnondir (file-name-nondirectory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (paths (cdr (reverse exec-path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (cwd (file-name-as-directory (expand-file-name default-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (ignored-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (and comint-completion-fignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (mapconcat (function (lambda (x) (concat (regexp-quote x) "$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 comint-completion-fignore "\\|")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (path "") (comps-in-path ()) (file "") (filepath "") (completions ()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 ;; Go thru each path in the search path, finding completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (while paths
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (setq path (file-name-as-directory (comint-directory (or (car paths) ".")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 comps-in-path (and (file-accessible-directory-p path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (file-name-all-completions pathnondir path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 ;; Go thru each completion found, to see whether it should be used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (while comps-in-path
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (setq file (car comps-in-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 filepath (concat path file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (if (and (not (member file completions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (not (and ignored-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (string-match ignored-extensions file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (or (string-equal path cwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (not (file-directory-p filepath)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (or (null shell-completion-execonly)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (file-executable-p filepath)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (setq completions (cons file completions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (setq comps-in-path (cdr comps-in-path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (setq paths (cdr paths)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 ;; OK, we've got a list of completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (let ((success (let ((comint-completion-addsuffix nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (comint-dynamic-simple-complete pathnondir completions))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (if (and (memq success '(sole shortest)) comint-completion-addsuffix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (not (file-directory-p (comint-match-partial-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (insert " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 success)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (defun shell-match-partial-variable ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 "Return the variable at point, or nil if non is found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (let ((limit (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (if (re-search-backward "[^A-Za-z0-9_{}]" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (or (looking-at "\\$") (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 ;; Anchor the search forwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (if (or (eolp) (looking-at "[^A-Za-z0-9_{}$]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (re-search-forward "\\$?{?[A-Za-z0-9_]*}?" limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (buffer-substring (match-beginning 0) (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (defun shell-dynamic-complete-environment-variable ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 "Dynamically complete the environment variable at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 Completes if after a variable, i.e., if it starts with a \"$\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 See `shell-dynamic-complete-as-environment-variable'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 This function is similar to `comint-dynamic-complete-filename', except that it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 searches `process-environment' for completion candidates. Note that this may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 not be the same as the interpreter's idea of variable names. The main problem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 with this type of completion is that `process-environment' is the environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 which Emacs started with. Emacs does not track changes to the environment made
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 by the interpreter. Perhaps it would be more accurate if this function was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 called `shell-dynamic-complete-process-environment-variable'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 Returns non-nil if successful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (let ((variable (shell-match-partial-variable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (if (and variable (string-match "^\\$" variable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (prog2 (message "Completing variable name...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (shell-dynamic-complete-as-environment-variable)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (defun shell-dynamic-complete-as-environment-variable ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 "Dynamically complete at point as an environment variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 Used by `shell-dynamic-complete-environment-variable'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 Uses `comint-dynamic-simple-complete'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (let* ((var (or (shell-match-partial-variable) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (variable (substring var (or (string-match "[^$({]\\|$" var) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (variables (mapcar (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (substring x 0 (string-match "=" x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 process-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (addsuffix comint-completion-addsuffix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (comint-completion-addsuffix nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (success (comint-dynamic-simple-complete variable variables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (if (memq success '(sole shortest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (let* ((var (shell-match-partial-variable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (variable (substring var (string-match "[^$({]" var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (protection (cond ((string-match "{" var) "}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 ((string-match "(" var) ")")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (t "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (suffix (cond ((null addsuffix) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 ((file-directory-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (comint-directory (getenv variable))) "/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (t " "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (insert protection suffix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 success))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (defun shell-replace-by-expanded-directory ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 "Expand directory stack reference before point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 Directory stack references are of the form \"=digit\" or \"=-\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 See `default-directory' and `shell-dirstack'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 Returns t if successful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (if (comint-match-partial-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (let ((stack (cons default-directory shell-dirstack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (index (cond ((looking-at "=-/?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (length shell-dirstack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 ((looking-at "=\\([0-9]+\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (string-to-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (match-beginning 1) (match-end 1)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (cond ((null index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 ((>= index (length stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (error "Directory stack not that deep."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (replace-match (file-name-as-directory (nth index stack)) t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (message "Directory item: %d" index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (provide 'shell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 ;;; shell.el ends here