aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorJim Porter2022-07-09 10:34:31 -0700
committerJim Porter2022-09-04 15:15:01 -0700
commit1be925faa1065af5754fc11914b56ae98dfb2a83 (patch)
tree6003dde699588471a1a801705c3ea28bf272ac9f /doc
parent5af5ed6c6271a452bf37afa0e7349838960d446a (diff)
downloademacs-1be925faa1065af5754fc11914b56ae98dfb2a83.tar.gz
emacs-1be925faa1065af5754fc11914b56ae98dfb2a83.zip
Simplify Eshell handle functions and add tests/documentation
* lisp/eshell/esh-arg.el (eshell-parse-argument-hook): Explain how to use 'eshell-finish-arg'. * lisp/eshell/esh-io.el (eshell-create-handles): Only call 'eshell-get-target' for stderr if necessary. (eshell-protect-handles): Use 'dotimes'. (eshell-set-output-handle): Pass HANDLES and fix an edge case with setting a duplicate TARGET. * test/lisp/eshell/eshell-tests-helpers.el (eshell-with-temp-buffer): New macro. * test/lisp/eshell/esh-cmd-tests.el (esh-cmd-test/quoted-lisp-form) (esh-cmd-test/backquoted-lisp-form) (esh-cmd-test/backquoted-lisp-form/splice): New tests. * test/lisp/eshell/eshell-tests.el (eshell-test/redirect-buffer) (eshell-test/redirect-buffer-escaped): Move to... * test/lisp/eshell/esh-io-tests.el: ... here, and add other I/O tests. * doc/misc/eshell.texi (Arguments): Add documentation for special argument types. (Input/Output): Expand documentation for redirection and pipelines.
Diffstat (limited to 'doc')
-rw-r--r--doc/misc/eshell.texi160
1 files changed, 132 insertions, 28 deletions
diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi
index 13f13163dd7..0c98d2860e9 100644
--- a/doc/misc/eshell.texi
+++ b/doc/misc/eshell.texi
@@ -256,7 +256,6 @@ as an argument will ``spread'' the elements into multiple arguments:
256@end example 256@end example
257 257
258@subsection Quoting and escaping 258@subsection Quoting and escaping
259
260As with other shells, you can escape special characters and spaces 259As with other shells, you can escape special characters and spaces
261with by prefixing the character with a backslash (@code{\}), or by 260with by prefixing the character with a backslash (@code{\}), or by
262surrounding the string with apostrophes (@code{''}) or double quotes 261surrounding the string with apostrophes (@code{''}) or double quotes
@@ -268,6 +267,40 @@ When using expansions (@pxref{Expansion}) in an Eshell command, the
268result may potentially be of any data type. To ensure that the result 267result may potentially be of any data type. To ensure that the result
269is always a string, the expansion can be surrounded by double quotes. 268is always a string, the expansion can be surrounded by double quotes.
270 269
270@subsection Special argument types
271In addition to strings and numbers, Eshell supports a number of
272special argument types. These let you refer to various other Emacs
273Lisp data types, such as lists or buffers.
274
275@table @code
276
277@item #'@var{lisp-form}
278This refers to the quoted Emacs Lisp form @var{lisp-form}. Though
279this looks similar to the ``sharp quote'' syntax for functions
280(@pxref{Special Read Syntax, , , elisp, The Emacs Lisp Reference
281Manual}), it instead corresponds to @code{quote} and can be used for
282any quoted form.@footnote{Eshell would interpret a bare apostrophe
283(@code{'}) as the start of a single-quoted string.}
284
285@item `@var{lisp-form}
286This refers to the backquoted Emacs Lisp form @var{lisp-form}
287(@pxref{Backquote, , , elisp, The Emacs Lisp Reference Manual}). As
288in Emacs Lisp, you can use @samp{,} and @samp{,@@} to refer to
289non-constant values.
290
291@item #<buffer @var{name}>
292@itemx #<@var{name}>
293Return the buffer named @var{name}. This is equivalent to
294@samp{$(get-buffer-create "@var{name}")} (@pxref{Creating Buffers, , ,
295elisp, The Emacs Lisp Reference Manual}).
296
297@item #<process @var{name}>
298Return the process named @var{name}. This is equivalent to
299@samp{$(get-process "@var{name}")} (@pxref{Process Information, , ,
300elisp, The Emacs Lisp Reference Manual}).
301
302@end table
303
271@node Built-ins 304@node Built-ins
272@section Built-in commands 305@section Built-in commands
273Several commands are built-in in Eshell. In order to call the 306Several commands are built-in in Eshell. In order to call the
@@ -1560,6 +1593,13 @@ Reverses the order of a list of values.
1560Since Eshell does not communicate with a terminal like most command 1593Since Eshell does not communicate with a terminal like most command
1561shells, IO is a little different. 1594shells, IO is a little different.
1562 1595
1596@menu
1597* Visual Commands::
1598* Redirection::
1599* Pipelines::
1600@end menu
1601
1602@node Visual Commands
1563@section Visual Commands 1603@section Visual Commands
1564If you try to run programs from within Eshell that are not 1604If you try to run programs from within Eshell that are not
1565line-oriented, such as programs that use ncurses, you will just get 1605line-oriented, such as programs that use ncurses, you will just get
@@ -1592,40 +1632,104 @@ program exits, customize the variable
1592@code{eshell-destroy-buffer-when-process-dies} to a non-@code{nil} 1632@code{eshell-destroy-buffer-when-process-dies} to a non-@code{nil}
1593value; the default is @code{nil}. 1633value; the default is @code{nil}.
1594 1634
1635@node Redirection
1595@section Redirection 1636@section Redirection
1596Redirection is mostly the same in Eshell as it is in other command 1637Redirection in Eshell is similar to that of other command shells. You
1597shells. The output redirection operators @code{>} and @code{>>} as 1638can use the output redirection operators @code{>} and @code{>>}, but
1598well as pipes are supported, but there is not yet any support for 1639there is not yet any support for input redirection. In the cases
1599input redirection. Output can also be redirected to buffers, using 1640below, @var{fd} specifies the file descriptor to redirect; if not
1600the @code{>>>} redirection operator, and Elisp functions, using 1641specified, file descriptor 1 (standard output) will be used by
1601virtual devices. 1642default.
1602 1643
1603The buffer redirection operator, @code{>>>}, expects a buffer object 1644@table @code
1604on the right-hand side, into which it inserts the output of the 1645
1605left-hand side. e.g., @samp{echo hello >>> #<buffer *scratch*>} 1646@item > @var{dest}
1606inserts the string @code{"hello"} into the @file{*scratch*} buffer. 1647@itemx @var{fd}> @var{dest}
1607The convenience shorthand variant @samp{#<@var{buffer-name}>}, as in 1648Redirect output to @var{dest}, overwriting its contents with the new
1608@samp{#<*scratch*>}, is also accepted. 1649output.
1609 1650
1610@code{eshell-virtual-targets} is a list of mappings of virtual device 1651@item >> @var{dest}
1611names to functions. Eshell comes with two virtual devices: 1652@itemx @var{fd}>> @var{dest}
1612@file{/dev/kill}, which sends the text to the kill ring, and 1653Redirect output to @var{dest}, appending it to the existing contents
1613@file{/dev/clip}, which sends text to the clipboard. 1654of @var{dest}.
1655
1656@item >>> @var{buffer}
1657@itemx @var{fd}>>> @var{buffer}
1658Redirect output to @var{dest}, inserting it at the current mark if
1659@var{dest} is a buffer, at the beginning of the file if @var{dest} is
1660a file, or otherwise behaving the same as @code{>>}.
1661
1662@end table
1663
1664Eshell supports redirecting output to several different types of
1665targets:
1666
1667@itemize @bullet
1668
1669@item
1670files, including virtual targets (see below);
1614 1671
1672@item
1673buffers (@pxref{Buffers, , , elisp, GNU Emacs Lisp Reference Manual});
1674
1675@item
1676markers (@pxref{Markers, , , elisp, GNU Emacs Lisp Reference Manual});
1677
1678@item
1679processes (@pxref{Processes, , , elisp, GNU Emacs Lisp Reference
1680Manual}); and
1681
1682@item
1683symbols (@pxref{Symbols, , , elisp, GNU Emacs Lisp Reference Manual}).
1684
1685@end itemize
1686
1687@subsection Virtual Targets
1688Virtual targets are mapping of device names to functions. Eshell
1689comes with four virtual devices:
1690
1691@table @file
1692
1693@item /dev/null
1694Does nothing with the output passed to it.
1695
1696@item /dev/eshell
1697Writes the text passed to it to the display.
1698
1699@item /dev/kill
1700Adds the text passed to it to the kill ring.
1701
1702@item /dev/clip
1703Adds the text passed to it to the clipboard.
1704
1705@end table
1706
1707@vindex eshell-virtual-targets
1615You can, of course, define your own virtual targets. They are defined 1708You can, of course, define your own virtual targets. They are defined
1616by adding a list of the form @samp{("/dev/name" @var{function} @var{mode})} to 1709by adding a list of the form @samp{("/dev/name" @var{function}
1617@code{eshell-virtual-targets}. The first element is the device name; 1710@var{mode})} to @code{eshell-virtual-targets}. The first element is
1618@var{function} may be either a lambda or a function name. If 1711the device name; @var{function} may be either a lambda or a function
1619@var{mode} is @code{nil}, then the function is the output function; if it is 1712name. If @var{mode} is @code{nil}, then the function is the output
1620non-@code{nil}, then the function is passed the redirection mode as a 1713function; if it is non-@code{nil}, then the function is passed the
1621symbol--@code{overwrite} for @code{>}, @code{append} for @code{>>}, or 1714redirection mode as a symbol--@code{overwrite} for @code{>},
1622@code{insert} for @code{>>>}--and the function is expected to return 1715@code{append} for @code{>>}, or @code{insert} for @code{>>>}--and the
1623the output function. 1716function is expected to return the output function.
1624 1717
1625The output function is called once on each line of output until 1718The output function is called once on each line of output until
1626@code{nil} is passed, indicating end of output. 1719@code{nil} is passed, indicating end of output.
1627 1720
1628@section Running Shell Pipelines Natively 1721@node Pipelines
1722@section Pipelines
1723As with most other shells, Eshell supports pipelines to pass the
1724output of one command the input of the next command. You can pipe
1725commands to each other using the @code{|} operator. For example,
1726
1727@example
1728~ $ echo hello | rev
1729olleh
1730@end example
1731
1732@subsection Running Shell Pipelines Natively
1629When constructing shell pipelines that will move a lot of data, it is 1733When constructing shell pipelines that will move a lot of data, it is
1630a good idea to bypass Eshell's own pipelining support and use the 1734a good idea to bypass Eshell's own pipelining support and use the
1631operating system shell's instead. This is especially relevant when 1735operating system shell's instead. This is especially relevant when