emacs-diffs
[Top][All Lists]
Advanced

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

master d72cd4a2b7 5/5: Allow splitting strings in Eshell expansions with


From: Lars Ingebrigtsen
Subject: master d72cd4a2b7 5/5: Allow splitting strings in Eshell expansions with "plain" strings
Date: Thu, 3 Mar 2022 08:59:49 -0500 (EST)

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

    Allow splitting strings in Eshell expansions with "plain" strings
    
    Since '$var[hello 0]' doesn't make sense when 'var' is a string, the
    previous restriction was unnecessary.
    
    * lisp/eshell/esh-var.el (Commentary): Update documentation.
    (eshell-apply-indices): Allow "plain" strings to split strings.
    
    * test/lisp/eshell/esh-var-test.el
    (esh-var-test/interp-var-string-split-indices)
    (esh-var-test/quoted-interp-var-string-split-indices): Update tests.
    
    * doc/misc/eshell.texi (Dollars expansion): Update documentation.
---
 doc/misc/eshell.texi              |  6 +++---
 lisp/eshell/esh-var.el            | 17 +++++++----------
 test/lisp/eshell/esh-var-tests.el | 12 ++++++++++++
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi
index 3301a854eb..5581e5cd9e 100644
--- a/doc/misc/eshell.texi
+++ b/doc/misc/eshell.texi
@@ -1055,9 +1055,9 @@ Multiple sets of indices can also be specified. For 
example, if
 
 @item $@var{expr}[@var{regexp} @var{i...}]
 As above (when @var{expr} expands to a string), but use @var{regexp}
-to split the string.  @var{regexp} can be any form other than a number
-or a plain variable name.  For example, @samp{$@var{var}[: 0]} will
-return the first element of a colon-delimited string.
+to split the string.  @var{regexp} can be any form other than a
+number.  For example, @samp{$@var{var}[: 0]} will return the first
+element of a colon-delimited string.
 
 @item $#@var{expr}
 Expands to the length of the result of @var{expr}, an expression in
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index 6f08a3fbc4..af89e35f55 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -74,9 +74,8 @@
 ;;   $EXPR["\\\\" 10]
 ;;
 ;; Separate on backslash characters.  Actually, the first argument --
-;; if it doesn't have the form of a number, or a plain variable name
-;; -- can be any regular expression.  So to split on numbers, use
-;; '$EXPR["[0-9]+" 10 20]'.
+;; if it doesn't have the form of a number -- can be any regular
+;; expression.  So to split on numbers, use '$EXPR["[0-9]+" 10 20]'.
 ;;
 ;;   $EXPR[hello]
 ;;
@@ -566,13 +565,11 @@ For example, to retrieve the second element of a user's 
record in
   (while indices
     (let ((refs (car indices)))
       (when (stringp value)
-       (let (separator)
-         (if (not (or (not (stringp (caar indices)))
-                      (string-match
-                       (concat "^" eshell-variable-name-regexp "$")
-                       (caar indices))))
-             (setq separator (caar indices)
-                   refs (cdr refs)))
+       (let (separator (index (caar indices)))
+          (when (and (stringp index)
+                     (not (get-text-property 0 'number index)))
+            (setq separator index
+                  refs (cdr refs)))
          (setq value
                (mapcar #'eshell-convert
                        (split-string value separator)))))
diff --git a/test/lisp/eshell/esh-var-tests.el 
b/test/lisp/eshell/esh-var-tests.el
index e679174939..d09dd614de 100644
--- a/test/lisp/eshell/esh-var-tests.el
+++ b/test/lisp/eshell/esh-var-tests.el
@@ -84,6 +84,11 @@
     (should (equal (eshell-test-command-result "echo $eshell-test-value[: 0]")
                    "zero"))
     (should (equal (eshell-test-command-result "echo $eshell-test-value[: 0 
2]")
+                   '("zero" "two"))))
+  (let ((eshell-test-value "zeroXoneXtwoXthreeXfour"))
+    (should (equal (eshell-test-command-result "echo $eshell-test-value[X 0]")
+                   "zero"))
+    (should (equal (eshell-test-command-result "echo $eshell-test-value[X 0 
2]")
                    '("zero" "two")))))
 
 (ert-deftest esh-var-test/interp-var-regexp-split-indices ()
@@ -216,6 +221,13 @@ inside double-quotes"
                    "zero"))
     (should (equal (eshell-test-command-result
                     "echo \"$eshell-test-value[: 0 2]\"")
+                   '("zero" "two"))))
+  (let ((eshell-test-value "zeroXoneXtwoXthreeXfour"))
+    (should (equal (eshell-test-command-result
+                    "echo \"$eshell-test-value[X 0]\"")
+                   "zero"))
+    (should (equal (eshell-test-command-result
+                    "echo \"$eshell-test-value[X 0 2]\"")
                    '("zero" "two")))))
 
 (ert-deftest esh-var-test/quoted-interp-var-regexp-split-indices ()



reply via email to

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