GNU bug report logs - #26055
25.1; Eshell dollar expansion $var[i] not working

Previous Next

Package: emacs;

Reported by: Chunyang Xu <mail <at> xuchunyang.me>

Date: Sat, 11 Mar 2017 09:36:02 UTC

Severity: minor

Tags: confirmed, fixed, patch

Found in version 25.1

Fixed in version 26.1

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: npostavs <at> users.sourceforge.net
To: Chunyang Xu <mail <at> xuchunyang.me>
Cc: 26055 <at> debbugs.gnu.org
Subject: bug#26055: 25.1; Eshell dollar expansion $var[i] not working
Date: Tue, 14 Mar 2017 00:03:06 -0400
severity 26055 minor
tags 26055 confirmed
quit

Chunyang Xu <mail <at> 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)





This bug report was last modified 7 years and 337 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.