@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
;; $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]
;;
(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)))))
(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 ()
"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 ()