annotate lisp/shell.el @ 17884:aa0b21b54684

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