bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#26055: 25.1; Eshell dollar expansion $var[i] not working


From: npostavs
Subject: bug#26055: 25.1; Eshell dollar expansion $var[i] not working
Date: Tue, 14 Mar 2017 00:03:06 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

severity 26055 minor
tags 26055 confirmed
quit

Chunyang Xu <mail@xuchunyang.me> writes:

> I execute the following commands in Eshell
>
> ~ $ setq l (quote (a b c))
> (a b c)
> ~ $ echo $l[1]
> ~ $ nth 1 $l
> b
> ~ $
>
> I expect 'echo $l[1]' should print 'b'
>
> ~ $ setq s 'foo bar baz'
> foo bar baz
> ~ $ echo $s[1]
> ~ $ nth 1 (split-string s)
> bar
> ~ $ 
>
> and 'echo $s[1]' should print 'bar' because in
> (info "(eshell) Dollars Expansion") it says
>
> ‘$var[i]’
>      Expands to the ‘i’th element of the value bound to ‘var’.  If the
>      value is a string, it will be split at whitespace to make it a
>      list.  Again, raises an error if the value is not a sequence.
>
> Do I misunderstand this? Besides, the manual also says
>
> ‘$var[hello]’
>      Calls ‘assoc’ on ‘var’ with ‘"hello"’, expecting it to be an alist
>      (*note Association Lists: (elisp)Association List Type.).
>
> it looks like to me they are using the same syntax, if so, how can
> Eshell know which is which?
>
> ~ $ setq al (quote (("1" . one) ("2" . two)))
> (("1" . one)
>  ("2" . two))
> ~ $ echo $al[1]
> one
> ~ $

Since this apparently never worked it's hard to say what's supposed to
happen, but it looks like a 'number' property is added and then ignored.
Maybe something like this should be applied?

---   i/lisp/eshell/esh-var.el
+++   w/lisp/eshell/esh-var.el
@@ -562,8 +562,10 @@ eshell-apply-indices
   value)
 
 (defun eshell-index-value (value index)
   "Reference VALUE using the given INDEX."
+  (when (and (stringp index) (get-text-property 0 'number index))
+    (setq index (string-to-number index)))
   (if (stringp index)
       (cdr (assoc index value))
     (cond
      ((ring-p value)






reply via email to

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