From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 60999@debbugs.gnu.org
Subject: bug#60999: 30.0.50; [PATCH] Add support for negative indices and index ranges in Eshell
Date: Sun, 22 Jan 2023 00:13:16 -0800 [thread overview]
Message-ID: <e8e97c75-e5b2-4b28-a1c1-7de6d304b2e6@gmail.com> (raw)
In-Reply-To: <83zgabjd4v.fsf@gnu.org>
On 1/21/2023 10:29 PM, Eli Zaretskii wrote:
>> Date: Sat, 21 Jan 2023 19:47:47 -0800
>> From: Jim Porter <jporterbugs@gmail.com>
>>
>> I have just one question though: this implementation treats ranges as
>> half-open, i.e. "M..N" is [M, N). I think that's the best way of doing
>> things (and it matches how 'seq-subseq' works). However, "M..N" is the
>> Bash syntax, which uses a closed range, [M, N]. Maybe this would be too
>> confusing for users? [snip]
>
> I think compatibility to other shells is an advantage.
True. Though, in practice I find that the half-open range is easier to
use whenever things become more complex than just using constant values.
For example, truncating a larger list to be the same size as a shorter
one ("$#" means "length of"):
$long-list[..$#short-list]
Using Bash-style closed ranges, you'd have to do:
$long-list[..${1- $#short-list}]
(Note that unlike Bash syntax, I made this so that M and N are optional.
That's another thing we could consider changing.)
Half-open ranges are also more consistent with Emacs Lisp in my
experience. It would be strange (at least to me) to have things like
'seq-subseq', 'add-text-properties', 'substring', etc use one way of
specifying ranges, and Eshell to use another, especially when you can
call any of those functions within Eshell. But like you say,
compatibility with other shells is an advantage too...
In that sense, some non-Bash syntax might be nice. However, Eshell
subscripts are already fairly complex, so we'd need to be careful about
what we choose so that we don't break compatibility. For example, when
subscripting a string, the first element in the subscript can be a
regexp that splits the string, so to get the first element in your PATH,
you could do:
$PATH[: 0]
If ":" was the range separator, this would change meaning. There are
ways to prevent that incompatible change if we're careful, but it's
something to keep in mind. ".." has the advantage that while it's a
valid regexp, it's not very useful in this context, so we probably
wouldn't break anything in practice.
>> +(defcustom eshell-integer-regexp (rx (? "-") (+ digit))
>> + "Regular expression used to match integer arguments."
>> + :type 'regexp)
>
> Why is this a defcustom? what alternative could a user possibly want?
Just for symmetry with 'eshell-number-regexp'. Maybe that shouldn't be a
defcustom either though; if someone wanted to change
'eshell-number-regexp', that's probably a sign that there's a bug, and
the default value should be improved.
Either way we decide about 'eshell-number-regexp', I can turn
'eshell-integer-regexp' into a regular defvar. (The only thing I can
think of that a person would customize it to would be to allow a "+" at
the start of an integer, like "+123".)
next prev parent reply other threads:[~2023-01-22 8:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-22 3:47 bug#60999: 30.0.50; [PATCH] Add support for negative indices and index ranges in Eshell Jim Porter
2023-01-22 6:29 ` Eli Zaretskii
2023-01-22 8:13 ` Jim Porter [this message]
2023-01-27 1:23 ` Jim Porter
2023-01-27 7:38 ` Eli Zaretskii
2023-01-27 18:02 ` Jim Porter
2023-01-27 18:57 ` Eli Zaretskii
2023-01-28 2:15 ` Jim Porter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e8e97c75-e5b2-4b28-a1c1-7de6d304b2e6@gmail.com \
--to=jporterbugs@gmail.com \
--cc=60999@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.