aboutsummaryrefslogtreecommitdiffstats
path: root/doc/misc
diff options
context:
space:
mode:
authorJim Porter2022-11-08 22:49:23 -0800
committerJim Porter2022-12-15 21:41:03 -0800
commite63ef66c57ee74b24998a16b34949f67bbb73d8d (patch)
treed41fe6c0405a02f78f025284a245e1c4735a6a1b /doc/misc
parent66ac920b0c233e472c7f54d108503dfe9236d3c0 (diff)
downloademacs-e63ef66c57ee74b24998a16b34949f67bbb73d8d.tar.gz
emacs-e63ef66c57ee74b24998a16b34949f67bbb73d8d.zip
Add support for the "splice operator" in Eshell
This allows splicing lists in-place in argument lists, which is particularly important when defining aliases using the '$*' special variable (bug#59960). * lisp/eshell/esh-var.el (eshell-parse-variable): Add support for the splice operator. (eshell-interpolate-variable): Let 'eshell-parse-variable' handle adding 'eshell-escape-arg'. (eshell-complete-variable-reference): Handle the splice operator. * lisp/eshell/esh-arg.el (eshell-concat-groups) (eshell-prepare-splice): New functions... (eshell-resolve-current-argument): ... use them. (eshell-splice-args): New function. * lisp/eshell/esh-cmd.el (eshell-rewrite-named-command): Handle 'eshell-splice-args'. * lisp/eshell/esh-util.el (eshell-list-to-string): New function... (eshell-flatten-and-stringify): ... use it. * lisp/eshell/em-cmpl.el (eshell-complete-parse-arguments): Remove 'eshell-splice-args' sigils in Eshell command forms so that we can perform completion on splice-expansions. * lisp/eshell/em-unix.el (eshell-complete-host-reference): Don't try to complete arguments containing "$@". * test/lisp/eshell/esh-var-tets.el (esh-var-test/interp-list-var) (esh-var-test/interp-list-var-concat, esh-var-test/interp-var-splice) (esh-var-test/interp-var-splice-concat) (esh-var-test/quoted-interp-list-var) (esh-var-test/quoted-interp-list-var-concat) (esh-var-test/quoted-interp-var-splice) (esh-var-test/quoted-interp-var-splice-concat): New tests. * test/lisp/eshell/em-alias-tests.el (em-alias-test/alias-all-args-var-splice): New test. * doc/misc/eshell.texi (Dollars Expansion): Explain the splice operator. (Aliases): Expand documentation and use '$@*'. (Built-ins, Bugs and Ideas): Use '$@*' where appropriate. * etc/NEWS: Announce this change.
Diffstat (limited to 'doc/misc')
-rw-r--r--doc/misc/eshell.texi100
1 files changed, 73 insertions, 27 deletions
diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi
index 1383b412ce7..f9796d69a9a 100644
--- a/doc/misc/eshell.texi
+++ b/doc/misc/eshell.texi
@@ -349,9 +349,9 @@ alias (@pxref{Aliases}). Example:
349@example 349@example
350~ $ which sudo 350~ $ which sudo
351eshell/sudo is a compiled Lisp function in `em-tramp.el'. 351eshell/sudo is a compiled Lisp function in `em-tramp.el'.
352~ $ alias sudo '*sudo $*' 352~ $ alias sudo '*sudo $@@*'
353~ $ which sudo 353~ $ which sudo
354sudo is an alias, defined as "*sudo $*" 354sudo is an alias, defined as "*sudo $@@*"
355@end example 355@end example
356 356
357@vindex eshell-prefer-lisp-functions 357@vindex eshell-prefer-lisp-functions
@@ -475,7 +475,7 @@ Manual}.
475 475
476If @code{eshell-plain-diff-behavior} is non-@code{nil}, then this 476If @code{eshell-plain-diff-behavior} is non-@code{nil}, then this
477command does not use Emacs's internal @code{diff}. This is the same 477command does not use Emacs's internal @code{diff}. This is the same
478as using @samp{alias diff '*diff $*'}. 478as using @samp{alias diff '*diff $@@*'}.
479 479
480@item dirname 480@item dirname
481@cmindex dirname 481@cmindex dirname
@@ -545,9 +545,9 @@ but use Emacs's internal @code{grep} instead.
545 545
546If @code{eshell-plain-grep-behavior} is non-@code{nil}, then these 546If @code{eshell-plain-grep-behavior} is non-@code{nil}, then these
547commands do not use Emacs's internal @code{grep}. This is the same as 547commands do not use Emacs's internal @code{grep}. This is the same as
548using @samp{alias grep '*grep $*'}, though this setting applies to all 548using @samp{alias grep '*grep $@@*'}, though this setting applies to
549of the built-in commands for which you would need to create a separate 549all of the built-in commands for which you would need to create a
550alias. 550separate alias.
551 551
552@item history 552@item history
553@cmindex history 553@cmindex history
@@ -603,7 +603,7 @@ Alias to Emacs's @code{locate} function, which simply runs the external
603 603
604If @code{eshell-plain-locate-behavior} is non-@code{nil}, then Emacs's 604If @code{eshell-plain-locate-behavior} is non-@code{nil}, then Emacs's
605internal @code{locate} is not used. This is the same as using 605internal @code{locate} is not used. This is the same as using
606@samp{alias locate '*locate $*'}. 606@samp{alias locate '*locate $@@*'}.
607 607
608@item ls 608@item ls
609@cmindex ls 609@cmindex ls
@@ -1027,25 +1027,47 @@ necessary. Its value is @code{@var{emacs-version},eshell}.
1027@node Aliases 1027@node Aliases
1028@section Aliases 1028@section Aliases
1029 1029
1030@vindex $* 1030@findex eshell-read-aliases-list
1031@findex eshell-expand-history-references
1032Aliases are commands that expand to a longer input line. For example, 1031Aliases are commands that expand to a longer input line. For example,
1033@command{ll} is a common alias for @code{ls -l}, and would be defined 1032@command{ll} is a common alias for @code{ls -l}. To define this alias
1034with the command invocation @kbd{alias ll 'ls -l $*'}; with this defined, 1033in Eshell, you can use the command invocation @kbd{alias ll 'ls -l
1035running @samp{ll foo} in Eshell will actually run @samp{ls -l foo}. 1034$@@*'}; with this defined, running @samp{ll foo} in Eshell will
1036Aliases defined (or deleted) by the @command{alias} command are 1035actually run @samp{ls -l foo}. Aliases defined (or deleted) by the
1037automatically written to the file named by @code{eshell-aliases-file}, 1036@command{alias} command are automatically written to the file named by
1038which you can also edit directly. After doing so, use @w{@kbd{M-x 1037@code{eshell-aliases-file}, which you can also edit directly. After
1039eshell-read-aliases-list}} to load the edited aliases. 1038doing so, use @w{@kbd{M-x eshell-read-aliases-list}} to load the
1040 1039edited aliases.
1041@vindex $1, $2, @dots{} 1040
1042Note that unlike aliases in Bash, arguments must be handled 1041Note that unlike aliases in Bash, arguments must be handled
1043explicitly. Typically the alias definition would end in @samp{$*} to 1042explicitly. Within aliases, you can use the special variables
1044pass all arguments along. More selective use of arguments via 1043@samp{$*}, @samp{$0}, @samp{$1}, @samp{$2}, etc. to refer to the
1045@samp{$1}, @samp{$2}, etc., is also possible. For example, 1044arguments passed to the alias.
1045
1046@table @code
1047
1048@vindex $*
1049@item $*
1050This expands to the list of arguments passed to the alias. For
1051example, if you run @code{my-alias 1 2 3}, then @samp{$*} would be the
1052list @code{(1 2 3)}. Note that since this variable is a list, using
1053@samp{$*} in an alias will pass this list as a single argument to the
1054aliased command. Therefore, when defining an alias, you should
1055usually use @samp{$@@*} to pass all arguments along, splicing them
1056into your argument list (@pxref{Dollars Expansion}).
1057
1058@vindex $0
1059@item $0
1060This expands to the name of the alias currently being executed.
1061
1062@vindex $1, $2, @dots{}, $9
1063@item $1, $2, @dots{}, $9
1064These variables expand to the nth argument (starting at 1) passed to
1065the alias. This lets you selectively use an alias's arguments, so
1046@kbd{alias mcd 'mkdir $1 && cd $1'} would cause @kbd{mcd foo} to 1066@kbd{alias mcd 'mkdir $1 && cd $1'} would cause @kbd{mcd foo} to
1047create and switch to a directory called @samp{foo}. 1067create and switch to a directory called @samp{foo}.
1048 1068
1069@end table
1070
1049@node History 1071@node History
1050@section History 1072@section History
1051@cmindex history 1073@cmindex history
@@ -1307,12 +1329,36 @@ to split the string. @var{regexp} can be any form other than a
1307number. For example, @samp{$@var{var}[: 0]} will return the first 1329number. For example, @samp{$@var{var}[: 0]} will return the first
1308element of a colon-delimited string. 1330element of a colon-delimited string.
1309 1331
1332@cindex length operator, in variable expansion
1310@item $#@var{expr} 1333@item $#@var{expr}
1311Expands to the length of the result of @var{expr}, an expression in 1334This is the @dfn{length operator}. It expands to the length of the
1312one of the above forms. For example, @samp{$#@var{var}} returns the 1335result of @var{expr}, an expression in one of the above forms. For
1313length of the variable @var{var} and @samp{$#@var{var}[0]} returns the 1336example, @samp{$#@var{var}} returns the length of the variable
1314length of the first element of @var{var}. Again, signals an error if 1337@var{var} and @samp{$#@var{var}[0]} returns the length of the first
1315the result of @var{expr} is not a string or a sequence. 1338element of @var{var}. Again, signals an error if the result of
1339@var{expr} is not a string or a sequence.
1340
1341@cindex splice operator, in variable expansion
1342@item $@@@var{expr}
1343This is the @dfn{splice operator}. It ``splices'' the elements of
1344@var{expr} (an expression of one of the above forms) into the
1345resulting list of arguments, much like the @samp{,@@} marker in Emacs
1346Lisp (@pxref{Backquote, , , elisp, The Emacs Lisp Reference Manual}).
1347The elements of @var{expr} become arguments at the same level as the
1348other arguments around it. For example, if @var{numbers} is the list
1349@code{(1 2 3)}, then:
1350
1351@example
1352@group
1353~ $ echo 0 $numbers
1354(0
1355 (1 2 3))
1356@end group
1357@group
1358~ $ echo 0 $@@numbers
1359(0 1 2 3)
1360@end group
1361@end example
1316 1362
1317@end table 1363@end table
1318 1364
@@ -2031,7 +2077,7 @@ Allow for a Bash-compatible syntax, such as:
2031 2077
2032@example 2078@example
2033alias arg=blah 2079alias arg=blah
2034function arg () @{ blah $* @} 2080function arg () @{ blah $@@* @}
2035@end example 2081@end example
2036 2082
2037@item Pcomplete sometimes gets stuck 2083@item Pcomplete sometimes gets stuck