zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCH] Re: Should we be avoiding "zstyle -m" ?
Date: Tue, 9 Jan 2024 10:17:38 +0100	[thread overview]
Message-ID: <CAHYJk3RKRE5QW-E9_r2gJtncxqG9fkq5Oh1rr6f9rc6CEY7ziQ@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7aEubWMxOAUh6yaq9vzzUKXdXZozr9BjmQ5RtbKccpYAA@mail.gmail.com>

On 1/9/24, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mon, Jan 8, 2024 at 8:52 AM Peter Stephenson
> <p.w.stephenson@ntlworld.com> wrote:
>>
>> > On 07/01/2024 20:06 GMT Bart Schaefer <schaefer@brasslantern.com>
>> > 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


  reply	other threads:[~2024-01-09  9:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-07 20:06 Bart Schaefer
2024-01-08 16:52 ` Peter Stephenson
2024-01-09  4:22   ` [PATCH] " Bart Schaefer
2024-01-09  9:17     ` Mikael Magnusson [this message]
2024-01-09 18:30       ` 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=CAHYJk3RKRE5QW-E9_r2gJtncxqG9fkq5Oh1rr6f9rc6CEY7ziQ@mail.gmail.com \
    --to=mikachu@gmail.com \
    --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).