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

Re: Should we be avoiding "zstyle -m" ?



> On 07/01/2024 20:06 GMT Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 
>  
> 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 -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?

pws




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