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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 26055 in the body.
You can then email your comments to 26055 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#26055; Package emacs. (Sat, 11 Mar 2017 09:36:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Chunyang Xu <mail <at> xuchunyang.me>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 11 Mar 2017 09:36:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Chunyang Xu <mail <at> xuchunyang.me>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.1; Eshell dollar expansion $var[i] not working
Date: Sat, 11 Mar 2017 17:35:05 +0800
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
~ $






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26055; Package emacs. (Tue, 14 Mar 2017 04:02:02 GMT) Full text and rfc822 format available.

Message #8 received at 26055 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Chunyang Xu <mail <at> xuchunyang.me>
Cc: 26055 <at> debbugs.gnu.org
Subject: Re: 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)





Severity set to 'minor' from 'normal' Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Tue, 14 Mar 2017 04:02:02 GMT) Full text and rfc822 format available.

Added tag(s) confirmed. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Tue, 14 Mar 2017 04:02:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26055; Package emacs. (Sat, 10 Jun 2017 00:32:02 GMT) Full text and rfc822 format available.

Message #15 received at 26055 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Chunyang Xu <mail <at> xuchunyang.me>
Cc: 26055 <at> debbugs.gnu.org
Subject: Re: bug#26055: 25.1; Eshell dollar expansion $var[i] not working
Date: Fri, 09 Jun 2017 20:33:26 -0400
[Message part 1 (text/plain, inline)]
tags 26055 patch
quit

npostavs <at> users.sourceforge.net writes:

> 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?

Since `eshell-lisp-command' does the conversion of strings marked with
'number', I think it's correct to make eshell-index-value do so as well.

[v1-0001-Handle-integer-indices-for-eshell-variables-Bug-2.patch (text/x-diff, inline)]
From bacbb41ab4d5539d284b1a540e70779a49c00e25 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Fri, 9 Jun 2017 19:40:38 -0400
Subject: [PATCH v1] Handle integer indices for eshell variables (Bug#26055)

* lisp/eshell/esh-var.el (eshell-index-value): Convert index to number
if it's been marked as one, just like `eshell-lisp-command' does.
---
 lisp/eshell/esh-var.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index fe1f1188c8..cdd05bd7e9 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -563,6 +563,8 @@ (defun eshell-apply-indices (value indices)
 
 (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
-- 
2.11.1


Added tag(s) patch. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 10 Jun 2017 00:32:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26055; Package emacs. (Sat, 17 Jun 2017 04:17:02 GMT) Full text and rfc822 format available.

Message #20 received at 26055 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Chunyang Xu <mail <at> xuchunyang.me>
Cc: 26055 <at> debbugs.gnu.org
Subject: Re: bug#26055: 25.1; Eshell dollar expansion $var[i] not working
Date: Sat, 17 Jun 2017 00:17:52 -0400
tags 26055 fixed
close 26055 26.1
quit

npostavs <at> users.sourceforge.net writes:

>> 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?
>
> Since `eshell-lisp-command' does the conversion of strings marked with
> 'number', I think it's correct to make eshell-index-value do so as well.

Pushed to master [1: 27c194995b].

[1: 27c194995b]: 2017-06-17 00:10:33 -0400
  Handle integer indices for eshell variables (Bug#26055)
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=27c194995b460b79e8e62e0d21e85d87df664649




Added tag(s) fixed. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 17 Jun 2017 04:17:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 26.1, send any further explanations to 26055 <at> debbugs.gnu.org and Chunyang Xu <mail <at> xuchunyang.me> Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 17 Jun 2017 04:17:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 15 Jul 2017 11:24:04 GMT) Full text and rfc822 format available.

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.