zsh-workers
 help / color / mirror / code / Atom feed
* Should we be avoiding "zstyle -m" ?
@ 2024-01-07 20:06 Bart Schaefer
  2024-01-08 16:52 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2024-01-07 20:06 UTC (permalink / raw)
  To: Zsh hackers list

I'm the main culprit here, using zstyle -m to test whether a style
exists before asserting a default, something I first did in
url-quote-magic 20 years ago -- but recently while working on
something else I realized that -m invokes code defined by zstyle -e,
which may be inappropriate at the point where the test appears.

One alternative is to use zstyle -g, but that retrieves only a
specific pattern rather than matching a context.  The other
possibility is zstyle -L, which requires capturing stdout because -L
always returns zero, and further it's uncertain whether the
metapattern matched by -L is similar enough to a context match.  Based
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 ...

1) Allow -L and -g to be combined, to return the list in an array
instead of printing it.
2) Add a -q option to -L, to exit 0 or 1 on found or not found,
without printing.
3) Add an option to -m to only match the context, without interpreting
the value.  Maybe -n ?  In every case where -m is currently used in
Functions/ and Completion/, the value to match is '*'.
4) Variant of #3, which is to skip interpreting the value when
searching for '*' ... but it's possible someone is depending on -e
evaluating with -m.
5) Add an option to go along with -a/-b/-s that installs the style
only if it's not already there.  This still runs the risk of adding a
more-specific style that overrides a user's generic style covering the
context ... unless this new option also takes a context as an
argument?  Which gets ugly.

The first two require altering the way scanhashtable() is used.  The
third and fourth alter the way that lookupstyle() works.

Any thoughts?


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-09 18:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-07 20:06 Should we be avoiding "zstyle -m" ? Bart Schaefer
2024-01-08 16:52 ` Peter Stephenson
2024-01-09  4:22   ` [PATCH] " Bart Schaefer
2024-01-09  9:17     ` Mikael Magnusson
2024-01-09 18:30       ` Bart Schaefer

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