GNU bug report logs - #55838
29.0.50; Eshell string-split subscript indexing splits too much

Previous Next

Package: emacs;

Reported by: Jim Porter <jporterbugs <at> gmail.com>

Date: Wed, 8 Jun 2022 01:37:01 UTC

Severity: normal

Found in version 29.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jim Porter <jporterbugs <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 55838 <at> debbugs.gnu.org
Subject: bug#55838: 29.0.50; [PATCH] Eshell string-split subscript indexing splits too much
Date: Wed, 8 Jun 2022 16:06:45 -0700
On 6/8/2022 6:38 AM, Eli Zaretskii wrote:
> I don't have any objections based on actual experience, and I don't
> know what was the original design goals of this feature in Eshell.
> However, please note that you are changing the behavior significantly,
> and the only reason is that it doesn't make much sense to you.

I probably should have elaborated a bit more on my reasoning in the 
original report. My goal with this (and other Eshell patches in this 
area) is mainly to add tests for some of the more-advanced Eshell syntax 
and also to ensure that it works as documented. There are a few cases 
where it's tricky to decide whether the code is right and the 
documentation is wrong, or vice-versa. This is one of those cases.

Here's what the Emacs 27/28 manuals have to say about this syntax (I've 
already changed/expanded this section in 29, so I'm going back to 28 to 
show what the docs said before I changed them):

  $var[i]

      Expands to the ith 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.

  $var[: i]

      As above, but now splitting occurs at the colon character.

  $var[: i j]

      As above, but instead of returning just a string, it now returns a
      list of two strings. If the result is being interpolated into a
      larger string, this list will be flattened into one big string,
      with each element separated by a space.

I would interpret the above to mean that the only splitting that should 
happen for `$var[: i]' is with the ":". The last section says that 
`$var[: i]' returns "just a string", and `$var[: i j]' returns a list of 
two strings. However, in my example in the original message, `$foo[: 0 
1]' would return a list containing a list and a string. That's 
inconsistent with what the manual says, and in this case I think it's 
the manual that was right, and the code that wasn't.

Note: the last sentence in the manual excerpt above is also incorrect. 
When the list is "flattened into one big string", it will look like 
'("first" "second")', not 'first second'. Unlike the original bug here, 
which people probably don't encounter very often in practice, changing 
how the list is flattened would probably cause problems for users. It's 
a really common occurrence. Something as simple as `echo a b' will 
return '("a" "b")'. This problem is also discussed in bug#12689.




This bug report was last modified 2 years and 347 days ago.

Previous Next


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