diff options
| author | Jim Porter | 2023-01-20 13:54:20 -0800 |
|---|---|---|
| committer | Jim Porter | 2023-01-27 18:03:10 -0800 |
| commit | dabe0b7d40778496ecb308f54999248ea286d89b (patch) | |
| tree | a51119134da0ea2332b82d94bb3d8401252d530c /doc/misc | |
| parent | 4287d56bad5201cf0946526bb0e27c17426bd969 (diff) | |
| download | emacs-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.texi | 28 |
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. | |||
| 1059 | This refers to the last argument of the last command. With a | 1059 | This refers to the last argument of the last command. With a |
| 1060 | subscript, you can access any argument of the last command. For | 1060 | subscript, you can access any argument of the last command. For |
| 1061 | example, @samp{$_[1]} refers to the second argument of the last | 1061 | example, @samp{$_[1]} refers to the second argument of the last |
| 1062 | command (excluding the command name itself). | 1062 | command (excluding the command name itself). To get all arguments of |
| 1063 | the 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 |
| 1371 | Expands to the element at the (zero-based) index @var{i} of the | 1373 | Expands to the element at the (zero-based) index @var{i} of the |
| 1372 | sequence (@pxref{Sequences Arrays Vectors, Sequences, , elisp, The | 1374 | sequence (@pxref{Sequences Arrays Vectors, Sequences, , elisp, The |
| 1373 | Emacs Lisp Reference Manual}). | 1375 | Emacs Lisp Reference Manual}). If @var{i} is negative, @var{i} counts |
| 1376 | from the end, so -1 refers to the last element of the sequence. | ||
| 1377 | |||
| 1378 | If @var{i} is a range like @code{@var{start}..@var{end}}, this expands | ||
| 1379 | to a subsequence from the indices @var{start} to @var{end}, where | ||
| 1380 | @var{end} is excluded@footnote{This behavior is different from ranges | ||
| 1381 | in Bash (where both the start and end are included in the range), but | ||
| 1382 | matches the behavior of similar Emacs Lisp functions, like | ||
| 1383 | @code{substring} (@pxref{Creating Strings, , , elisp, The Emacs Lisp | ||
| 1384 | Reference Manual}).}. @var{start} and/or @var{end} can also be | ||
| 1385 | omitted, which is equivalent to the start and/or end of the entire | ||
| 1386 | list. For example, @samp{$@var{expr}[-2..]} expands to the last two | ||
| 1387 | values of @var{expr}. | ||
| 1374 | 1388 | ||
| 1375 | @item a string | 1389 | @item a string |
| 1376 | Split the string at whitespace, and then expand to the @var{i}th | 1390 | Split the string at whitespace, and then expand to the @var{i}th |
| 1377 | element of the resulting sequence. | 1391 | element of the resulting sequence. As above, @var{i} can be a range |
| 1392 | like @code{@var{start}..@var{end}}. | ||
| 1378 | 1393 | ||
| 1379 | @item an alist | 1394 | @item an alist |
| 1380 | If @var{i} is a non-numeric value, expand to the value associated with | 1395 | If @var{i} is a non-numeric value, expand to the value associated with |
| @@ -2442,13 +2457,6 @@ current being used. | |||
| 2442 | 2457 | ||
| 2443 | This way, the user could change it to use rc syntax: @samp{>[2=1]}. | 2458 | This 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 | |||
| 2449 | Return them as a list, so that @samp{$_[*]} is all the arguments of the | ||
| 2450 | last 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 | ||
| 2454 | Make it possible for the user to send char-by-char to the underlying | 2462 | Make it possible for the user to send char-by-char to the underlying |