diff options
| author | Stefan Kangas | 2022-03-02 06:33:19 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2022-03-02 06:33:19 +0100 |
| commit | 6d78321ce824ede11ab04d976d46487bcd191cab (patch) | |
| tree | e1f511f01c224bea7b70d1f4db52ccee5331b34a | |
| parent | 2b130bd944a36510043750286106a16a1e2ad7c4 (diff) | |
| parent | 9dadcbe4297fdd52e2664e99fe693ba35a51eb57 (diff) | |
| download | emacs-6d78321ce824ede11ab04d976d46487bcd191cab.tar.gz emacs-6d78321ce824ede11ab04d976d46487bcd191cab.zip | |
Merge from origin/emacs-28
9dadcbe429 ; * doc/misc/eshell.texi (Dollars Expansion): Fix markup.
2c3d1b6bf4 Improve/correct documentation about Eshell variable expansion
9e257aecc9 Partially revert b03f74e0f2a578b1580e8b1c368665850ee7f808
| -rw-r--r-- | doc/misc/eshell.texi | 54 | ||||
| -rw-r--r-- | lisp/eshell/esh-var.el | 23 | ||||
| -rw-r--r-- | test/lisp/eshell/eshell-tests.el | 4 |
3 files changed, 55 insertions, 26 deletions
diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi index 261e88d00c6..bbf8ca6b8bd 100644 --- a/doc/misc/eshell.texi +++ b/doc/misc/eshell.texi | |||
| @@ -1012,51 +1012,63 @@ of familiarity. | |||
| 1012 | 1012 | ||
| 1013 | @table @code | 1013 | @table @code |
| 1014 | 1014 | ||
| 1015 | @item $var | 1015 | @item $@var{var} |
| 1016 | Expands to the value bound to @code{var}. This is the main way to use | 1016 | Expands to the value bound to @var{var}. This is the main way to use |
| 1017 | variables in command invocations. | 1017 | variables in command invocations. |
| 1018 | 1018 | ||
| 1019 | @item $#var | 1019 | @item $"@var{var}" |
| 1020 | Expands to the length of the value bound to @code{var}. Raises an error | 1020 | @item $'@var{var}' |
| 1021 | Expands to the value bound to @var{var}. This is useful to | ||
| 1022 | disambiguate the variable name when concatenating it with another | ||
| 1023 | value, such as @samp{$"@var{var}"-suffix}. | ||
| 1024 | |||
| 1025 | @item $#@var{var} | ||
| 1026 | Expands to the length of the value bound to @var{var}. Raises an error | ||
| 1021 | if the value is not a sequence | 1027 | if the value is not a sequence |
| 1022 | (@pxref{Sequences Arrays Vectors, Sequences, , elisp, The Emacs Lisp Reference Manual}). | 1028 | (@pxref{Sequences Arrays Vectors, Sequences, , elisp, The Emacs Lisp Reference Manual}). |
| 1023 | 1029 | ||
| 1024 | @item $(lisp) | 1030 | @item $(@var{lisp}) |
| 1025 | Expands to the result of evaluating the S-expression @code{(lisp)}. On | 1031 | Expands to the result of evaluating the S-expression @code{(@var{lisp})}. On |
| 1026 | its own, this is identical to just @code{(lisp)}, but with the @code{$}, | 1032 | its own, this is identical to just @code{(@var{lisp})}, but with the @code{$}, |
| 1027 | it can be used in a string, such as @samp{/some/path/$(lisp).txt}. | 1033 | it can be used in a string, such as @samp{/some/path/$(@var{lisp}).txt}. |
| 1028 | 1034 | ||
| 1029 | @item $@{command@} | 1035 | @item $@{@var{command}@} |
| 1030 | Returns the output of @command{command}, which can be any valid Eshell | 1036 | Returns the output of @command{@var{command}}, which can be any valid Eshell |
| 1031 | command invocation, and may even contain expansions. | 1037 | command invocation, and may even contain expansions. |
| 1032 | 1038 | ||
| 1033 | @item $var[i] | 1039 | @item $<@var{command}> |
| 1034 | Expands to the @code{i}th element of the value bound to @code{var}. If | 1040 | As with @samp{$@{@var{command}@}}, evaluates the Eshell command invocation |
| 1041 | @command{@var{command}}, but writes the output to a temporary file and | ||
| 1042 | returns the file name. | ||
| 1043 | |||
| 1044 | @item $@var{var}[i] | ||
| 1045 | Expands to the @code{i}th element of the value bound to @var{var}. If | ||
| 1035 | the value is a string, it will be split at whitespace to make it a list. | 1046 | the value is a string, it will be split at whitespace to make it a list. |
| 1036 | Again, raises an error if the value is not a sequence. | 1047 | Again, raises an error if the value is not a sequence. |
| 1037 | 1048 | ||
| 1038 | @item $var[: i] | 1049 | @item $@var{var}[: i] |
| 1039 | As above, but now splitting occurs at the colon character. | 1050 | As above, but now splitting occurs at the colon character. |
| 1040 | 1051 | ||
| 1041 | @item $var[: i j] | 1052 | @item $@var{var}[: i j] |
| 1042 | As above, but instead of returning just a string, it now returns a list | 1053 | As above, but instead of returning just a string, it now returns a list |
| 1043 | of two strings. If the result is being interpolated into a larger | 1054 | of two strings. If the result is being interpolated into a larger |
| 1044 | string, this list will be flattened into one big string, with each | 1055 | string, this list will be flattened into one big string, with each |
| 1045 | element separated by a space. | 1056 | element separated by a space. |
| 1046 | 1057 | ||
| 1047 | @item $var["\\\\" i] | 1058 | @item $@var{var}["\\\\" i] |
| 1048 | Separate on backslash characters. Actually, the first argument -- if it | 1059 | Separate on backslash characters. Actually, the first argument -- if it |
| 1049 | doesn't have the form of a number, or a plain variable name -- can be | 1060 | doesn't have the form of a number, or a plain variable name -- can be |
| 1050 | any regular expression. So to split on numbers, use @samp{$var["[0-9]+" 10 20]}. | 1061 | any regular expression. So to split on numbers, use |
| 1062 | @samp{$@var{var}["[0-9]+" 10 20]}. | ||
| 1051 | 1063 | ||
| 1052 | @item $var[hello] | 1064 | @item $@var{var}[hello] |
| 1053 | Calls @code{assoc} on @code{var} with @code{"hello"}, expecting it to be | 1065 | Calls @code{assoc} on @var{var} with @code{"hello"}, expecting it to be |
| 1054 | an alist (@pxref{Association List Type, Association Lists, , elisp, | 1066 | an alist (@pxref{Association List Type, Association Lists, , elisp, |
| 1055 | The Emacs Lisp Reference Manual}). | 1067 | The Emacs Lisp Reference Manual}). |
| 1056 | 1068 | ||
| 1057 | @item $#var[hello] | 1069 | @item $#@var{var}[hello] |
| 1058 | Returns the length of the cdr of the element of @code{var} who car is equal | 1070 | Returns the length of the @code{cdr} of the element of @var{var} whose |
| 1059 | to @code{"hello"}. | 1071 | car is equal to @code{"hello"}. |
| 1060 | 1072 | ||
| 1061 | @end table | 1073 | @end table |
| 1062 | 1074 | ||
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el index 5c8dacd980e..ee3ffbc6475 100644 --- a/lisp/eshell/esh-var.el +++ b/lisp/eshell/esh-var.el | |||
| @@ -34,7 +34,8 @@ | |||
| 34 | ;; | 34 | ;; |
| 35 | ;; "-" is a valid part of a variable name. | 35 | ;; "-" is a valid part of a variable name. |
| 36 | ;; | 36 | ;; |
| 37 | ;; $<MYVAR>-TOO | 37 | ;; $\"MYVAR\"-TOO |
| 38 | ;; $'MYVAR'-TOO | ||
| 38 | ;; | 39 | ;; |
| 39 | ;; Only "MYVAR" is part of the variable name in this case. | 40 | ;; Only "MYVAR" is part of the variable name in this case. |
| 40 | ;; | 41 | ;; |
| @@ -55,6 +56,11 @@ | |||
| 55 | ;; Returns the value of an eshell subcommand. See the note above | 56 | ;; Returns the value of an eshell subcommand. See the note above |
| 56 | ;; regarding Lisp evaluations. | 57 | ;; regarding Lisp evaluations. |
| 57 | ;; | 58 | ;; |
| 59 | ;; $<command> | ||
| 60 | ;; | ||
| 61 | ;; Evaluates an eshell subcommand, redirecting the output to a | ||
| 62 | ;; temporary file, and returning the file name. | ||
| 63 | ;; | ||
| 58 | ;; $ANYVAR[10] | 64 | ;; $ANYVAR[10] |
| 59 | ;; | 65 | ;; |
| 60 | ;; Return the 10th element of ANYVAR. If ANYVAR's value is a string, | 66 | ;; Return the 10th element of ANYVAR. If ANYVAR's value is a string, |
| @@ -423,9 +429,12 @@ variable. | |||
| 423 | Possible options are: | 429 | Possible options are: |
| 424 | 430 | ||
| 425 | NAME an environment or Lisp variable value | 431 | NAME an environment or Lisp variable value |
| 426 | <LONG-NAME> disambiguates the length of the name | 432 | \"LONG-NAME\" disambiguates the length of the name |
| 433 | 'LONG-NAME' as above | ||
| 427 | {COMMAND} result of command is variable's value | 434 | {COMMAND} result of command is variable's value |
| 428 | (LISP-FORM) result of Lisp form is variable's value" | 435 | (LISP-FORM) result of Lisp form is variable's value |
| 436 | <COMMAND> write the output of command to a temporary file; | ||
| 437 | result is the file name" | ||
| 429 | (cond | 438 | (cond |
| 430 | ((eq (char-after) ?{) | 439 | ((eq (char-after) ?{) |
| 431 | (let ((end (eshell-find-delimiter ?\{ ?\}))) | 440 | (let ((end (eshell-find-delimiter ?\{ ?\}))) |
| @@ -457,8 +466,12 @@ Possible options are: | |||
| 457 | (eshell-as-subcommand ,(eshell-parse-command cmd)) | 466 | (eshell-as-subcommand ,(eshell-parse-command cmd)) |
| 458 | (ignore | 467 | (ignore |
| 459 | (nconc eshell-this-command-hook | 468 | (nconc eshell-this-command-hook |
| 460 | (list (lambda () | 469 | ;; Quote this lambda; it will be evaluated |
| 461 | (delete-file ,temp))))) | 470 | ;; by `eshell-do-eval', which requires very |
| 471 | ;; particular forms in order to work | ||
| 472 | ;; properly. See bug#54190. | ||
| 473 | (list (function (lambda () | ||
| 474 | (delete-file ,temp)))))) | ||
| 462 | (quote ,temp))) | 475 | (quote ,temp))) |
| 463 | (goto-char (1+ end))))))) | 476 | (goto-char (1+ end))))))) |
| 464 | ((eq (char-after) ?\() | 477 | ((eq (char-after) ?\() |
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index d6ee1bdb175..eff4edd62c7 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el | |||
| @@ -93,6 +93,10 @@ e.g. \"{(+ 1 2)} 3\" => 3" | |||
| 93 | "Interpolate Lisp form evaluation" | 93 | "Interpolate Lisp form evaluation" |
| 94 | (should (equal (eshell-test-command-result "+ $(+ 1 2) 3") 6))) | 94 | (should (equal (eshell-test-command-result "+ $(+ 1 2) 3") 6))) |
| 95 | 95 | ||
| 96 | (ert-deftest eshell-test/interp-temp-cmd () | ||
| 97 | "Interpolate command result redirected to temp file" | ||
| 98 | (should (equal (eshell-test-command-result "cat $<echo hi>") "hi"))) | ||
| 99 | |||
| 96 | (ert-deftest eshell-test/interp-concat () | 100 | (ert-deftest eshell-test/interp-concat () |
| 97 | "Interpolate and concat command" | 101 | "Interpolate and concat command" |
| 98 | (should (equal (eshell-test-command-result "+ ${+ 1 2}3 3") 36))) | 102 | (should (equal (eshell-test-command-result "+ ${+ 1 2}3 3") 36))) |