emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master a8e5e3ce5d: Don't split Eshell expansions by line when using spli


From: Lars Ingebrigtsen
Subject: master a8e5e3ce5d: Don't split Eshell expansions by line when using split-subscript operator
Date: Wed, 8 Jun 2022 08:11:53 -0400 (EDT)

branch: master
commit a8e5e3ce5d7929fa92251359c13da959c3f22771
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Don't split Eshell expansions by line when using split-subscript operator
    
    * lisp/eshell/esh-var.el (eshell-apply-indices): Use
    'eshell-convert-to-number' instead of 'eshell-convert'.
    
    * test/lisp/eshell/esh-var-tests.el
    (esh-var-test/interp-convert-var-split-indices): Expand test
    (bug#55838).
---
 lisp/eshell/esh-var.el            | 15 ++++++++-------
 test/lisp/eshell/esh-var-tests.el |  9 ++++++++-
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index 186f6358bc..27be6e1b1a 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -582,10 +582,11 @@ Otherwise, each INT-OR-NAME refers to an element of the 
list value.
 Integers imply a direct index, and names, an associate lookup using
 `assoc'.
 
-If QUOTED is non-nil, this was invoked inside double-quotes.  This
-affects the behavior of splitting strings: without quoting, the
-split values are converted to Lisp forms via `eshell-convert'; with
-quoting, they're left as strings.
+If QUOTED is non-nil, this was invoked inside double-quotes.
+This affects the behavior of splitting strings: without quoting,
+the split values are converted to numbers via
+`eshell-convert-to-number' if possible; with quoting, they're
+left as strings.
 
 For example, to retrieve the second element of a user's record in
 '/etc/passwd', the variable reference would look like:
@@ -599,9 +600,9 @@ For example, to retrieve the second element of a user's 
record in
                      (not (get-text-property 0 'number index)))
             (setq separator index
                   refs (cdr refs)))
-         (setq value
-               (mapcar (lambda (i) (eshell-convert i quoted))
-                       (split-string value separator)))))
+         (setq value (split-string value separator))
+          (unless quoted
+            (setq value (mapcar #'eshell-convert-to-number value)))))
       (cond
        ((< (length refs) 0)
        (error "Invalid array variable index: %s"
diff --git a/test/lisp/eshell/esh-var-tests.el 
b/test/lisp/eshell/esh-var-tests.el
index 4e2a18861e..072cdb9b40 100644
--- a/test/lisp/eshell/esh-var-tests.el
+++ b/test/lisp/eshell/esh-var-tests.el
@@ -357,11 +357,18 @@ inside double-quotes"
 
 (ert-deftest esh-var-test/interp-convert-var-split-indices ()
   "Interpolate and convert string variable with indices"
+  ;; Check that numeric forms are converted to numbers.
   (let ((eshell-test-value "000 010 020 030 040"))
     (should (equal (eshell-test-command-result "echo $eshell-test-value[0]")
                    0))
     (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2]")
-                   '(0 20)))))
+                   '(0 20))))
+  ;; Check that multiline forms are preserved as-is.
+  (let ((eshell-test-value "foo\nbar:baz\n"))
+    (should (equal (eshell-test-command-result "echo $eshell-test-value[: 0]")
+                   "foo\nbar"))
+    (should (equal (eshell-test-command-result "echo $eshell-test-value[: 1]")
+                   "baz\n"))))
 
 (ert-deftest esh-var-test/interp-convert-quoted-var-number ()
   "Interpolate numeric quoted numeric variable"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]