[Top][All Lists]

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

[RFC] Behavior of range syntax in Eshell

From: Jim Porter
Subject: [RFC] Behavior of range syntax in Eshell
Date: Fri, 27 Jan 2023 20:44:55 -0800

Recently in bug#60999, I added support for range syntax in Eshell to let you get sub-sequences:

  ~ $ echo $exec-path[1..3]
  ("/usr/local/sbin" "/usr/local/bin")

However, as you can see above, this is a half-open range. Bash, on the other hand, uses a closed range:

  ~ $ for i in {1..3}; do echo $i; done

I opted for a half-open range to match the rest of Emacs Lisp, because that's how functions like 'substring' work. On the other hand, Eshell is a shell-like interface, so maybe using the Bash meaning would be less confusing for users. Does anyone on this list have any strong opinions? As I see it, there are three options:


1. Half-open (the status quo)

I have a soft preference for this, since Eshell lets you call any Emacs Lisp function as a command, so by using half-open ranges, we remain consistent with Emacs Lisp functions. I also find half-open ranges to be a little easier to use. For example, to truncate one list to be the same length as another, I could type:

  ;; or...

With closed ranges, I'd have to type:

  $long-list[..${1- $#short-list}]

That's not a huge difference, but I think it's less convenient.


2. Closed (Bash-style)

This has the benefit of being consistent with Bash (and Zsh, I believe; probably other shells too), so users who are used to those shells will have less to learn in order to be comfortable with Eshell. However, this might set them up for confusion later down the road if they try to treat a function like 'substring' as having a closed range.


3. Use a different delimiter

To make it more obvious that Eshell ranges have a different meaning from Bash ranges, we could use a different delimiter than "..". However, we need to be careful here: If the variable 'foo' is a string, you can split the string with a regexp delimiter in Eshell via: $foo[my-regexp]. That means that we'd want the range syntax to be hard to mistake as a regexp; for example, ":" would be a bad range delimiter, since $PATH[:] would be a common way for users to split the $PATH env var[1]. ".." is a valid regexp, but it's not very useful to use for splitting a string with, so it's probably safe in this regard.[2]


If anyone has any thoughts or other ideas about this, let me know. Like I said, I have a soft preference for the status quo, but if others have a strong opinion about changing this, I don't mind. The way I see it though, Eshell is a part of Emacs, and you can write commands as ordinary Elisp, so following Elisp conventions makes the most sense to me.

If you need any more details on the current syntax, you can check the Eshell manual. Hopefully I've described it reasonably thoroughly.

[1] In practice, you'd probably just want to use $exec-path in Eshell, which is already a list. But this applies to things like $CPATH, etc too.

[2] If you really wanted to split on "..", you'd just need to surround it with quotes so Eshell doesn't interpret it as a range.

reply via email to

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