aboutsummaryrefslogtreecommitdiffstats
path: root/doc/misc
diff options
context:
space:
mode:
authorJim Porter2024-10-19 11:52:42 -0700
committerJim Porter2024-10-19 12:01:10 -0700
commit43d5b7a04c4b1a8a7d57f25824df2e8720d2c567 (patch)
tree189201134e9e92c6bbf156ebb772f573f65cf71f /doc/misc
parentc2a9f519f7e9a5cbb5dbe50ba7b4e4b2757bb3b6 (diff)
downloademacs-43d5b7a04c4b1a8a7d57f25824df2e8720d2c567.tar.gz
emacs-43d5b7a04c4b1a8a7d57f25824df2e8720d2c567.zip
Lazily convert numeric strings to Lisp numbers in Eshell
This should reduce the number of issues with Eshell converting strings to numbers too aggressively and losing information (e.g. "001" -> 1) while still allowing almost all of the beneficial uses, like summing a list of numeric strings with '+'. * lisp/eshell/esh-util.el (eshell--do-mark-numeric-string): New function. (eshell-convert-to-number): Make obsolete in favor of... (eshell-mark-numeric-string): ... this. Update callers. * lisp/eshell/esh-arg.el (eshell--numberlike-p): New function... (eshell-concat-1): ... use it. * test/lisp/eshell/esh-util-tests.el: Reimplement type conversion tests to use 'eshell-convertible-to-number-p' instead. * test/lisp/eshell/esh-var-tests.el (esh-var-test/interp-var-splice-concat, esh-var-test/interp-concat-cmd) (esh-var-test/interp-convert-var-split-indices) (esh-var-test/interp-convert-quoted-var-split-indices) (esh-var-test/interp-convert-cmd-multiline) (esh-var-test/interp-convert-cmd-split-indices): Adjust tests to check the new behavior. * doc/misc/eshell.texi (Type Conversion): New section. (Expansion): Clarify concatenation behavior.
Diffstat (limited to 'doc/misc')
-rw-r--r--doc/misc/eshell.texi61
1 files changed, 46 insertions, 15 deletions
diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi
index 9a2714b14fb..ee4d0ca09c8 100644
--- a/doc/misc/eshell.texi
+++ b/doc/misc/eshell.texi
@@ -432,16 +432,6 @@ This command writes a list of all files matching the glob pattern
432 432
433@node Arguments 433@node Arguments
434@section Arguments 434@section Arguments
435Ordinarily, Eshell parses arguments in command form as either strings
436or numbers, depending on what the parser thinks they look like. To
437specify an argument of some other data type, you can use a Lisp form
438(@pxref{Invocation}):
439
440@example
441~ $ echo (list 1 2 3)
442(1 2 3)
443@end example
444
445When calling external commands (and many built-in Eshell commands, 435When calling external commands (and many built-in Eshell commands,
446too) Eshell will flatten the arguments the command receives, so 436too) Eshell will flatten the arguments the command receives, so
447passing a list as an argument will ``spread'' the elements into 437passing a list as an argument will ``spread'' the elements into
@@ -454,13 +444,15 @@ multiple arguments:
4543 4443
455@end example 445@end example
456 446
457@subsection Quoting and escaping 447@subsection Quoting and Escaping
458As with other shells, you can escape special characters and spaces by 448As with other shells, you can escape special characters and spaces by
459prefixing the character with a backslash (@samp{\}), or by surrounding 449prefixing the character with a backslash (@samp{\}), or by surrounding
460the string with apostrophes (@samp{''}) or double quotes (@samp{""}). 450the string with apostrophes (@samp{''}) or double quotes (@samp{""}).
461This is needed especially for file names with special characters like 451This is needed especially for file names with special characters like
462pipe (@samp{|}) or square brackets (@samp{[} or @samp{]}), which could 452pipe (@samp{|}) or square brackets (@samp{[} or @samp{]}), which could
463be part of remote file names. 453be part of remote file names. In addition, quoting or escaping an
454argument will prevent it from being converted to a number when passed to
455a Lisp function.
464 456
465When you escape a character with @samp{\} outside of any quotes, the 457When you escape a character with @samp{\} outside of any quotes, the
466result is the literal character immediately following it. For 458result is the literal character immediately following it. For
@@ -495,7 +487,46 @@ When using expansions (@pxref{Expansion}) in an Eshell command, the
495result may potentially be of any data type. To ensure that the result 487result may potentially be of any data type. To ensure that the result
496is always a string, the expansion can be surrounded by double quotes. 488is always a string, the expansion can be surrounded by double quotes.
497 489
498@subsection Special argument types 490@subsection Type Conversion
491When invoking a Lisp function via command form, Eshell automatically
492converts string arguments that look like numbers to actual Lisp
493numbers in order to make it easier to work with numeric values. You can
494prevent this conversion on a case-by-case basis by quoting or escaping
495the argument:
496
497@example
498~ $ type-of 1
499integer
500~ $ type-of "1"
501string
502@end example
503
504When invoking a subcommand in command form, Eshell will split the output
505line-by-line into a list. Additionally, if every line looks like a
506number, then Eshell will mark them as numeric so that passing them to a
507Lisp function will convert them to Lisp numbers:
508
509@example
510~ $ cat numbers.txt
51101
51202
51303
514~ $ + $@@@{cat numbers.txt@}
5156
516@end example
517
518If you find this behavior inconvenient for certain functions, you can
519tell Eshell not to perform this conversion for that function:
520
521@example
522(put \\='find-file \\='eshell-no-numeric-conversions t)
523@end example
524
525@vindex eshell-convert-numeric-arguments
526You can also disable this conversion behavior entirely by setting
527@code{eshell-convert-numeric-arguments} to @code{nil}.
528
529@subsection Special Argument Types
499In addition to strings and numbers, Eshell supports a number of 530In addition to strings and numbers, Eshell supports a number of
500special argument types. These let you refer to various other Emacs 531special argument types. These let you refer to various other Emacs
501Lisp data types, such as lists or buffers. 532Lisp data types, such as lists or buffers.
@@ -1764,8 +1795,8 @@ behavior depends on the types of each value being concatenated:
1764Concatenate both values together. 1795Concatenate both values together.
1765 1796
1766@item one or both numbers 1797@item one or both numbers
1767Concatenate the string representation of each value, converting back to 1798Concatenate the string representation of each value. If either value is
1768a number if possible. 1799numeric, mark the concatenated value as numeric if possible.
1769 1800
1770@item one or both (non-@code{nil}) lists 1801@item one or both (non-@code{nil}) lists
1771Concatenate ``adjacent'' elements of each value (possibly converting 1802Concatenate ``adjacent'' elements of each value (possibly converting