Mercurial > emacs
annotate lisp/eshell/eshell.el @ 105498:3cdeeb563149
Markus Rost <rost at math.uni-bielefeld.de>
(describe-no-warranty): Place point in a slightly better position in
the GPLv3 text.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Wed, 07 Oct 2009 02:52:37 +0000 |
parents | a9dc0e7c3f2b |
children | 1d1d5d9bd884 |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38120
diff
changeset
|
1 ;;; eshell.el --- the Emacs command shell |
29876 | 2 |
74509 | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
100908 | 4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
29876 | 5 |
6 ;; Author: John Wiegley <johnw@gnu.org> | |
38120
64002802a902
Added a version string.
John Wiegley <johnw@newartisans.com>
parents:
38119
diff
changeset
|
7 ;; Version: 2.4.2 |
29876 | 8 ;; Keywords: processes |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
29876 | 13 ;; it under the terms of the GNU General Public License as published by |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; (at your option) any later version. |
29876 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
29876 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;;;_* What does Eshell offer you? | |
28 ;; | |
29 ;; Despite the sheer fact that running an Emacs shell can be fun, here | |
30 ;; are a few of the unique features offered by Eshell: | |
31 ;; | |
32 ;; @ Integration with the Emacs Lisp programming environment | |
33 ;; | |
34 ;; @ A high degree of configurability | |
35 ;; | |
36 ;; @ The ability to have the same shell on every system Emacs has been | |
37 ;; ported to. Since Eshell imposes no external requirements, and | |
38 ;; relies upon only the Lisp functions exposed by Emacs, it is quite | |
39 ;; operating system independent. Several of the common UNIX | |
40 ;; commands, such as ls, mv, rm, ln, etc., have been implemented in | |
41 ;; Lisp in order to provide a more consistent work environment. | |
42 ;; | |
43 ;; For those who might be using an older version of Eshell, version | |
44 ;; 2.1 represents an entirely new, module-based architecture. It | |
45 ;; supports most of the features offered by modern shells. Here is a | |
46 ;; brief list of some of its more visible features: | |
47 ;; | |
48 ;; @ Command argument completion (tcsh, zsh) | |
49 ;; @ Input history management (bash) | |
50 ;; @ Intelligent output scrolling | |
50937
dfc70cb4fd02
Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents:
46705
diff
changeset
|
51 ;; @ Pseudo-devices (such as "/dev/clip" for copying to the clipboard) |
29876 | 52 ;; @ Extended globbing (zsh) |
53 ;; @ Argument and globbing predication (zsh) | |
54 ;; @ I/O redirection to buffers, files, symbols, processes, etc. | |
55 ;; @ Many niceties otherwise seen only in 4DOS | |
56 ;; @ Alias functions, both Lisp and Eshell-syntax | |
57 ;; @ Piping, sequenced commands, background jobs, etc... | |
58 ;; | |
59 ;;;_* How to begin | |
60 ;; | |
86416
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
61 ;; To start using Eshell, simply type `M-x eshell'. |
29876 | 62 ;; |
63 ;;;_* Philosophy | |
64 ;; | |
65 ;; A shell is a layer which metaphorically surrounds the kernel, or | |
66 ;; heart of an operating system. This kernel can be seen as an engine | |
67 ;; of pure functionality, waiting to serve, while the user programs | |
68 ;; take advantage of that functionality to accomplish their purpose. | |
69 ;; | |
70 ;; The shell's role is to make that functionality accessible to the | |
71 ;; user in an unformed state. Very roughly, it associates kernel | |
72 ;; functionality with textual commands, allowing the user to interact | |
73 ;; with the operating system via linguistic constructs. Process | |
74 ;; invocation is perhaps the most significant form this takes, using | |
75 ;; the kernel's `fork' and `exec' functions. | |
76 ;; | |
77 ;; Other programs also interact with the functionality of the kernel, | |
78 ;; but these user applications typically offer a specific range of | |
79 ;; functionality, and thus are not classed as "shells" proper. | |
80 ;; (What they lose in quiddity, they gain in rigidity). | |
81 ;; | |
82 ;; Emacs is also a user application, but it does make the | |
83 ;; functionality of the kernel accessible through an interpreted | |
84 ;; language -- namely, Lisp. For that reason, there is little | |
85 ;; preventing Emacs from serving the same role as a modern shell. It | |
86 ;; too can manipulate the kernel in an unpredetermined way to cause | |
87 ;; system changes. All it's missing is the shell-ish linguistic | |
88 ;; model. | |
89 ;; | |
90 ;; Enter Eshell. Eshell translates "shell-like" syntax into Lisp | |
91 ;; in order to exercise the kernel in the same manner as typical | |
92 ;; system shells. There is a fundamental difference here, however, | |
93 ;; although it may seem subtle at first... | |
94 ;; | |
95 ;; Shells like csh and Bourne shell were written several decades ago, | |
96 ;; in different times, under more restrictive circumstances. This | |
97 ;; confined perspective shows itself in the paradigm used by nearly | |
98 ;; all command-line shells since. They are linear in conception, byte | |
99 ;; stream-based, sequential, and confined to movement within a single | |
100 ;; host machine. | |
101 ;; | |
102 ;; Emacs, on the other hand, is more than just a limited translator | |
103 ;; that can invoke subprocesses and redirect file handles. It also | |
104 ;; manages character buffers, windowing frames, network connections, | |
105 ;; registers, bookmarks, processes, etc. In other words, it's a very | |
106 ;; multi-dimensional environment, within which eshell emulates a highly | |
107 ;; linear methodology. | |
108 ;; | |
109 ;; Taking a moment, let's look at how this could affect the future of | |
110 ;; a shell allowed to develop in such a wider field of play: | |
111 ;; | |
112 ;; @ There is no reason why directory movement should be linear, and | |
113 ;; confined to a single file-system. Emacs, through w3 and ange-ftp, | |
114 ;; has access to the entire Web. Why not allow a user to cd to | |
115 ;; multiple directories simultaneously, for example? It might make | |
116 ;; some tasks easier, such as diff'ing files separated by very long | |
117 ;; pathnames. | |
118 ;; | |
119 ;; @ Data sources are available from anywhere Emacs can derive | |
120 ;; information from: not just from files or the output of other | |
121 ;; processes. | |
122 ;; | |
123 ;; @ Multiple shell invocations all share the same environment -- even | |
124 ;; the same process list! It would be possible to have "process | |
125 ;; views", so that one buffer is watching standard output, another | |
126 ;; standard error, and another the result of standard output grep'd | |
127 ;; through a regular expression... | |
128 ;; | |
129 ;; @ It is not necessary to "leave" the shell, losing all input and | |
130 ;; output history, environment variables, directory stack, etc. | |
131 ;; Emacs could save the contents of your eshell environment, and | |
132 ;; restore all of it (or at least as much as possible) each time you | |
133 ;; restart. This could occur automatically, without requiring | |
134 ;; complex initialization scripts. | |
135 ;; | |
136 ;; @ Typos occur all of the time; many of them are repeats of common | |
137 ;; errors, such as 'dri' for `dir'. Since executing non-existent | |
138 ;; programs is rarely the intention of the user, eshell could prompt | |
139 ;; for the replacement string, and then record that in a database of | |
140 ;; known misspellings. (Note: The typo at the beginning of this | |
141 ;; paragraph wasn't discovered until two months after I wrote the | |
142 ;; text; it was not intentional). | |
143 ;; | |
144 ;; @ Emacs' register and bookmarking facilities can be used for | |
145 ;; remembering where you've been, and what you've seen -- to varying | |
146 ;; levels of persistence. They could perhaps even be tied to | |
147 ;; specific "moments" during eshell execution, which would include | |
148 ;; the environment at that time, as well as other variables. | |
149 ;; Although this would require functionality orthogonal to Emacs' | |
150 ;; own bookmarking facilities, the interface used could be made to | |
151 ;; operate very similarly. | |
152 ;; | |
153 ;; This presents a brief idea of what the fuller dimensionality of an | |
154 ;; Emacs shell could offer. It's not just the language of a shell | |
155 ;; that determines how it's used, but also the Weltanschauung | |
156 ;; underlying its design -- and which is felt behind even the smallest | |
157 ;; feature. I would hope the freedom provided by using Emacs as a | |
158 ;; parent environment will invite rich ideas from others. It | |
159 ;; certainly feels as though all I've done so far is to tie down the | |
160 ;; horse, so to speak, so that he will run at a man's pace. | |
161 ;; | |
162 ;;;_* Influences | |
163 ;; | |
164 ;; The author of Eshell has been a long-time user of the following | |
165 ;; shells, all of which contributed to Eshell's design: | |
166 ;; | |
167 ;; @ rc | |
168 ;; @ bash | |
169 ;; @ zsh | |
170 ;; @ sh | |
171 ;; @ 4nt | |
172 ;; @ csh | |
173 | |
38119
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
174 ;;;_* Speeding up load time |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
175 ;; |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
176 ;; If you find that Eshell loads too slowly, there is something you |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
177 ;; can do to speed it up. |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
178 ;; |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
179 ;; Create a file, named /tmp/elc, containing this filelist: |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
180 ;; |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
181 ;; esh-util.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
182 ;; eshell.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
183 ;; esh-module.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
184 ;; esh-var.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
185 ;; esh-proc.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
186 ;; esh-arg.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
187 ;; esh-io.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
188 ;; esh-ext.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
189 ;; esh-cmd.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
190 ;; esh-mode.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
191 ;; esh-opt.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
192 ;; em-alias.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
193 ;; em-banner.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
194 ;; em-basic.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
195 ;; em-cmpl.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
196 ;; em-dirs.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
197 ;; em-pred.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
198 ;; em-glob.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
199 ;; em-hist.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
200 ;; em-ls.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
201 ;; em-prompt.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
202 ;; em-rebind.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
203 ;; em-script.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
204 ;; em-smart.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
205 ;; em-term.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
206 ;; em-unix.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
207 ;; em-xtra.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
208 ;; |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
209 ;; The order is very important. Remove from the filelist any features |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
210 ;; you don't use. These all begin with "em-". If you don't use |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
211 ;; Eshell's key rebinding module, you can remove "em-rebind.elc" from |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
212 ;; the filelist. The modules you are currently using are listed in |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
213 ;; `eshell-modules-list'. |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
214 ;; |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
215 ;; Now, concatenating all of the above mentioned .elc files, in that |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
216 ;; order, to another file. Here is how to do this on UNIX: |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
217 ;; |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
218 ;; cat `cat /tmp/elc` > tmp.elc ; mv tmp.elc eshell.elc |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
219 ;; |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
220 ;; Now your eshell.elc file contains all of the .elc files that make |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
221 ;; up Eshell, in the right load order. When you next load Eshell, it |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
222 ;; will only have to read in this one file, which will greatly speed |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
223 ;; things up. |
9c0099738383
Don't load in esh-util if it's already loaded. Also, added a comment
John Wiegley <johnw@newartisans.com>
parents:
37436
diff
changeset
|
224 |
87083
52787def92eb
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86487
diff
changeset
|
225 (eval-when-compile |
52787def92eb
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86487
diff
changeset
|
226 (require 'cl) |
52787def92eb
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86487
diff
changeset
|
227 (require 'esh-util)) |
86416
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
228 (require 'esh-util) |
87083
52787def92eb
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86487
diff
changeset
|
229 (require 'esh-mode) |
86416
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
230 |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
231 (defgroup eshell nil |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
232 "Eshell is a command shell implemented entirely in Emacs Lisp. It |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
233 invokes no external processes beyond those requested by the user. It |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
234 is intended to be a functional replacement for command shells such as |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
235 bash, zsh, rc, 4dos; since Emacs itself is capable of handling most of |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
236 the tasks accomplished by such tools." |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
237 :tag "The Emacs shell" |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
238 :link '(info-link "(eshell)Top") |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
239 :version "21.1" |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
240 :group 'applications) |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
241 |
95151 | 242 ;; This is hack to force make-autoload to put the whole definition |
243 ;; into the autoload file (see esh-module.el). | |
244 (defalias 'eshell-defgroup 'defgroup) | |
86416
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
245 |
29876 | 246 ;;;_* User Options |
247 ;; | |
248 ;; The following user options modify the behavior of Eshell overall. | |
87083
52787def92eb
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
86487
diff
changeset
|
249 (defvar eshell-buffer-name) |
29876 | 250 |
251 (defsubst eshell-add-to-window-buffer-names () | |
252 "Add `eshell-buffer-name' to `same-window-buffer-names'." | |
253 (add-to-list 'same-window-buffer-names eshell-buffer-name)) | |
254 | |
255 (defsubst eshell-remove-from-window-buffer-names () | |
256 "Remove `eshell-buffer-name' from `same-window-buffer-names'." | |
257 (setq same-window-buffer-names | |
258 (delete eshell-buffer-name same-window-buffer-names))) | |
259 | |
260 (defcustom eshell-load-hook nil | |
86416
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
261 "A hook run once Eshell has been loaded." |
29876 | 262 :type 'hook |
263 :group 'eshell) | |
264 | |
265 (defcustom eshell-unload-hook | |
266 '(eshell-remove-from-window-buffer-names | |
267 eshell-unload-all-modules) | |
86416
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
268 "A hook run when Eshell is unloaded from memory." |
29876 | 269 :type 'hook |
270 :group 'eshell) | |
271 | |
272 (defcustom eshell-buffer-name "*eshell*" | |
86416
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
273 "The basename used for Eshell buffers." |
29876 | 274 :set (lambda (symbol value) |
275 ;; remove the old value of `eshell-buffer-name', if present | |
276 (if (boundp 'eshell-buffer-name) | |
277 (eshell-remove-from-window-buffer-names)) | |
278 (set symbol value) | |
279 ;; add the new value | |
280 (eshell-add-to-window-buffer-names) | |
281 value) | |
282 :type 'string | |
283 :group 'eshell) | |
284 | |
285 (eshell-deftest mode same-window-buffer-names | |
286 "`eshell-buffer-name' is a member of `same-window-buffer-names'" | |
287 (member eshell-buffer-name same-window-buffer-names)) | |
288 | |
30271
54ff6ef3d884
(eshell-directory-name): Run default directory
Eli Zaretskii <eliz@gnu.org>
parents:
29934
diff
changeset
|
289 (defcustom eshell-directory-name (convert-standard-filename "~/.eshell/") |
86416
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
290 "The directory where Eshell control files should be kept." |
29876 | 291 :type 'directory |
292 :group 'eshell) | |
293 | |
294 (eshell-deftest mode eshell-directory-exists | |
295 "`eshell-directory-name' exists and is writable" | |
296 (file-writable-p eshell-directory-name)) | |
297 | |
298 (eshell-deftest mode eshell-directory-modes | |
299 "`eshell-directory-name' has correct access protections" | |
300 (or (eshell-under-windows-p) | |
301 (= (file-modes eshell-directory-name) | |
302 eshell-private-directory-modes))) | |
303 | |
304 ;;;_* Running Eshell | |
305 ;; | |
306 ;; There are only three commands used to invoke Eshell. The first two | |
307 ;; are intended for interactive use, while the third is meant for | |
308 ;; programmers. They are: | |
309 | |
310 ;;;###autoload | |
311 (defun eshell (&optional arg) | |
312 "Create an interactive Eshell buffer. | |
313 The buffer used for Eshell sessions is determined by the value of | |
314 `eshell-buffer-name'. If there is already an Eshell session active in | |
315 that buffer, Emacs will simply switch to it. Otherwise, a new session | |
46705
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
316 will begin. A numeric prefix arg (as in `C-u 42 M-x eshell RET') |
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
317 switches to the session with that number, creating it if necessary. A |
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
318 nonnumeric prefix arg means to create a new session. Returns the |
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
319 buffer selected (or created)." |
29876 | 320 (interactive "P") |
321 (assert eshell-buffer-name) | |
46705
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
322 (let ((buf (cond ((numberp arg) |
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
323 (get-buffer-create (format "%s<%d>" |
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
324 eshell-buffer-name |
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
325 arg))) |
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
326 (arg |
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
327 (generate-new-buffer eshell-buffer-name)) |
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
328 (t |
9f4f7bee7b8d
(eshell): Numeric prefix arg means to switch
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43321
diff
changeset
|
329 (get-buffer-create eshell-buffer-name))))) |
29876 | 330 ;; Simply calling `pop-to-buffer' will not mimic the way that |
331 ;; shell-mode buffers appear, since they always reuse the same | |
332 ;; window that that command was invoked from. To achieve this, | |
333 ;; it's necessary to add `eshell-buffer-name' to the variable | |
334 ;; `same-window-buffer-names', which is done when Eshell is loaded | |
335 (assert (and buf (buffer-live-p buf))) | |
336 (pop-to-buffer buf) | |
86416
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
337 (unless (eq major-mode 'eshell-mode) |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
338 (eshell-mode)) |
29876 | 339 buf)) |
340 | |
341 (defun eshell-return-exits-minibuffer () | |
342 (define-key eshell-mode-map [(control ?g)] 'abort-recursive-edit) | |
343 (define-key eshell-mode-map [return] 'exit-minibuffer) | |
344 (define-key eshell-mode-map [(control ?m)] 'exit-minibuffer) | |
345 (define-key eshell-mode-map [(control ?j)] 'exit-minibuffer) | |
346 (define-key eshell-mode-map [(meta return)] 'exit-minibuffer) | |
347 (define-key eshell-mode-map [(meta control ?m)] 'exit-minibuffer)) | |
348 | |
37436
33a9a90f3e76
(eshell-command): Made a few changes so that `eshell-command' could be
John Wiegley <johnw@newartisans.com>
parents:
37281
diff
changeset
|
349 (defvar eshell-non-interactive-p nil |
33a9a90f3e76
(eshell-command): Made a few changes so that `eshell-command' could be
John Wiegley <johnw@newartisans.com>
parents:
37281
diff
changeset
|
350 "A variable which is non-nil when Eshell is not running interactively. |
33a9a90f3e76
(eshell-command): Made a few changes so that `eshell-command' could be
John Wiegley <johnw@newartisans.com>
parents:
37281
diff
changeset
|
351 Modules should use this variable so that they don't clutter |
33a9a90f3e76
(eshell-command): Made a few changes so that `eshell-command' could be
John Wiegley <johnw@newartisans.com>
parents:
37281
diff
changeset
|
352 non-interactive sessions, such as when using `eshell-command'.") |
33a9a90f3e76
(eshell-command): Made a few changes so that `eshell-command' could be
John Wiegley <johnw@newartisans.com>
parents:
37281
diff
changeset
|
353 |
29876 | 354 ;;;###autoload |
355 (defun eshell-command (&optional command arg) | |
356 "Execute the Eshell command string COMMAND. | |
357 With prefix ARG, insert output into the current buffer at point." | |
358 (interactive) | |
359 (require 'esh-cmd) | |
37436
33a9a90f3e76
(eshell-command): Made a few changes so that `eshell-command' could be
John Wiegley <johnw@newartisans.com>
parents:
37281
diff
changeset
|
360 (unless arg |
33a9a90f3e76
(eshell-command): Made a few changes so that `eshell-command' could be
John Wiegley <johnw@newartisans.com>
parents:
37281
diff
changeset
|
361 (setq arg current-prefix-arg)) |
29876 | 362 (unwind-protect |
363 (let ((eshell-non-interactive-p t)) | |
364 (add-hook 'minibuffer-setup-hook 'eshell-mode) | |
43321
358616bbe6a1
(eshell-command): Before reading from the minibuffer, add
John Wiegley <johnw@newartisans.com>
parents:
42686
diff
changeset
|
365 (add-hook 'minibuffer-exit-hook 'eshell-add-command-to-history) |
29876 | 366 (add-hook 'eshell-mode-hook 'eshell-return-exits-minibuffer) |
37436
33a9a90f3e76
(eshell-command): Made a few changes so that `eshell-command' could be
John Wiegley <johnw@newartisans.com>
parents:
37281
diff
changeset
|
367 (unless command |
33a9a90f3e76
(eshell-command): Made a few changes so that `eshell-command' could be
John Wiegley <johnw@newartisans.com>
parents:
37281
diff
changeset
|
368 (setq command (read-from-minibuffer "Emacs shell command: ")))) |
29876 | 369 (remove-hook 'eshell-mode-hook 'eshell-return-exits-minibuffer) |
43321
358616bbe6a1
(eshell-command): Before reading from the minibuffer, add
John Wiegley <johnw@newartisans.com>
parents:
42686
diff
changeset
|
370 (remove-hook 'minibuffer-exit-hook 'eshell-add-command-to-history) |
29876 | 371 (remove-hook 'minibuffer-setup-hook 'eshell-mode)) |
372 (unless command | |
373 (error "No command specified!")) | |
374 ;; redirection into the current buffer is achieved by adding an | |
375 ;; output redirection to the end of the command, of the form | |
376 ;; 'COMMAND >>> #<buffer BUFFER>'. This will not interfere with | |
377 ;; other redirections, since multiple redirections merely cause the | |
378 ;; output to be copied to multiple target locations | |
379 (if arg | |
380 (setq command | |
381 (concat command | |
382 (format " >>> #<buffer %s>" | |
383 (buffer-name (current-buffer)))))) | |
384 (save-excursion | |
385 (let ((buf (set-buffer (generate-new-buffer " *eshell cmd*"))) | |
386 (eshell-non-interactive-p t)) | |
387 (eshell-mode) | |
388 (let* ((proc (eshell-eval-command | |
389 (list 'eshell-commands | |
390 (eshell-parse-command command)))) | |
391 intr | |
392 (bufname (if (and proc (listp proc)) | |
393 "*EShell Async Command Output*" | |
394 (setq intr t) | |
395 "*EShell Command Output*"))) | |
396 (if (buffer-live-p (get-buffer bufname)) | |
397 (kill-buffer bufname)) | |
398 (rename-buffer bufname) | |
399 ;; things get a little coarse here, since the desire is to | |
400 ;; make the output as attractive as possible, with no | |
401 ;; extraneous newlines | |
402 (when intr | |
403 (if (eshell-interactive-process) | |
404 (eshell-wait-for-process (eshell-interactive-process))) | |
405 (assert (not (eshell-interactive-process))) | |
406 (goto-char (point-max)) | |
407 (while (and (bolp) (not (bobp))) | |
408 (delete-backward-char 1))) | |
409 (assert (and buf (buffer-live-p buf))) | |
410 (unless arg | |
411 (let ((len (if (not intr) 2 | |
412 (count-lines (point-min) (point-max))))) | |
413 (cond | |
414 ((= len 0) | |
415 (message "(There was no command output)") | |
416 (kill-buffer buf)) | |
417 ((= len 1) | |
37281
85c38f2eac06
(eshell-command): Needed a "%s" format specifier, in case the buffer
John Wiegley <johnw@newartisans.com>
parents:
32451
diff
changeset
|
418 (message "%s" (buffer-string)) |
29876 | 419 (kill-buffer buf)) |
420 (t | |
421 (save-selected-window | |
422 (select-window (display-buffer buf)) | |
423 (goto-char (point-min)) | |
424 ;; cause the output buffer to take up as little screen | |
425 ;; real-estate as possible, if temp buffer resizing is | |
426 ;; enabled | |
427 (and intr temp-buffer-resize-mode | |
428 (resize-temp-buffer-window))))))))))) | |
429 | |
430 ;;;###autoload | |
431 (defun eshell-command-result (command &optional status-var) | |
432 "Execute the given Eshell COMMAND, and return the result. | |
433 The result might be any Lisp object. | |
434 If STATUS-VAR is a symbol, it will be set to the exit status of the | |
435 command. This is the only way to determine whether the value returned | |
436 corresponding to a successful execution." | |
437 ;; a null command produces a null, successful result | |
438 (if (not command) | |
439 (ignore | |
440 (if (and status-var (symbolp status-var)) | |
441 (set status-var 0))) | |
442 (with-temp-buffer | |
443 (let ((eshell-non-interactive-p t)) | |
444 (eshell-mode) | |
445 (let ((result (eshell-do-eval | |
446 (list 'eshell-commands | |
447 (list 'eshell-command-to-value | |
448 (eshell-parse-command command))) t))) | |
449 (assert (eq (car result) 'quote)) | |
450 (if (and status-var (symbolp status-var)) | |
451 (set status-var eshell-last-command-status)) | |
452 (cadr result)))))) | |
453 | |
454 (eshell-deftest mode simple-command-result | |
455 "`eshell-command-result' works with a simple command." | |
456 (= (eshell-command-result "+ 1 2") 3)) | |
457 | |
458 ;;;_* Reporting bugs | |
459 ;; | |
86424
abb353cfc8db
(eshell-report-bug-address): Remove.
Glenn Morris <rgm@gnu.org>
parents:
86416
diff
changeset
|
460 ;; If you do encounter a bug, on any system, please report |
29876 | 461 ;; it -- in addition to any particular oddities in your configuration |
462 ;; -- so that the problem may be corrected for the benefit of others. | |
463 | |
464 ;;;###autoload | |
86487
70414d2bb729
(eshell-report-bug): Add version number of obsolescence.
Glenn Morris <rgm@gnu.org>
parents:
86424
diff
changeset
|
465 (define-obsolete-function-alias 'eshell-report-bug 'report-emacs-bug "23.1") |
29876 | 466 |
467 ;;; Code: | |
468 | |
469 (defun eshell-unload-all-modules () | |
470 "Unload all modules that were loaded by Eshell, if possible. | |
471 If the user has require'd in any of the modules, or customized a | |
472 variable with a :require tag (such as `eshell-prefer-to-shell'), it | |
473 will be impossible to unload Eshell completely without restarting | |
474 Emacs." | |
475 ;; if the user set `eshell-prefer-to-shell' to t, but never loaded | |
476 ;; Eshell, then `eshell-subgroups' will be unbound | |
477 (when (fboundp 'eshell-subgroups) | |
478 (eshell-for module (eshell-subgroups 'eshell) | |
479 ;; this really only unloads as many modules as possible, | |
480 ;; since other `require' references (such as by customizing | |
481 ;; `eshell-prefer-to-shell' to a non-nil value) might make it | |
482 ;; impossible to unload Eshell completely | |
483 (if (featurep module) | |
484 (ignore-errors | |
485 (message "Unloading %s..." (symbol-name module)) | |
486 (unload-feature module) | |
487 (message "Unloading %s...done" (symbol-name module))))) | |
488 (message "Unloading eshell...done"))) | |
489 | |
490 (run-hooks 'eshell-load-hook) | |
491 | |
86416
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
492 (provide 'eshell) |
b8c6722b2727
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
493 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
494 ;; arch-tag: 9d4d5214-0e4e-4e02-b349-39add640d63f |
29876 | 495 ;;; eshell.el ends here |