diff options
| author | Jim Porter | 2022-07-09 10:34:31 -0700 |
|---|---|---|
| committer | Jim Porter | 2022-09-04 15:15:01 -0700 |
| commit | 1be925faa1065af5754fc11914b56ae98dfb2a83 (patch) | |
| tree | 6003dde699588471a1a801705c3ea28bf272ac9f /doc | |
| parent | 5af5ed6c6271a452bf37afa0e7349838960d446a (diff) | |
| download | emacs-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.texi | 160 |
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 | |||
| 260 | As with other shells, you can escape special characters and spaces | 259 | As with other shells, you can escape special characters and spaces |
| 261 | with by prefixing the character with a backslash (@code{\}), or by | 260 | with by prefixing the character with a backslash (@code{\}), or by |
| 262 | surrounding the string with apostrophes (@code{''}) or double quotes | 261 | surrounding the string with apostrophes (@code{''}) or double quotes |
| @@ -268,6 +267,40 @@ When using expansions (@pxref{Expansion}) in an Eshell command, the | |||
| 268 | result may potentially be of any data type. To ensure that the result | 267 | result may potentially be of any data type. To ensure that the result |
| 269 | is always a string, the expansion can be surrounded by double quotes. | 268 | is always a string, the expansion can be surrounded by double quotes. |
| 270 | 269 | ||
| 270 | @subsection Special argument types | ||
| 271 | In addition to strings and numbers, Eshell supports a number of | ||
| 272 | special argument types. These let you refer to various other Emacs | ||
| 273 | Lisp data types, such as lists or buffers. | ||
| 274 | |||
| 275 | @table @code | ||
| 276 | |||
| 277 | @item #'@var{lisp-form} | ||
| 278 | This refers to the quoted Emacs Lisp form @var{lisp-form}. Though | ||
| 279 | this looks similar to the ``sharp quote'' syntax for functions | ||
| 280 | (@pxref{Special Read Syntax, , , elisp, The Emacs Lisp Reference | ||
| 281 | Manual}), it instead corresponds to @code{quote} and can be used for | ||
| 282 | any 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} | ||
| 286 | This refers to the backquoted Emacs Lisp form @var{lisp-form} | ||
| 287 | (@pxref{Backquote, , , elisp, The Emacs Lisp Reference Manual}). As | ||
| 288 | in Emacs Lisp, you can use @samp{,} and @samp{,@@} to refer to | ||
| 289 | non-constant values. | ||
| 290 | |||
| 291 | @item #<buffer @var{name}> | ||
| 292 | @itemx #<@var{name}> | ||
| 293 | Return the buffer named @var{name}. This is equivalent to | ||
| 294 | @samp{$(get-buffer-create "@var{name}")} (@pxref{Creating Buffers, , , | ||
| 295 | elisp, The Emacs Lisp Reference Manual}). | ||
| 296 | |||
| 297 | @item #<process @var{name}> | ||
| 298 | Return the process named @var{name}. This is equivalent to | ||
| 299 | @samp{$(get-process "@var{name}")} (@pxref{Process Information, , , | ||
| 300 | elisp, 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 |
| 273 | Several commands are built-in in Eshell. In order to call the | 306 | Several commands are built-in in Eshell. In order to call the |
| @@ -1560,6 +1593,13 @@ Reverses the order of a list of values. | |||
| 1560 | Since Eshell does not communicate with a terminal like most command | 1593 | Since Eshell does not communicate with a terminal like most command |
| 1561 | shells, IO is a little different. | 1594 | shells, 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 |
| 1564 | If you try to run programs from within Eshell that are not | 1604 | If you try to run programs from within Eshell that are not |
| 1565 | line-oriented, such as programs that use ncurses, you will just get | 1605 | line-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} |
| 1593 | value; the default is @code{nil}. | 1633 | value; the default is @code{nil}. |
| 1594 | 1634 | ||
| 1635 | @node Redirection | ||
| 1595 | @section Redirection | 1636 | @section Redirection |
| 1596 | Redirection is mostly the same in Eshell as it is in other command | 1637 | Redirection in Eshell is similar to that of other command shells. You |
| 1597 | shells. The output redirection operators @code{>} and @code{>>} as | 1638 | can use the output redirection operators @code{>} and @code{>>}, but |
| 1598 | well as pipes are supported, but there is not yet any support for | 1639 | there is not yet any support for input redirection. In the cases |
| 1599 | input redirection. Output can also be redirected to buffers, using | 1640 | below, @var{fd} specifies the file descriptor to redirect; if not |
| 1600 | the @code{>>>} redirection operator, and Elisp functions, using | 1641 | specified, file descriptor 1 (standard output) will be used by |
| 1601 | virtual devices. | 1642 | default. |
| 1602 | 1643 | ||
| 1603 | The buffer redirection operator, @code{>>>}, expects a buffer object | 1644 | @table @code |
| 1604 | on the right-hand side, into which it inserts the output of the | 1645 | |
| 1605 | left-hand side. e.g., @samp{echo hello >>> #<buffer *scratch*>} | 1646 | @item > @var{dest} |
| 1606 | inserts the string @code{"hello"} into the @file{*scratch*} buffer. | 1647 | @itemx @var{fd}> @var{dest} |
| 1607 | The convenience shorthand variant @samp{#<@var{buffer-name}>}, as in | 1648 | Redirect output to @var{dest}, overwriting its contents with the new |
| 1608 | @samp{#<*scratch*>}, is also accepted. | 1649 | output. |
| 1609 | 1650 | ||
| 1610 | @code{eshell-virtual-targets} is a list of mappings of virtual device | 1651 | @item >> @var{dest} |
| 1611 | names 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 | 1653 | Redirect output to @var{dest}, appending it to the existing contents |
| 1613 | @file{/dev/clip}, which sends text to the clipboard. | 1654 | of @var{dest}. |
| 1655 | |||
| 1656 | @item >>> @var{buffer} | ||
| 1657 | @itemx @var{fd}>>> @var{buffer} | ||
| 1658 | Redirect 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 | ||
| 1660 | a file, or otherwise behaving the same as @code{>>}. | ||
| 1661 | |||
| 1662 | @end table | ||
| 1663 | |||
| 1664 | Eshell supports redirecting output to several different types of | ||
| 1665 | targets: | ||
| 1666 | |||
| 1667 | @itemize @bullet | ||
| 1668 | |||
| 1669 | @item | ||
| 1670 | files, including virtual targets (see below); | ||
| 1614 | 1671 | ||
| 1672 | @item | ||
| 1673 | buffers (@pxref{Buffers, , , elisp, GNU Emacs Lisp Reference Manual}); | ||
| 1674 | |||
| 1675 | @item | ||
| 1676 | markers (@pxref{Markers, , , elisp, GNU Emacs Lisp Reference Manual}); | ||
| 1677 | |||
| 1678 | @item | ||
| 1679 | processes (@pxref{Processes, , , elisp, GNU Emacs Lisp Reference | ||
| 1680 | Manual}); and | ||
| 1681 | |||
| 1682 | @item | ||
| 1683 | symbols (@pxref{Symbols, , , elisp, GNU Emacs Lisp Reference Manual}). | ||
| 1684 | |||
| 1685 | @end itemize | ||
| 1686 | |||
| 1687 | @subsection Virtual Targets | ||
| 1688 | Virtual targets are mapping of device names to functions. Eshell | ||
| 1689 | comes with four virtual devices: | ||
| 1690 | |||
| 1691 | @table @file | ||
| 1692 | |||
| 1693 | @item /dev/null | ||
| 1694 | Does nothing with the output passed to it. | ||
| 1695 | |||
| 1696 | @item /dev/eshell | ||
| 1697 | Writes the text passed to it to the display. | ||
| 1698 | |||
| 1699 | @item /dev/kill | ||
| 1700 | Adds the text passed to it to the kill ring. | ||
| 1701 | |||
| 1702 | @item /dev/clip | ||
| 1703 | Adds the text passed to it to the clipboard. | ||
| 1704 | |||
| 1705 | @end table | ||
| 1706 | |||
| 1707 | @vindex eshell-virtual-targets | ||
| 1615 | You can, of course, define your own virtual targets. They are defined | 1708 | You can, of course, define your own virtual targets. They are defined |
| 1616 | by adding a list of the form @samp{("/dev/name" @var{function} @var{mode})} to | 1709 | by 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 | 1711 | the 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 | 1712 | name. If @var{mode} is @code{nil}, then the function is the output |
| 1620 | non-@code{nil}, then the function is passed the redirection mode as a | 1713 | function; if it is non-@code{nil}, then the function is passed the |
| 1621 | symbol--@code{overwrite} for @code{>}, @code{append} for @code{>>}, or | 1714 | redirection 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 |
| 1623 | the output function. | 1716 | function is expected to return the output function. |
| 1624 | 1717 | ||
| 1625 | The output function is called once on each line of output until | 1718 | The 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 | ||
| 1723 | As with most other shells, Eshell supports pipelines to pass the | ||
| 1724 | output of one command the input of the next command. You can pipe | ||
| 1725 | commands to each other using the @code{|} operator. For example, | ||
| 1726 | |||
| 1727 | @example | ||
| 1728 | ~ $ echo hello | rev | ||
| 1729 | olleh | ||
| 1730 | @end example | ||
| 1731 | |||
| 1732 | @subsection Running Shell Pipelines Natively | ||
| 1629 | When constructing shell pipelines that will move a lot of data, it is | 1733 | When constructing shell pipelines that will move a lot of data, it is |
| 1630 | a good idea to bypass Eshell's own pipelining support and use the | 1734 | a good idea to bypass Eshell's own pipelining support and use the |
| 1631 | operating system shell's instead. This is especially relevant when | 1735 | operating system shell's instead. This is especially relevant when |