Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Re: Should we be avoiding "zstyle -m" ?



On 1/9/24, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Mon, Jan 8, 2024 at 8:52 AM Peter Stephenson
> <p.w.stephenson@xxxxxxxxxxxx> wrote:
>>
>> > On 07/01/2024 20:06 GMT Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
>> > wrote:
>> >
>> > on a quick glance at the code I think they may be identical (that is,
>> > that
>> >   zstyle -L ":completion:$curcontext"
>> > would give the desired result), but there's a lot going on in there.
>> >
>> > So what to do here?  Ideas that occur to me ...
>> >
>> > 2) Add a -q option to -L, to exit 0 or 1 on found or not found,
>> > without printing.
>>
>> The -q and -L combination sounds like it ought to be reasonably easy
>> (pass through a flag to suppress output) and ought to be quite flexible
>> as -L already has a lot of search configurability built into it, maybe?
>
> Sadly all zstyle options are singletons, that is, it doesn't use the
> normal option parsing but only looks at argv[0][1].  Combining options
> is not friendly.
>
> Also -L acts more like -g than like -m, and what's wanted here is -m.
> That is, -L doesn't apply the zstyle pattern to the context, it treats
> the context as a pattern (which is why the doc calls it a
> "metapattern") and looks for a zstyle pattern that matches it.  Which
> could be shoehorned into working, I guess, but is not straightforward
> for this use case.
>
> So amend the above to say "add a -q option that acts like -m except ..."

I don't understand what the \ does in your context argument for zstyle
-m, I took a look at the docs and found nothing that explains it:
  zstyle -m context style pattern
    Match a value. Returns status zero if the pattern matches at least one
    of the strings in the value.

This doesn't imply that the context argument is treated differently
than in any of the other forms?

Using the code in url-quote-magic as an example, in a new shell the
following returns 1(false) which is expected:
zstyle -m ':url-quote-magic:\*' url-metas '*'
and after running the following, it returns 0(true), also expected:
zstyle ':url-quote-magic:*' url-metas '*?[]^(|)~#{}='

but the \* seems to just be taken literally, so for example the
following also now returns true:
zstyle -m ':url-quote-magic:asasadsaf' url-metas '*'
This makes me suspicious that maybe the code doesn't at all do what
the author expected it to do? It is of course more likely that I am
the one that's confused, the point is I don't understand what the \ is
supposed to accomplish, if anything it just seems misleading.

I am slightly more confident in my view after the following experiment
(again a new shell):
% zstyle ':url-quote-magic:\\*' url-metas '*?[]^(|)~#{}='
% zstyle -m ':url-quote-magic:\*' url-metas '*' && echo true
true

So if I've set the url-metas style for the \\* context, the code will
now override whatever my url-metas style was set for in the * context
which is bad.

On a more general note, I think the whole approach is wrong and we
should never set a style if we think it's empty; just use the fallback
value when you look up the style and it was empty later on in the
code, that will never have weird subtleties like this.

-- 
Mikael Magnusson




Messages sorted by: Reverse Date, Date, Thread, Author