zsh-users
 help / color / mirror / code / Atom feed
From: Marlon Richert <marlon.richert@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Oliver Kiddle <opk@zsh.org>, Zsh Users <zsh-users@zsh.org>
Subject: Re: Questions about completion matchers
Date: Sun, 10 Oct 2021 01:12:15 +0300	[thread overview]
Message-ID: <CAHLkEDumxFh=7bLx0geSoL3K-OF9LF447FEzujp_QX1MZ33SMg@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7ZpxduSrwZ101JoRJfEkE_xAnNfd_Lo6BUkaQmuxsiu5A@mail.gmail.com>

On Sat, Oct 9, 2021 at 7:23 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> I think what you've missed is that there are two things being
> examined:  The word on the command line, and the "trial completion",
> that is, the word passed to compadd that might replace the one on the
> command line.  It's not merely (choosing the first of your seeming
> duplications)
>
> > *              b:$lpat=$tpat -> ${word/#$~lpat/$~tpat}
> > *             l:|$lpat=$tpat -> ${word/#$~lpat/$~tpat}
>
> Rather it's
>
> *              b:$lpat=$tpat -> [[ $trial = ${~lpat}* ]] &&
> ${word/#$~lpat/$~tpat}
> *             l:|$lpat=$tpat -> [[ $trial = *${~lpat}* ]] &&
> ${word/#$~lpat/$~tpat}

Perhaps I'm mistaken, but aren't you mixing up $lpat and $lanchor
here? In the docs, it says:

> Matching for lpat and tpat is as for m and M, but the pattern lpat matched on the command line must be preceded by the pattern lanchor. The lanchor can be blank to anchor the match to the start of the command line string; otherwise the anchor can occur anywhere, but must match in both the command line and trial completion strings.

Above, $lanchor is blank and thus needs to match only the start of the
command line string, whereas anything to the right of $lanchor that
matches $~lpat is simply replaced with $~tpat, just as in
m:$lpat=$tpat. Are the docs wrong or am I understanding them wrong?

Thanks, though, for this example, because it does help me understand
what the documentation means with:

> If no lpat is given but a ranchor is, this matches the gap between substrings matched by lanchor and ranchor. Unlike lanchor, the ranchor only needs to match the trial completion string.

Before, it was unclear to me how I should interpret "only needs to
match the trial completion string", but now, I suppose it would be
like this:

l:$lanchor||$ranchor=$tpat -> [[ $trial == *$~lanchor$~tpat$~ranchor*
]] && ${word//(#m)($~lanchor)/$MATCH$~tpat}

However, isn't that equivalent to the following?

l:$lanchor||$ranchor=$tpat -> ${word//(#m)($~lanchor)/$MATCH$~tpat$~ranchor}

Correct me if I'm wrong, but this seems to match the exact same trial
strings. But then, the above transformation would be equivalent to
this one:

l:$lanchor|=$tpat$ranchor -> ${word//(#b)($~lanchor)/$match[1]$~tpat$~ranchor}

Again, something doesn't seem right here.


On Sat, Oct 9, 2021 at 7:23 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
> In the cases with r: and R:, $ranchor is only compared to $trial, it
> is not used when replacing into $word.

Are you sure? The phrase "the ranchor only needs to match the trial
completion string" is listed in the docs for l and L. Conversely, in
the docs for r and R, it says "As l, L, b and B, with the difference
that the command line and trial completion patterns are anchored on
the right side." This makes me believe that, in the case of r and R,
it is in fact $lanchor that is compared only to $trial, not $ranchor.
If your interpretation were correct, l:$lanchor||$ranchor=$tpat and
r:$lanchor||$ranchor=$tpat would be completely equivalent.


Perhaps I should consider the _examples_ in the docs to be the truth
and just ignore the ambiguous wording given earlier on in the docs. If
I do that, then Oliver's examples now start to make sense to me and I
can deduce the transformations as follows:

Given 'r:|.=* r:|=*', c.u becomes c(^*.*).u* and c.s.u becomes
c(^*.*).s(^*.*).u*. Ergo:

* r:$lpat|$ranchor=$tpat  ->
${word//(#b)$~lpat($~ranchor)/($~tpat~*$~ranchor*)$match[1]}
* l:$lanchor|$lpat=$tpat  ->
${word//(#b)($~lanchor)$~lpat/$match[1]($~tpat~*$~lanchor*)}
* r:$lpat|=$tpat  ->  ${word%$~lpat}$~tpat
* l:|$lpat=$tpat  ->  $~tpat${word#$~lpat}

Given  'r:|.=** r:|=*', c.u becomes c*.u*.
Given 'r:|[[:upper:]0-9]=** r:|=*', H becomes *H* and 2 becomes *2*.
Ergo:

* r:$lpat|$ranchor=**  ->  ${word//(#b)$~lpat($~ranchor)/*$match[1]}
* l:$lanchor|$lpat=**  ->  ${word//(#b)($~lanchor)$~lpat/$match[1]*}

Given 'r:[^[:upper:]0-9]||[[:upper:]0-9]=** r:|=*', H becomes
*[^[:upper:]0-9]H* and 2 becomes *[^[:upper:]0-9]2*. Ergo:

* r:$lanchor||$ranchor=**  ->  ${word//(#m)($~ranchor)/*$~lanchor$MATCH}
* l:$lanchor||$ranchor=**  ->  ${word//(#m)($~lanchor)/$MATCH$~lanchor*}

Given 'B:[nN][oO]= M:_= M:{[:upper:]}={[:lower:]}', both _NO_f and
NONO_f become f. Ergo:

* b:$lpat=$tpat  ->  ${word/#(#b)(|?)($~lpat)##/$match[1]$~tpat}
* e:$lpat=$tpat  ->  ${word/%(#b)($~lpat)##(|?)/$~tpat$match[-1]}


How about changing the docs to just literally state the transformation
that each matcher applies? It would be clearer than the prose it
currently contains, which is ambiguous and open to interpretation.


  reply	other threads:[~2021-10-09 22:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-21  9:23 Marlon Richert
2021-09-22 23:25 ` Bart Schaefer
2021-09-26 13:09 ` Oliver Kiddle
2021-10-08 22:38   ` Marlon Richert
2021-10-09 16:23     ` Bart Schaefer
2021-10-09 22:12       ` Marlon Richert [this message]
2021-10-09 22:39         ` Bart Schaefer
2021-10-10 11:17           ` Marlon Richert
2021-10-09 21:59     ` Oliver Kiddle
2021-10-10 12:05       ` Marlon Richert
2021-10-10 20:14         ` Marlon Richert

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='CAHLkEDumxFh=7bLx0geSoL3K-OF9LF447FEzujp_QX1MZ33SMg@mail.gmail.com' \
    --to=marlon.richert@gmail.com \
    --cc=opk@zsh.org \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@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).