zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Oliver Kiddle <okiddle@yahoo.co.uk>
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 15:32:50 -0700	[thread overview]
Message-ID: <CAH+w=7aaZCLsnd5c0AaWD5AmmibGwy47xnibhXwu-osv-zBfDA@mail.gmail.com> (raw)
In-Reply-To: <71744-1590427742.474587@WgsI.yCFx.n5vu>

(Thanks for copying me, that got around gmail's blocking list-forwards
of yahoo.)

On Mon, May 25, 2020 at 10:29 AM Oliver Kiddle <okiddle@yahoo.co.uk> wrote:
>
> > On Sat, May 23, 2020 at 2:30 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
> > >
> > > all the desired combinations seem to work
> > > and all the undesired ones seem not to.
>
> How about the following combination:
>
> zed -f -x2 -- <tab>

Ah, I didn't notice that

zed -f _zed -x2

is not accepted by zed itself.

> > My uncertainty is around these three lines:
> >
> > >      '(- 2):file:_files' \
> > > +    '(-f -x 1)-h[edit history]:history file:_files' \
> > > +    '2:history size: ';;
>
> 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.

Do I understand, then, that you would have written the original
        '(- 2):file:_files' \
        '(1):shell function:_functions'
as
        '(- 2)1:file:_files' \
        '(1)2:shell function:_functions'
??  I can see where that might have puzzled me less.

> > 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.

OK, that explains my confusion then.  Why does it do that?  If I
wanted to indicate that _arguments was NOT meant to "move on and offer
the second one in the first position", would I have to write
        '(1)2:history file: '
??  Or is there a way to say "exactly the Nth position" without also
specifying the (N-1)th position?

> > 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.

"count the argument after -h as a non-option argument" and "offer the
second one in the first position" have equivalent results from the
point of view of a black-box test.  I just didn't know how to explain
what I was seeing.

> 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.

Is that "subsequent" part stated in the doc anywhere that you can point to?

>         '(-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';;

I would never have thought of that, because without the implicit
"become active earlier" there is no third or fourth position.

Perhaps the way to explain/understand this is that "position" here
does not mean "position on the command line", rather it means "order
in which to attempt to fill the next available position on the command
line".

  reply	other threads:[~2020-05-25 22:33 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
2020-05-25 22:32         ` Bart Schaefer [this message]
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='CAH+w=7aaZCLsnd5c0AaWD5AmmibGwy47xnibhXwu-osv-zBfDA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=okiddle@yahoo.co.uk \
    --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).