zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: _arguments optspecs (was Re: Editing the history in the shell)
Date: Mon, 25 May 2020 19:29:02 +0200	[thread overview]
Message-ID: <71744-1590427742.474587@WgsI.yCFx.n5vu> (raw)
In-Reply-To: <CAH+w=7ZxOQQCwzCzYm6NX1NP-HPspACV_Yf56b0O3VZP=jsfPA@mail.gmail.com>

Bart wrote:
> On Sat, May 23, 2020 at 2:30 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
> >
> > I'm not entirely sure about some
> > of the _zed optspecs, but all the desired combinations seem to work
> > and all the undesired ones seem not to.

How about the following combination:

zed -f -x2 -- <tab>

> My uncertainty is around these three lines:
>
> >      '(- 2):file:_files' \
> > +    '(-f -x 1)-h[edit history]:history file:_files' \
> > +    '2:history size: ';;
>
> The first spec causes "file" to be offered (as the first non-option
> argument)  if there is no option yet, and will not offer a second
> argument.

The first thing to note is that if you leave the number out as in the
first spec, it will assign it the next number. So the 1 in the exclusion
list for -h does apply to the first spec. I try to avoid leaving the
number out for any spec that is the target of an exclusion.

> The second spec offers -h followed by "history file" as the argument
> to -h, and won't offer -f or -x or a first non-option argument.

Yes. And in excluding the first non-option argument, it will move on and
offer the second one in the first position. So you get "history size" in
position 1 despite it being labelled as 2.

> What's strange is why "history size" is the second non-option
> argument.  If I leave (1) out of the exclusion list on the second
> spec, I get offered "file", so in that case the argument to -h is
> being taken as an option argument; but after filling in that position
> I next get "no more arguments" instead of "history files".  So it
> appears that sometimes the argument of -h is not counted as a
> non-option argument, and other times it is so counted, which is why
> it's "2:" in the third optspec and the (1) is required in the second
> optspec.

I can't find any arrangement of words on a command-line that gives the
argument after -h as being anything other than "history file". Neither
is it being counted as one of the non-option arguments.

> Does anybody actually understand this?  Is it explainable (or already
> explained, where?) in the doc for _arguments?

It seems clear enough to me but I know enough of the implementation's
workings to be approaching it from that angle. Which may not mean I'm
best able to explain it.

There's a list of possible states. In each state, individual specs
are disabled if an option is found which would disable it. If you
exclude positional arguments, subsequent ones become active at an
earlier position. So you can exclude lots of them and there is always
something to complete. Having gaps is fairly useless as is apparent if
you try: compdef "_arguments '3:three'" foo
This approach may not be the most readable but I think it works:

	'(-h 1 3 4)-f[edit function]' \
	'(-h 1 3 4)-x+[specify spaces to use for indentation in function expansion]:spaces' \
	'(-f -x 1 2)-h[edit history]' \
	'(- 2 3 4)1:file:_files' \
	'(3 4)2:shell function:_functions' \
	'3:history file:_files' \
	'4:history size';;

Oliver

  reply	other threads:[~2020-05-25 17:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-22 22:24 Editing the history in the shell Bart Schaefer
2020-05-23  2:28 ` Daniel Shahaf
2020-05-23 21:30   ` Bart Schaefer
2020-05-24 22:02     ` _arguments optspecs (was Re: Editing the history in the shell) Bart Schaefer
2020-05-25 17:29       ` Oliver Kiddle [this message]
2020-05-25 22:32         ` Bart Schaefer
2020-05-26  7:56           ` Oliver Kiddle
2020-05-25 22:42         ` Bart Schaefer
     [not found]     ` <20200525023515.7855610a@tarpaulin.shahaf.local2>
     [not found]       ` <CAH+w=7bTCCC2XBr+_HCAPqXWuOV_YOrDv+36C6jJScKrxZjhLQ@mail.gmail.com>
2020-05-27  3:32         ` Fwd: Editing the history in the shell Bart Schaefer
2021-04-25 21:56           ` [PATCH] " Bart Schaefer

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=71744-1590427742.474587@WgsI.yCFx.n5vu \
    --to=okiddle@yahoo.co.uk \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.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 public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).