* bug#26055: 25.1; Eshell dollar expansion $var[i] not working
@ 2017-03-11 9:35 Chunyang Xu
2017-03-14 4:03 ` npostavs
0 siblings, 1 reply; 4+ messages in thread
From: Chunyang Xu @ 2017-03-11 9:35 UTC (permalink / raw)
To: 26055
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
~ $
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#26055: 25.1; Eshell dollar expansion $var[i] not working
2017-03-11 9:35 bug#26055: 25.1; Eshell dollar expansion $var[i] not working Chunyang Xu
@ 2017-03-14 4:03 ` npostavs
2017-06-10 0:33 ` npostavs
0 siblings, 1 reply; 4+ messages in thread
From: npostavs @ 2017-03-14 4:03 UTC (permalink / raw)
To: Chunyang Xu; +Cc: 26055
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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#26055: 25.1; Eshell dollar expansion $var[i] not working
2017-03-14 4:03 ` npostavs
@ 2017-06-10 0:33 ` npostavs
2017-06-17 4:17 ` npostavs
0 siblings, 1 reply; 4+ messages in thread
From: npostavs @ 2017-06-10 0:33 UTC (permalink / raw)
To: Chunyang Xu; +Cc: 26055
[-- Attachment #1: Type: text/plain, Size: 404 bytes --]
tags 26055 patch
quit
npostavs@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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 929 bytes --]
From bacbb41ab4d5539d284b1a540e70779a49c00e25 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#26055: 25.1; Eshell dollar expansion $var[i] not working
2017-06-10 0:33 ` npostavs
@ 2017-06-17 4:17 ` npostavs
0 siblings, 0 replies; 4+ messages in thread
From: npostavs @ 2017-06-17 4:17 UTC (permalink / raw)
To: Chunyang Xu; +Cc: 26055
tags 26055 fixed
close 26055 26.1
quit
npostavs@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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-06-17 4:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-11 9:35 bug#26055: 25.1; Eshell dollar expansion $var[i] not working Chunyang Xu
2017-03-14 4:03 ` npostavs
2017-06-10 0:33 ` npostavs
2017-06-17 4:17 ` npostavs
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).