aboutsummaryrefslogtreecommitdiffstats
path: root/doc/misc
diff options
context:
space:
mode:
authorJim Porter2023-01-20 13:54:20 -0800
committerJim Porter2023-01-27 18:03:10 -0800
commitdabe0b7d40778496ecb308f54999248ea286d89b (patch)
treea51119134da0ea2332b82d94bb3d8401252d530c /doc/misc
parent4287d56bad5201cf0946526bb0e27c17426bd969 (diff)
downloademacs-dabe0b7d40778496ecb308f54999248ea286d89b.tar.gz
emacs-dabe0b7d40778496ecb308f54999248ea286d89b.zip
Add support for negative indices and index ranges in Eshell
* lisp/eshell/esh-util.el (eshell-integer-regexp): New defvar. * lisp/eshell/esh-var.el (eshell-parse-indices): Expand docstring. (eshell-parse-index): New function. (eshell-apply-indices): Use 'eshell-parse-index' to determine whether to treat the first index as a regexp. Simplify the implementation a bit. (eshell-index-range): New pcase macro... (eshell-index-value): ... use it, and restructure the implementation. * test/lisp/eshell/esh-var-tests.el (esh-var-test/interp-var-indices): New function... (esh-var-test/interp-var-indices/list) (esh-var-test/interp-var-indices/vector) (esh-var-test/interp-var-indices/ring) (esh-var-test/interp-var-indices/split): ... use it. (esh-var-test/interp-var-string-split-indices) (esh-var-test/interp-var-regexp-split-indices) (esh-var-test/interp-var-assoc): Expand tests to cover things that look like numbers or ranges, but aren't. * doc/misc/eshell.texi (Variables): Describe how to get all arguments of the last command. (Dollars Expansion): Explain negative indices and index ranges. (Bugs and ideas): Remove now-implemented ideas. * etc/NEWS: Announce this change.
Diffstat (limited to 'doc/misc')
-rw-r--r--doc/misc/eshell.texi28
1 files changed, 18 insertions, 10 deletions
diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi
index 57a2020fdca..e51e2cf799b 100644
--- a/doc/misc/eshell.texi
+++ b/doc/misc/eshell.texi
@@ -1059,7 +1059,9 @@ remote connection.
1059This refers to the last argument of the last command. With a 1059This refers to the last argument of the last command. With a
1060subscript, you can access any argument of the last command. For 1060subscript, you can access any argument of the last command. For
1061example, @samp{$_[1]} refers to the second argument of the last 1061example, @samp{$_[1]} refers to the second argument of the last
1062command (excluding the command name itself). 1062command (excluding the command name itself). To get all arguments of
1063the last command, you can use an index range like @samp{$_[..]}
1064(@pxref{Dollars Expansion}).
1063 1065
1064@vindex $$ 1066@vindex $$
1065@item $$ 1067@item $$
@@ -1370,11 +1372,24 @@ index. The exact behavior depends on the type of @var{expr}'s value:
1370@item a sequence 1372@item a sequence
1371Expands to the element at the (zero-based) index @var{i} of the 1373Expands to the element at the (zero-based) index @var{i} of the
1372sequence (@pxref{Sequences Arrays Vectors, Sequences, , elisp, The 1374sequence (@pxref{Sequences Arrays Vectors, Sequences, , elisp, The
1373Emacs Lisp Reference Manual}). 1375Emacs Lisp Reference Manual}). If @var{i} is negative, @var{i} counts
1376from the end, so -1 refers to the last element of the sequence.
1377
1378If @var{i} is a range like @code{@var{start}..@var{end}}, this expands
1379to a subsequence from the indices @var{start} to @var{end}, where
1380@var{end} is excluded@footnote{This behavior is different from ranges
1381in Bash (where both the start and end are included in the range), but
1382matches the behavior of similar Emacs Lisp functions, like
1383@code{substring} (@pxref{Creating Strings, , , elisp, The Emacs Lisp
1384Reference Manual}).}. @var{start} and/or @var{end} can also be
1385omitted, which is equivalent to the start and/or end of the entire
1386list. For example, @samp{$@var{expr}[-2..]} expands to the last two
1387values of @var{expr}.
1374 1388
1375@item a string 1389@item a string
1376Split the string at whitespace, and then expand to the @var{i}th 1390Split the string at whitespace, and then expand to the @var{i}th
1377element of the resulting sequence. 1391element of the resulting sequence. As above, @var{i} can be a range
1392like @code{@var{start}..@var{end}}.
1378 1393
1379@item an alist 1394@item an alist
1380If @var{i} is a non-numeric value, expand to the value associated with 1395If @var{i} is a non-numeric value, expand to the value associated with
@@ -2442,13 +2457,6 @@ current being used.
2442 2457
2443This way, the user could change it to use rc syntax: @samp{>[2=1]}. 2458This way, the user could change it to use rc syntax: @samp{>[2=1]}.
2444 2459
2445@item Allow @samp{$_[-1]}, which would indicate the last element of the array
2446
2447@item Make @samp{$x[*]} equal to listing out the full contents of @samp{x}
2448
2449Return them as a list, so that @samp{$_[*]} is all the arguments of the
2450last command.
2451
2452@item Copy ANSI code handling from @file{term.el} into @file{em-term.el} 2460@item Copy ANSI code handling from @file{term.el} into @file{em-term.el}
2453 2461
2454Make it possible for the user to send char-by-char to the underlying 2462Make it possible for the user to send char-by-char to the underlying