zsh-workers
 help / color / mirror / code / Atom feed
From: "Daniel Shahaf" <d.s@daniel.shahaf.name>
To: "Bart Schaefer" <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org, "Thomas Gläßle" <thomas@coldfix.de>
Subject: Re: Path with spaces in _canonical_paths
Date: Wed, 23 Nov 2022 22:24:35 +0000	[thread overview]
Message-ID: <aa2462d2-468f-4b76-a36d-35a08dc975a9@app.fastmail.com> (raw)
In-Reply-To: <CAH+w=7ZOw2kKzVy3CwqgQEgZRX8agxic1VQqh4mB642ayKz0aQ@mail.gmail.com>

Bart Schaefer wrote on Wed, 23 Nov 2022 21:36 +00:00:
> On Wed, Nov 23, 2022 at 6:14 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>>
>> Bart Schaefer wrote on Mon, Nov 21, 2022 at 13:32:41 -0800:
>> > On Mon, Nov 21, 2022 at 9:41 AM Thomas Gläßle <thomas@coldfix.de> wrote:
>> > >
>> > > +  local -a tmp_buffer
>> > > +  compadd -A tmp_buffer "$__gopts[@]" -a files
>> > >  [...]
>> > > +    matches+=( "${(@)tmp_buffer/$canpref/$origpref}" )
>> > >     else
>> > >       # ### Ideally, this codepath would do what the 'if' above does,
>> > >       # ### but telling compadd to pretend the "word on the command line"
>> > >       # ### is ${"the word on the command line"/$origpref/$canpref}.
>> > > -    matches+=(${${(M)files:#$canpref*}/$canpref/$origpref})
>> > > +    matches+=(${${(M)tmp_buffer:#$canpref*}/$canpref/$origpref})
>> > >     fi
>>
>> The comment quoted above concerns how the candidate completions are
>> compared to the word on the command line.  The comment says that,
>> instead of applying s/foo/bar/ to the word on the command line and
>> comparing the result against the raw candidate completions, the reverse
>> is done — s/bar/foo/ is applied to the candidate completions and that's
>> compared to the raw word on the command line
>
> Hrm, but in both cases (even before the diff) the substitution is
> s/$canpref/$origpref/ ?  Your explanation here would seem to imply
> that in at least the second case the substitution should look like
> s/$origpref/$canpref/.

Yes.  That's why the comment says s/$origpref/$canpref/ rather than
s/$canpref/$origpref/ as the code in HEAD says.

Perhaps an analogy.  Imagine a function that takes an unmetafied string
and an array of metafied strings and has to return 0 or 1 according to
whether or not the string is in the array, using nothing but strcmp()
for comparisons.  The function should either metafy the string or
unmetafy each string in the array in order, then.  (This analogy falls
short of explaining why one approach is better than the other.)

> The difference is that in the first case
> $tmp_buffer is the result of filtering with "compadd ... files" and in
> the second case we're altering the elements of $files directly.
>
>> Adding or removing -Q or {(@)} (or ${(b)}, cf. workers/39080) might well
>> be independent of that issue, though.
>
> I believe the difference here is also compadd -- it performs the
> quoting changes that -Q then has to account for.  So when we modify
> $files directly in the second branch, we have to also emulate the
> quote behavior of compadd.  My previous suggested patch perhaps didn't
> go far enough in that direction?

I'm not sure off the top of my head.  Perhaps that patch needs an extra
${(q)} somewhere?  Or perhaps we should add -Q to the if() codepath?
What do callers expect?

In general, I think the metafy analogy is valid here: we should define
whether $matches contains raw values or quoted values (and perhaps also
which form of quoting is used — presumably ${(q)}) and then ensure that
both branches conform to that internal API, just like for any char*
variable we define whether it's metafied or not.

Cheers,

Daniel


  reply	other threads:[~2022-11-23 22:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 17:41 thomas
2022-11-21  3:57 ` Bart Schaefer
2022-11-21 10:47   ` thomas
2022-11-21 16:30     ` Bart Schaefer
2022-11-21 17:41       ` Thomas Gläßle
2022-11-21 21:32         ` Bart Schaefer
2022-11-23 14:13           ` Daniel Shahaf
2022-11-23 21:36             ` Bart Schaefer
2022-11-23 22:24               ` Daniel Shahaf [this message]
2022-11-23 22:42                 ` Bart Schaefer
2022-11-23 23:06                   ` Daniel Shahaf
2022-11-23 23:12                     ` Bart Schaefer
2022-11-24  0:12                       ` Daniel Shahaf
2022-11-24 18:42                         ` Bart Schaefer
2022-11-23 23:36                   ` Thomas Gläßle
2022-11-23 23:40                     ` Thomas Gläßle
2022-11-24 18:51                     ` 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=aa2462d2-468f-4b76-a36d-35a08dc975a9@app.fastmail.com \
    --to=d.s@daniel.shahaf.name \
    --cc=schaefer@brasslantern.com \
    --cc=thomas@coldfix.de \
    --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).