Gnus: Improve parts deletion and stripping behavior
[emacs.git] / doc / misc / eshell.texi
blobca90573f30bcdc46f746cf6fc4a96dd67d692d6a
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename ../../info/eshell.info
4 @settitle Eshell: The Emacs Shell
5 @defindex cm
6 @synindex vr fn
7 @documentencoding UTF-8
8 @c %**end of header
10 @copying
11 This manual is for Eshell, the Emacs shell.
13 Copyright @copyright{} 1999--2015 Free Software Foundation, Inc.
15 @quotation
16 Permission is granted to copy, distribute and/or modify this document
17 under the terms of the GNU Free Documentation License, Version 1.3 or
18 any later version published by the Free Software Foundation; with no
19 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
20 and with the Back-Cover Texts as in (a) below.  A copy of the license
21 is included in the section entitled ``GNU Free Documentation License''.
23 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
24 modify this GNU manual.''
25 @end quotation
26 @end copying
28 @dircategory Emacs misc features
29 @direntry
30 * Eshell: (eshell).             A command shell implemented in Emacs Lisp.
31 @end direntry
33 @titlepage
34 @sp 4
35 @c The title is printed in a large font.
36 @center @titlefont{User's Guide}
37 @sp 1
38 @center @titlefont{to}
39 @sp 1
40 @center @titlefont{Eshell: The Emacs Shell}
41 @ignore
42 @sp 2
43 @center release 2.4
44 @c -release-
45 @end ignore
46 @sp 3
47 @center John Wiegley & Aidan Gauland
48 @c -date-
50 @page
51 @vskip 0pt plus 1filll
52 @insertcopying
53 @end titlepage
55 @contents
57 @c ================================================================
58 @c                   The real text starts here
59 @c ================================================================
61 @ifnottex
62 @node Top
63 @top Eshell
65 Eshell is a shell-like command interpreter implemented in Emacs Lisp.
66 It invokes no external processes except for those requested by the
67 user.  It is intended to be an alternative to the IELM (@pxref{Lisp Interaction, Emacs Lisp Interaction, , emacs, The Emacs Editor})
68 REPL for Emacs @emph{and} with an interface similar to command shells
69 such as @command{bash}, @command{zsh}, @command{rc}, or
70 @command{4dos}.
71 @c This manual is updated to release 2.4 of Eshell.
73 @insertcopying
74 @end ifnottex
76 @menu
77 * Introduction::             A brief introduction to the Emacs Shell.
78 * Commands::
79 * Expansion::
80 * Input/Output::
81 * Extension modules::
82 * Bugs and ideas::              Known problems, and future ideas.
83 * GNU Free Documentation License:: The license for this documentation.
84 * Concept Index::
85 * Function and Variable Index::
86 * Command Index::
87 * Key Index::
88 @end menu
90 @node Introduction
91 @chapter Introduction
92 @section What is Eshell?
93 @cindex what is Eshell?
94 @cindex Eshell, what it is
96 Eshell is a @dfn{command shell} written in Emacs Lisp.  Everything it
97 does, it uses Emacs's facilities to do.  This means that Eshell is as
98 portable as Emacs itself.  It also means that cooperation with Lisp code
99 is natural and seamless.
101 What is a command shell?  To properly understand the role of a shell,
102 it's necessary to visualize what a computer does for you.  Basically, a
103 computer is a tool; in order to use that tool, you must tell it what to
104 do---or give it ``commands.''  These commands take many forms, such as
105 clicking with a mouse on certain parts of the screen.  But that is only
106 one form of command input.
108 By far the most versatile way to express what you want the computer to
109 do is by using an abbreviated language called @dfn{script}.  In
110 script, instead of telling the computer, ``list my files, please'',
111 one writes a standard abbreviated command word---@samp{ls}.  Typing
112 @samp{ls} in a command shell is a script way of telling the computer
113 to list your files.@footnote{This is comparable to viewing the
114 contents of a folder using a graphical display.}
116 The real flexibility of this approach is apparent only when you realize
117 that there are many, many different ways to list files.  Perhaps you
118 want them sorted by name, sorted by date, in reverse order, or grouped
119 by type.  Most graphical browsers have simple ways to express this.  But
120 what about showing only a few files, or only files that meet a certain
121 criteria?  In very complex and specific situations, the request becomes
122 too difficult to express using a mouse or pointing device.  It is just
123 these kinds of requests that are easily solved using a command shell.
125 For example, what if you want to list every Word file on your hard
126 drive, larger than 100 kilobytes in size, and which hasn't been looked
127 at in over six months?  That is a good candidate list for deletion, when
128 you go to clean up your hard drive.  But have you ever tried asking your
129 computer for such a list?  There is no way to do it!  At least, not
130 without using a command shell.
132 The role of a command shell is to give you more control over what your
133 computer does for you.  Not everyone needs this amount of control, and
134 it does come at a cost: Learning the necessary script commands to
135 express what you want done.  A complicated query, such as the example
136 above, takes time to learn.  But if you find yourself using your
137 computer frequently enough, it is more than worthwhile in the long run.
138 Any tool you use often deserves the time spent learning to master it.
139 @footnote{For the understandably curious, here is what that command
140 looks like: But don't let it fool you; once you know what's going on,
141 it's easier than it looks: @code{ls -lt **/*.doc(Lk+50aM+5)}.}
143 @section What Eshell is not
144 @cindex Eshell, what it is not
145 @cindex what Eshell is not
146 @cindex what isn't Eshell?
148 Eshell is @emph{not} a replacement for system shells such as
149 @command{bash} or @command{zsh}.  Use Eshell when you want to move
150 text between Emacs and external processes; if you only want to pipe
151 output from one external process to another (and then another, and so
152 on), use a system shell, because Emacs's IO system is buffer oriented,
153 not stream oriented, and is very inefficient at such tasks.  If you
154 want to write shell scripts in Eshell, don't; either write an elisp
155 library or use a system shell.
157 Some things Eshell just doesn't do well.  It fills the niche between
158 IELM and your system shell, where the peculiar use-cases lie, and it
159 is less than ideal outside that niche.
161 @menu
162 * Contributors to Eshell::      People who have helped out!
163 @end menu
165 @node Contributors to Eshell
166 @section Contributors to Eshell
167 @cindex contributors
168 @cindex authors
170 Contributions to Eshell are welcome.  I have limited time to work on
171 this project, but I will gladly add any code you contribute to me to
172 this package.
174 The following persons have made contributions to Eshell.
176 @itemize @bullet
177 @item
178 Eli Zaretskii made it possible for Eshell to run without requiring
179 asynchronous subprocess support.  This is important for MS-DOS, which
180 does not have such support.
182 @item
183 Miles Bader contributed many fixes during the port to Emacs 21.
185 @item
186 Stefan Monnier fixed the things which bothered him, which of course made
187 things better for all.
189 @item
190 Gerd Moellmann also helped to contribute bug fixes during the initial
191 integration with Emacs 21.
193 @item
194 Alex Schroeder contributed code for interactively querying the user
195 before overwriting files.
197 @item
198 Sudish Joseph helped with some XEmacs compatibility issues.
199 @end itemize
201 Apart from these, a lot of people have sent suggestions, ideas,
202 requests, bug reports and encouragement.  Thanks a lot!  Without you
203 there would be no new releases of Eshell.
205 @node Commands
206 @chapter Commands
208 In a command shell, everything is done by invoking commands.  This
209 chapter covers command invocations in Eshell, including the command
210 history and invoking commands in a script file.
212 @menu
213 * Invocation::
214 * Arguments::
215 * Built-ins::
216 * Variables::
217 * Aliases::
218 * History::
219 * Completion::
220 * for loop::
221 * Scripts::
222 @end menu
224 @node Invocation
225 @section Invocation
226 Unlike regular system shells, Eshell never invokes kernel functions
227 directly, such as @code{exec(3)}.  Instead, it uses the Lisp functions
228 available in the Emacs Lisp library.  It does this by transforming the
229 input line into a callable Lisp form.@footnote{To see the Lisp form that will be invoked, type: @samp{eshell-parse-command "echo hello"}}
231 The command can be either an Elisp function or an external command.
232 Eshell looks first for an @ref{Aliases, alias} with the same name as the
233 command, then a @ref{Built-ins, built-in command} or a function with the
234 same name; if there is no match, it then tries to execute it as an
235 external command.
237 The semicolon (@code{;}) can be used to separate multiple command
238 invocations on a single line.  A command invocation followed by an
239 ampersand (@code{&}) will be run in the background.  Eshell has no job
240 control, so you can not suspend or background the current process, or
241 bring a background process into the foreground.  That said, background
242 processes invoked from Eshell can be controlled the same way as any
243 other background process in Emacs.
245 @node Arguments
246 @section Arguments
247 Command arguments are passed to the functions as either strings or
248 numbers, depending on what the parser thinks they look like.  If you
249 need to use a function that takes some other data type, you will need to
250 call it in an Elisp expression (which can also be used with
251 @ref{Expansion, expansions}).  As with other shells, you can
252 escape special characters and spaces with the backslash (@code{\}) and
253 the single (@code{''}) and double (@code{""}) quotes.
255 @node Built-ins
257 @section Built-in commands
258 Several commands are built-in in Eshell.  In order to call the
259 external variant of a built-in command @code{foo}, you could call
260 @code{*foo}.  Usually, this should not be necessary.  You can check
261 what will be applied by the @code{which} command:
263 @example
264 ~ $ which ls
265 eshell/ls is a compiled Lisp function in `em-ls.el'
266 ~ $ which *ls
267 /bin/ls
268 @end example
270 If you want to discard a given built-in command, you could declare an
271 alias, @ref{Aliases}.  Example:
273 @example
274 ~ $ which sudo
275 eshell/sudo is a compiled Lisp function in `em-unix.el'
276 ~ $ alias sudo '*sudo $*'
277 ~ $ which sudo
278 sudo is an alias, defined as "*sudo $*"
279 @end example
281 @vindex eshell-prefer-lisp-functions
282 If you would prefer to use the built-in commands instead of the external
283 commands, set @code{eshell-prefer-lisp-functions} to @code{t}.
285 Some of the built-in commands have different behavior from their
286 external counterparts, and some have no external counterpart.  Most of
287 these will print a usage message when given the @code{--help} option.
289 @table @code
291 @item addpath
292 @cmindex addpath
293 Adds a given path or set of paths to the PATH environment variable, or,
294 with no arguments, prints the current paths in this variable.
296 @item alias
297 @cmindex alias
298 Define an alias (@pxref{Aliases}).  This does not add it to the aliases
299 file.
301 @item date
302 @cmindex date
303 Similar to, but slightly different from, the GNU Coreutils
304 @command{date} command.
306 @item define
307 @cmindex define
308 Define a varalias.
309 @xref{Variable Aliases, , , elisp, The Emacs Lisp Reference Manual}.
311 @item diff
312 @cmindex diff
313 Use Emacs's internal @code{diff} (not to be confused with
314 @code{ediff}).  @xref{Comparing Files, , , emacs, The GNU Emacs Manual}.
316 @item grep
317 @cmindex grep
318 @itemx agrep
319 @cmindex agrep
320 @itemx egrep
321 @cmindex egrep
322 @itemx fgrep
323 @cmindex fgrep
324 @itemx glimpse
325 @cmindex glimpse
326 The @command{grep} commands are compatible with GNU @command{grep}, but
327 use Emacs's internal @code{grep} instead.
329 @item info
330 @cmindex info
331 Same as the external @command{info} command, but uses Emacs's internal
332 Info reader.
334 @item jobs
335 @cmindex jobs
336 List subprocesses of the Emacs process, if any, using the function
337 @code{list-processes}.
339 @item kill
340 @cmindex kill
341 Kill processes.  Takes a PID or a process object and an optional
342 signal specifier.
344 @item listify
345 @cmindex listify
346 Eshell version of @code{list}.  Allows you to create a list using Eshell
347 syntax, rather than Elisp syntax.  For example, @samp{listify foo bar}
348 and @code{("foo" "bar")} both evaluate to @code{("foo" "bar")}.
350 @item locate
351 @cmindex locate
352 Alias to Emacs's @code{locate} function, which simply runs the external
353 @command{locate} command and parses the results.
354 @xref{Dired and Find, , , emacs, The GNU Emacs Manual}.
356 @item make
357 @cmindex make
358 Run @command{make} through @code{compile}.
359 @xref{Compilation, , , emacs, The GNU Emacs Manual}.
361 @item occur
362 @cmindex occur
363 Alias to Emacs's @code{occur}.
364 @xref{Other Repeating Search, , , emacs, The GNU Emacs Manual}.
366 @item printnl
367 @cmindex printnl
368 Print the arguments separated by newlines.
370 @item cd
371 @cmindex cd
372 This command changes the current working directory.  Usually, it is
373 invoked as @samp{cd foo} where @file{foo} is the new working directory.
374 But @command{cd} knows about a few special arguments:
376 When it receives no argument at all, it changes to the home directory.
378 Giving the command @samp{cd -} changes back to the previous working
379 directory (this is the same as @samp{cd $-}).
381 The command @samp{cd =} shows the directory stack.  Each line is
382 numbered.
384 With @samp{cd =foo}, Eshell searches the directory stack for a directory
385 matching the regular expression @samp{foo} and changes to that
386 directory.
388 With @samp{cd -42}, you can access the directory stack by number.
390 @item su
391 @cmindex su
392 @itemx sudo
393 @cmindex sudo
394 Uses TRAMP's @command{su} or @command{sudo} method @pxref{Inline methods, , , tramp}
395 to run a command via @command{su} or @command{sudo}.  These commands
396 are in the eshell-tramp module, which is disabled by default.
398 @end table
400 @subsection Built-in variables
401 Eshell knows a few built-in variables:
403 @table @code
405 @item $+
406 @vindex $+
407 This variable always contains the current working directory.
409 @item $-
410 @vindex $-
411 This variable always contains the previous working directory (the
412 current working directory from before the last @code{cd} command).
414 @item $_
415 @vindex $_
416 It refers to the last argument of the last command.
418 @item $$
419 @vindex $$
420 This is the result of the last command.  In case of an external
421 command, it is @code{t} or @code{nil}.
423 @item $?
424 @vindex $?
425 This variable contains the exit code of the last command (0 or 1 for
426 Lisp functions, based on successful completion).
428 @end table
430 @node Variables
431 @section Variables
432 Since Eshell is just an Emacs REPL@footnote{Read-Eval-Print Loop}, it
433 does not have its own scope, and simply stores variables the same you
434 would in an Elisp program.  Eshell provides a command version of
435 @code{setq} for convenience.
437 @node Aliases
438 @section Aliases
440 Aliases are commands that expand to a longer input line.  For example,
441 @command{ll} is a common alias for @code{ls -l}, and would be defined
442 with the command invocation @samp{alias ll ls -l}; with this defined,
443 running @samp{ll foo} in Eshell will actually run @samp{ls -l foo}.
444 Aliases defined (or deleted) by the @command{alias} command are
445 automatically written to the file named by @code{eshell-aliases-file},
446 which you can also edit directly (although you will have to manually
447 reload it).
449 @node History
450 @section History
451 @cmindex history
452 The @samp{history} command shows all commands kept in the history ring
453 as numbered list.  If the history ring contains
454 @code{eshell-history-size} commands, those numbers change after every
455 command invocation, therefore the @samp{history} command shall be
456 applied before using the expansion mechanism with history numbers.
458 The n-th entry of the history ring can be applied with the @samp{!n}
459 command.  If @code{n} is negative, the entry is counted from the end
460 of the history ring.
462 @samp{!foo} expands to the last command beginning with @code{foo}, and
463 @samp{!?foo} to the last command containing @code{foo}.  The n-th
464 argument of the last command beginning with @code{foo} is accessible
465 by @code{!foo:n}.
467 The history ring is loaded from a file at the start of every session,
468 and written back to the file at the end of every session.  The file path
469 is specified in @code{eshell-history-file-name}.  Unlike other shells,
470 such as Bash, Eshell can not be configured to keep a history ring of a
471 different size than that of the history file.
473 Since the default buffer navigation and searching key-bindings are
474 still present in the Eshell buffer, the commands for history
475 navigation and searching are bound to different keys:
477 @table @kbd
478 @item M-r
479 @itemx M-s
480 History I-search.
482 @item M-p
483 @itemx M-n
484 Previous and next history line.  If there is anything on the input
485 line when you run these commands, they will instead jump to the
486 precious or next line that begins with that string.
487 @end table
489 @node Completion
490 @section Completion
491 Eshell uses the pcomplete package for programmable completion, similar
492 to that of other command shells.  Argument completion differs depending
493 on the preceding command: for example, possible completions for
494 @command{rmdir} are only directories, while @command{rm} completions can
495 be directories @emph{and} files.  Eshell provides predefined completions
496 for the built-in functions and some common external commands, and you
497 can define your own for any command.
499 Eshell completion also works for lisp forms and glob patterns. If the
500 point is on a lisp form, then @key{TAB} will behave similarly to completion
501 in @code{elisp-mode} and @code{lisp-interaction-mode}.  For glob
502 patterns, If there are few enough possible completions of the patterns,
503 they will be cycled when @key{TAB} is pressed, otherwise it will be removed
504 from the input line and the possible completions will be listed.
506 If you want to see the entire list of possible completions when it's
507 below the cycling threshold, press @kbd{M-?}.
509 @subsection pcomplete
510 Pcomplete, short for programmable completion, is the completion
511 library originally written for Eshell, but usable for command
512 completion@footnote{Command completion as opposed to code completion,
513 which is a beyond the scope of pcomplete.}  in other modes.
515 Completions are defined as functions (with @code{defun}) named
516 @code{pcomplete/COMMAND}, where @code{COMMAND} is the name of the
517 command for which this function provides completions; you can also name
518 the function @code{pcomplete/MAJOR-MODE/COMMAND} to define completions
519 for a specific major mode.
521 @node for loop
522 @section @code{for} loop
523 Because Eshell commands can not (easily) be combined with lisp forms,
524 Eshell provides a command-oriented @command{for}-loop for convenience.
525 The syntax is as follows:
527 @example
528 @code{for VAR in TOKENS @{ command invocation(s) @}}
529 @end example
531 where @samp{TOKENS} is a space-separated sequence of values of
532 @var{VAR} for each iteration.  This can even be the output of a
533 command if @samp{TOKENS} is replaced with @samp{@{ command invocation @}}.
535 @node Scripts
536 @section Scripts
537 @cmindex source
538 @fnindex eshell-source-file
539 You can run Eshell scripts much like scripts for other shells; the main
540 difference is that since Eshell is not a system command, you have to run
541 it from within Emacs.  An Eshell script is simply a file containing a
542 sequence of commands, as with almost any other shell script.  Scripts
543 are invoked from Eshell with @command{source}, or from anywhere in Emacs
544 with @code{eshell-source-file}.
546 @cmindex .
547 If you wish to load a script into your @emph{current} environment,
548 rather than in a subshell, use the @code{.} command.
550 @node Expansion
551 @chapter Expansion
552 Expansion in a command shell is somewhat like macro expansion in macro
553 parsers (such as @command{cpp} and @command{m4}), but in a command
554 shell, they are less often used for constants, and usually for using
555 variables and string manipulation.@footnote{Eshell has no
556 string-manipulation expansions because the Elisp library already
557 provides many functions for this.}  For example, @code{$var} on a line
558 expands to the value of the variable @code{var} when the line is
559 executed.  Expansions are usually passed as arguments, but may also be
560 used as commands.@footnote{E.g., entering just @samp{$var} at the prompt
561 is equivalent to entering the value of @code{var} at the prompt.}
563 @menu
564 * Dollars Expansion::
565 * Globbing::
566 @end menu
568 @node Dollars Expansion
569 @section Dollars Expansion
570 Eshell has different @code{$} expansion syntax from other shells.  There
571 are some similarities, but don't let these lull you into a false sense
572 of familiarity.
574 @table @code
576 @item $var
577 Expands to the value bound to @code{var}.  This is the main way to use
578 variables in command invocations.
580 @item $#var
581 Expands to the length of the value bound to @code{var}.  Raises an error
582 if the value is not a sequence
583 (@pxref{Sequences Arrays Vectors, Sequences, , elisp, The Emacs Lisp Reference Manual}).
585 @item $(lisp)
586 Expands to the result of evaluating the S-expression @code{(lisp)}.  On
587 its own, this is identical to just @code{(lisp)}, but with the @code{$},
588 it can be used in a string, such as @samp{/some/path/$(lisp).txt}.
590 @item $@{command@}
591 Returns the output of @command{command}, which can be any valid Eshell
592 command invocation, and may even contain expansions.
594 @item $var[i]
595 Expands to the @code{i}th element of the value bound to @code{var}.  If
596 the value is a string, it will be split at whitespace to make it a list.
597 Again, raises an error if the value is not a sequence.
599 @item $var[: i]
600 As above, but now splitting occurs at the colon character.
602 @item $var[: i j]
603 As above, but instead of returning just a string, it now returns a list
604 of two strings.  If the result is being interpolated into a larger
605 string, this list will be flattened into one big string, with each
606 element separated by a space.
608 @item $var["\\\\" i]
609 Separate on backslash characters.  Actually, the first argument -- if it
610 doesn't have the form of a number, or a plain variable name -- can be
611 any regular expression.  So to split on numbers, use @samp{$var["[0-9]+" 10 20]}.
613 @item $var[hello]
614 Calls @code{assoc} on @code{var} with @code{"hello"}, expecting it to be
615 an alist (@pxref{Association List Type, Association Lists, , elisp,
616 The Emacs Lisp Reference Manual}).
618 @item $#var[hello]
619 Returns the length of the cdr of the element of @code{var} who car is equal
620 to @code{"hello"}.
622 @end table
624 @node Globbing
625 @section Globbing
626 Eshell's globbing syntax is very similar to that of Zsh.  Users coming
627 from Bash can still use Bash-style globbing, as there are no
628 incompatibilities.  Most globbing is pattern-based expansion, but there
629 is also predicate-based expansion.  See
630 @ref{Filename Generation, , , zsh, The Z Shell Manual}
631 for full syntax.  To customize the syntax and behavior of globbing in
632 Eshell see the Customize@footnote{@xref{Easy Customization, , , emacs,
633 The GNU Emacs Manual}.}
634 groups ``eshell-glob'' and ``eshell-pred''.
636 @node Input/Output
637 @chapter Input/Output
638 Since Eshell does not communicate with a terminal like most command
639 shells, IO is a little different.
641 @section Visual Commands
642 If you try to run programs from within Eshell that are not
643 line-oriented, such as programs that use ncurses, you will just get
644 garbage output, since the Eshell buffer is not a terminal emulator.
645 Eshell solves this problem by running such programs in Emacs's
646 terminal emulator.
648 Programs that need a terminal to display output properly are referred
649 to in this manual as ``visual commands,'' because they are not simply
650 line-oriented.  You must tell Eshell which commands are visual, by
651 adding them to @code{eshell-visual-commands}; for commands that are
652 visual for only certain @emph{sub}-commands -- e.g. @samp{git log} but
653 not @samp{git status} -- use @code{eshell-visual-subcommands}; and for
654 commands that are visual only when passed certain options, use
655 @code{eshell-visual-options}.
657 @section Redirection
658 Redirection is mostly the same in Eshell as it is in other command
659 shells.  The output redirection operators @code{>} and @code{>>} as
660 well as pipes are supported, but there is not yet any support for
661 input redirection.  Output can also be redirected to buffers, using
662 the @code{>>>} redirection operator, and Elisp functions, using
663 virtual devices.
665 The buffer redirection operator, @code{>>>}, expects a buffer object
666 on the right-hand side, into which it inserts the output of the
667 left-hand side.  e.g., @samp{echo hello >>> #<buffer *scratch*>}
668 inserts the string @code{"hello"} into the @file{*scratch*} buffer.
670 @code{eshell-virtual-targets} is a list of mappings of virtual device
671 names to functions.  Eshell comes with two virtual devices:
672 @file{/dev/kill}, which sends the text to the kill ring, and
673 @file{/dev/clip}, which sends text to the clipboard.
675 You can, of course, define your own virtual targets.  They are defined
676 by adding a list of the form @samp{("/dev/name" @var{function} @var{mode})} to
677 @code{eshell-virtual-targets}.  The first element is the device name;
678 @var{function} may be either a lambda or a function name.  If
679 @var{mode} is @code{nil}, then the function is the output function; if it is
680 non-@code{nil}, then the function is passed the redirection mode as a
681 symbol--@code{overwrite} for @code{>}, @code{append} for @code{>>}, or
682 @code{insert} for @code{>>>}--and the function is expected to return
683 the output function.
685 The output function is called once on each line of output until
686 @code{nil} is passed, indicating end of output.
688 @node Extension modules
689 @chapter Extension modules
690 Eshell provides a facility for defining extension modules so that they
691 can be disabled and enabled without having to unload and reload them,
692 and to provide a common parent Customize group for the
693 modules.@footnote{ERC provides a similar module facility.}  An Eshell
694 module is defined the same as any other library but one requirement: the
695 module must define a Customize@footnote{@xref{Customization, , ,
696 elisp, The Emacs Lisp Reference Manual}.}
697 group using @code{eshell-defgroup} (in place of @code{defgroup}) with
698 @code{eshell-module} as the parent group.@footnote{If the module has
699 no user-customizable options, then there is no need to define it as an
700 Eshell module.}  You also need to load the following as shown:
702 @example
703 (eval-when-compile
704   (require 'cl-lib)
705   (require 'esh-mode)
706   (require 'eshell))
708 (require 'esh-util)
709 @end example
711 @menu
712 * Writing a module::
713 * Module testing::
714 * Directory handling::
715 * Key rebinding::
716 * Smart scrolling::
717 * Terminal emulation::
718 @end menu
720 @node Writing a module
721 @section Writing a module
723 @node Module testing
724 @section Module testing
726 @node Directory handling
727 @section Directory handling
729 @node Key rebinding
730 @section Key rebinding
732 @node Smart scrolling
733 @section Smart scrolling
735 @node Terminal emulation
736 @section Terminal emulation
738 @node Bugs and ideas
739 @chapter Bugs and ideas
740 @cindex reporting bugs and ideas
741 @cindex bugs, how to report them
742 @cindex author, how to reach
743 @cindex email to the author
744 @cindex FAQ
745 @cindex problems, list of common
746 @cindex known bugs
747 @cindex bugs, known
749 If you find a bug or misfeature, don't hesitate to report it, by
750 using @kbd{M-x report-emacs-bug}.  The same applies to feature requests.
751 It is best to discuss one thing at a time.  If you find several
752 unrelated bugs, please report them separately.
754 @ignore
755 If you have ideas for improvements, or if you have written some
756 extensions to this package, I would like to hear from you.  I hope you
757 find this package useful!
758 @end ignore
760 Below is a list of some known problems with Eshell version 2.4.2,
761 which is the version included with Emacs 22.
763 @table @asis
764 @item Documentation incomplete
766 @item Differentiate between aliases and functions
768 Allow for a Bash-compatible syntax, such as:
770 @example
771 alias arg=blah
772 function arg () @{ blah $* @}
773 @end example
775 @item @samp{for i in 1 2 3 @{ grep -q a b && *echo has it @} | wc -l} outputs result after prompt
777 In fact, piping to a process from a looping construct doesn't work in
778 general.  If I change the call to @code{eshell-copy-handles} in
779 @code{eshell-rewrite-for-command} to use @code{eshell-protect}, it seems
780 to work, but the output occurs after the prompt is displayed.  The whole
781 structured command thing is too complicated at present.
783 @item Error with @command{bc} in @code{eshell-test}
785 On some XEmacs system, the subprocess interaction test fails
786 inexplicably, although @command{bc} works fine at the command prompt.
788 @item Eshell does not delete @file{*Help*} buffers in XEmacs 21.1.8+
790 In XEmacs 21.1.8, the @file{*Help*} buffer has been renamed such that
791 multiple instances of the @file{*Help*} buffer can exist.
793 @item Pcomplete sometimes gets stuck
795 You press @key{TAB}, but no completions appear, even though the
796 directory has matching files.  This behavior is rare.
798 @item @samp{grep python $<rpm -qa>} doesn't work, but using @samp{*grep} does
800 This happens because the @code{grep} Lisp function returns immediately,
801 and then the asynchronous @command{grep} process expects to examine the
802 temporary file, which has since been deleted.
804 @item Problem with C-r repeating text
806 If the text @emph{before point} reads "./run", and you type @kbd{C-r r u
807 n}, it will repeat the line for every character typed.
809 @item Backspace doesn't scroll back after continuing (in smart mode)
811 Hitting space during a process invocation, such as @command{make}, will
812 cause it to track the bottom of the output; but backspace no longer
813 scrolls back.
815 @item It's not possible to fully @code{unload-feature} Eshell
817 @item Menu support was removed, but never put back
819 @item Using C-p and C-n with rebind gets into a locked state
821 This happened a few times in Emacs 21, but has been irreproducible
822 since.
824 @item If an interactive process is currently running, @kbd{M-!} doesn't work
826 @item Use a timer instead of @code{sleep-for} when killing child processes
828 @item Piping to a Lisp function is not supported
830 Make it so that the Lisp command on the right of the pipe is repeatedly
831 called with the input strings as arguments.  This will require changing
832 @code{eshell-do-pipeline} to handle non-process targets.
834 @item Input redirection is not supported
836 See the above entry.
838 @item Problem running @command{less} without arguments on Windows
840 The result in the Eshell buffer is:
842 @example
843 Spawning child process: invalid argument
844 @end example
846 Also a new @command{less} buffer was created with nothing in it@dots{}
847 (presumably this holds the output of @command{less}).
849 If @command{less.exe} is invoked from the Eshell command line, the
850 expected output is written to the buffer.
852 Note that this happens on NT-Emacs 20.6.1 on Windows 2000. The term.el
853 package and the supplied shell both use the @command{cmdproxy} program
854 for running shells.
856 @item Implement @samp{-r}, @samp{-n} and @samp{-s} switches for @command{cp}
858 @item Make @kbd{M-5 M-x eshell} switch to ``*eshell<5>*'', creating if need be
860 @item @samp{mv @var{dir} @var{file}.tar} does not remove directories
862 This is because the tar option --remove-files doesn't do so.  Should it
863 be Eshell's job?
865 @item Bind @code{standard-output} and @code{standard-error}
867 This would be so that if a Lisp function calls @code{print}, everything
868 will happen as it should (albeit slowly).
870 @item When an extension module fails to load, @samp{cd /} gives a Lisp error
872 @item If a globbing pattern returns one match, should it be a list?
874 @item Make sure syntax table is correct in Eshell mode
876 So that @kbd{M-DEL} acts in a predictable manner, etc.
878 @item Allow all Eshell buffers to share the same history and list-dir
880 @item There is a problem with script commands that output to @file{/dev/null}
882 If a script file, somewhere in the middle, uses @samp{> /dev/null},
883 output from all subsequent commands is swallowed.
885 @item Split up parsing of text after @samp{$} in @file{esh-var.el}
887 Make it similar to the way that @file{esh-arg.el} is structured.
888 Then add parsing of @samp{$[?\n]}.
890 @item After pressing @kbd{M-RET}, redisplay before running the next command
892 @item Argument predicates and modifiers should work anywhere in a path
894 @example
895 /usr/local/src/editors/vim $ vi **/CVS(/)/Root(.)
896 Invalid regexp: "Unmatched ( or \\("
897 @end example
899 With @command{zsh}, the glob above expands to all files named
900 @file{Root} in directories named @file{CVS}.
902 @item Typing @samp{echo $@{locate locate@}/bin<TAB>} results in a Lisp error
904 Perhaps it should interpolate all permutations, and make that the
905 globbing result, since otherwise hitting return here will result in
906 ``(list of filenames)/bin'', which is never valuable.  Thus, one could
907 @command{cat} only C backup files by using @samp{ls $@{identity *.c@}~}.
908 In that case, having an alias command name @command{glob} for
909 @command{identity} would be useful.
911 @item Once symbolic mode is supported for @command{umask}, implement @command{chmod} in Lisp
913 @item Create @code{eshell-expand-file-name}
915 This would use a data table to transform things such as @samp{~+},
916 @samp{...}, etc.
918 @item Abstract @file{em-smart.el} into @file{smart-scroll.el}
920 It only really needs: to be hooked onto the output filter and the
921 pre-command hook, and to have the input-end and input-start markers.
922 And to know whether the last output group was ``successful.''
924 @item Allow for fully persisting the state of Eshell
926 This would include: variables, history, buffer, input, dir stack, etc.
928 @item Implement D as an argument predicate
930 It means that files beginning with a dot should be included in the
931 glob match.
933 @item A comma in a predicate list should mean OR
935 At the moment, this is not supported.
937 @item Error if a glob doesn't expand due to a predicate
939 An error should be generated only if @code{eshell-error-if-no-glob} is
940 non-@code{nil}.
942 @item @samp{(+ RET SPC TAB} does not cause @code{indent-according-to-mode} to occur
944 @item Create @code{eshell-auto-accumulate-list}
946 This is a list of commands for which, if the user presses @kbd{RET}, the
947 text is staged as the next Eshell command, rather than being sent to the
948 current interactive process.
950 @item Display file and line number if an error occurs in a script
952 @item @command{wait} doesn't work with process ids at the moment
954 @item Enable the direct-to-process input code in @file{em-term.el}
956 @item Problem with repeating @samp{echo $@{find /tmp@}}
958 With smart display active, if @kbd{RET} is held down, after a while it
959 can't keep up anymore and starts outputting blank lines.  It only
960 happens if an asynchronous process is involved@dots{}
962 I think the problem is that @code{eshell-send-input} is resetting the
963 input target location, so that if the asynchronous process is not done
964 by the time the next @kbd{RET} is received, the input processor thinks
965 that the input is meant for the process; which, when smart display is
966 enabled, will be the text of the last command line!  That is a bug in
967 itself.
969 In holding down @kbd{RET} while an asynchronous process is running,
970 there will be a point in between termination of the process, and the
971 running of @code{eshell-post-command-hook}, which would cause
972 @code{eshell-send-input} to call @code{eshell-copy-old-input}, and then
973 process that text as a command to be run after the process.  Perhaps
974 there should be a way of killing pending input between the death of the
975 process, and the @code{post-command-hook}.
977 @item Allow for a more aggressive smart display mode
979 Perhaps toggled by a command, that makes each output block a smart
980 display block.
982 @item Create more meta variables
984 @table @samp
985 @item $!
986 The reason for the failure of the last disk command, or the text of the
987 last Lisp error.
989 @item $=
990 A special associate array, which can take references of the form
991 @samp{$=[REGEXP]}.  It indexes into the directory ring.
992 @end table
994 @item Eshell scripts can't execute in the background
996 @item Support zsh's ``Parameter Expansion'' syntax, i.e., @samp{$@{@var{name}:-@var{val}@}}
998 @item Write an @command{info} alias that can take arguments
1000 So that the user can enter @samp{info chmod}, for example.
1002 @item Create a mode @code{eshell-browse}
1004 It would treat the Eshell buffer as a outline.  Collapsing the outline
1005 hides all of the output text.  Collapsing again would show only the
1006 first command run in each directory
1008 @item Allow other revisions of a file to be referenced using @samp{file@{rev@}}
1010 This would be expanded by @code{eshell-expand-file-name} (see above).
1012 @item Print ``You have new mail'' when the ``Mail'' icon is turned on
1014 @item Implement @kbd{M-|} for Eshell
1016 @item Implement input redirection
1018 If it's a Lisp function, input redirection implies @command{xargs} (in a
1019 way@dots{}).  If input redirection is added, also update the
1020 @code{file-name-quote-list}, and the delimiter list.
1022 @item Allow @samp{#<@var{word} @var{arg}>} as a generic syntax
1024 With the handling of @emph{word} specified by an
1025 @code{eshell-special-alist}.
1027 @item In @code{eshell-eval-using-options}, allow a @code{:complete} tag
1029 It would be used to provide completion rules for that command.  Then the
1030 macro will automagically define the completion function.
1032 @item For @code{eshell-command-on-region}, apply redirections to the result
1034 So that @samp{+ > 'blah} would cause the result of the @code{+} (using
1035 input from the current region) to be inserting into the symbol
1036 @code{blah}.
1038 If an external command is being invoked, the input is sent as standard
1039 input, as if a @samp{cat <region> |} had been invoked.
1041 If a Lisp command, or an alias, is invoked, then if the line has no
1042 newline characters, it is divided by whitespace and passed as arguments
1043 to the Lisp function.  Otherwise, it is divided at the newline
1044 characters.  Thus, invoking @code{+} on a series of numbers will add
1045 them; @code{min} would display the smallest figure, etc.
1047 @item Write @code{eshell-script-mode} as a minor mode
1049 It would provide syntax, abbrev, highlighting and indenting support like
1050 @code{emacs-lisp-mode} and @code{shell-mode}.
1052 @item In the history mechanism, finish the Bash-style support
1054 This means @samp{!n}, @samp{!#}, @samp{!:%}, and @samp{!:1-} as separate
1055 from @samp{!:1*}.
1057 @item Support the -n command line option for @command{history}
1059 @item Implement @command{fc} in Lisp
1061 @item Specifying a frame as a redirection target should imply the currently active window's buffer
1063 @item Implement @samp{>@var{func-or-func-list}}
1065 This would allow for an ``output translators'', that take a function to
1066 modify output with, and a target.  Devise a syntax that works well with
1067 pipes, and can accommodate multiple functions (i.e., @samp{>'(upcase
1068 regexp-quote)} or @samp{>'upcase}).
1070 @item Allow Eshell to read/write to/from standard input and output
1072 This would be optional, rather than always using the Eshell buffer.
1073 This would allow it to be run from the command line (perhaps).
1075 @item Write a @command{help} command
1077 It would call subcommands with @option{--help}, or @option{-h} or
1078 @option{/?}, as appropriate.
1080 @item Implement @command{stty} in Lisp
1082 @item Support @command{rc}'s matching operator, e.g., @samp{~ (@var{list}) @var{regexp}}
1084 @item Implement @command{bg} and @command{fg} as editors of @code{eshell-process-list}
1086 Using @command{bg} on a process that is already in the background does
1087 nothing.  Specifying redirection targets replaces (or adds) to the list
1088 current being used.
1090 @item Have @command{jobs} print only the processes for the current shell
1092 @item How can Eshell learn if a background process has requested input?
1094 @item Support @samp{2>&1} and @samp{>&} and @samp{2>} and @samp{|&}
1096 The syntax table for parsing these should be customizable, such that the
1097 user could change it to use rc syntax: @samp{>[2=1]}.
1099 @item Allow @samp{$_[-1]}, which would indicate the last element of the array
1101 @item Make @samp{$x[*]} equal to listing out the full contents of @samp{x}
1103 Return them as a list, so that @samp{$_[*]} is all the arguments of the
1104 last command.
1106 @item Copy ANSI code handling from @file{term.el} into @file{em-term.el}
1108 Make it possible for the user to send char-by-char to the underlying
1109 process.  Ultimately, I should be able to move away from using term.el
1110 altogether, since everything but the ANSI code handling is already part
1111 of Eshell.  Then, things would work correctly on MS-Windows as well
1112 (which doesn't have @file{/bin/sh}, although @file{term.el} tries to use
1113 it).
1115 @item Make the shell spawning commands be visual
1117 That is, make (@command{su}, @command{bash}, @command{telnet},
1118 @command{rlogin}, @command{rsh}, etc.)@: be part of
1119 @code{eshell-visual-commands}.  The only exception is if the shell is
1120 being used to invoke a single command.  Then, the behavior should be
1121 based on what that command is.
1123 @item Create a smart viewing command named @command{open}
1125 This would search for some way to open its argument (similar to opening
1126 a file in the Windows Explorer).
1128 @item Alias @command{read} to be the same as @command{open}, only read-only
1130 @item Write a @command{tail} command which uses @code{view-file}
1132 It would move point to the end of the buffer, and then turns on
1133 auto-revert mode in that buffer at frequent intervals---and a
1134 @command{head} alias which assumes an upper limit of
1135 @code{eshell-maximum-line-length} characters per line.
1137 @item Make @command{dgrep} load @code{dired}, mark everything, then invoke @code{dired-do-search}
1139 @item Write mesh.c
1141 This would run Emacs with the appropriate arguments to invoke Eshell
1142 only.  That way, it could be listed as a login shell.
1144 @item Use an intangible @code{PS2} string for multi-line input prompts
1146 @item Auto-detect when a command is visual, by checking @code{TERMCAP} usage
1148 @item The first keypress after @kbd{M-x watson} triggers `eshell-send-input'
1150 @item Make @kbd{/} electric
1152 So that it automatically expands and corrects pathnames.  Or make
1153 pathname completion for Pcomplete auto-expand @samp{/u/i/std<TAB>} to
1154 @samp{/usr/include/std<TAB>}.
1156 @item Write the @command{pushd} stack to disk along with @code{last-dir-ring}
1158 @item Add options to @code{eshell/cat} which would allow it to sort and uniq
1160 @item Implement @command{wc} in Lisp
1162 Add support for counting sentences, paragraphs, pages, etc.
1164 @item Once piping is added, implement @command{sort} and @command{uniq} in Lisp
1166 @item Implement @command{touch} in Lisp
1168 @item Implement @command{comm} in Lisp
1170 @item Implement an @command{epatch} command in Lisp
1172 This would call @code{ediff-patch-file}, or @code{ediff-patch-buffer},
1173 depending on its argument.
1175 @item Have an option such that @samp{ls -l} generates a dired buffer
1177 @item Write a version of @command{xargs} based on command rewriting
1179 That is, @samp{find X | xargs Y} would be indicated using @samp{Y
1180 $@{find X@}}.  Maybe @code{eshell-do-pipelines} could be changed to
1181 perform this on-thy-fly rewriting.
1183 @item Write an alias for @command{less} that brings up a @code{view-mode} buffer
1185 Such that the user can press @key{SPC} and @key{DEL}, and then @key{q}
1186 to return to Eshell.  It would be equivalent to:
1187 @samp{X > #<buffer Y>; view-buffer #<buffer Y>}.
1189 @item Make @code{eshell-mode} as much a full citizen as @code{shell-mode}
1191 Everywhere in Emacs where @code{shell-mode} is specially noticed, add
1192 @code{eshell-mode} there.
1194 @item Permit the umask to be selectively set on a @command{cp} target
1196 @item Problem using @kbd{M-x eshell} after using @code{eshell-command}
1198 If the first thing that I do after entering Emacs is to run
1199 @code{eshell-command} and invoke @command{ls}, and then use @kbd{M-x
1200 eshell}, it doesn't display anything.
1202 @item @kbd{M-RET} during a long command (using smart display) doesn't work
1204 Since it keeps the cursor up where the command was invoked.
1206 @end table
1208 @node GNU Free Documentation License
1209 @appendix GNU Free Documentation License
1210 @include doclicense.texi
1212 @node Concept Index
1213 @unnumbered Concept Index
1215 @printindex cp
1217 @node Function and Variable Index
1218 @unnumbered Function and Variable Index
1220 @printindex fn
1222 @node Command Index
1223 @unnumbered Command Index
1225 @printindex cm
1227 @node Key Index
1228 @unnumbered Key Index
1230 @printindex ky
1231 @bye