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

Re: zstyle: "more specific" patterns and *-components



On 27 Apr 2020, at 05:14, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> However, going by the documentation I expected ':foo:*:baz:*' to be
> considered more specific than ':foo:bar:*' (because it contains more
> components: 'three literal strings and two asterisks' is more than
> 'three literal strings and one asterisk'), and therefore, 'hello' to be
> printed regardless of the order of the first two lines.

I've actually had something about this in my drafts for a few months now.
Pasting here in full:

  Re: workers/45413, i was going to change ":completion:${curcontext%}:*" to
  ":completion:*:${service}:*", reasoning that that would be the best way to
  ensure that the fall-back style doesn't override the user's.

  But that isn't actually guaranteed — when calculating the weight of a style,
  zstyle adds 0 for each component consisting of only *, such that
  :foo:*:bar and :foo:*:*:*:bar are equally weighted, and which one wins
  depends on the order they were defined.

  The documentation says:

    For ordering of comparisons, patterns are searched from most specific to
    least specific, and patterns that are equally specific keep the order in
    which they were defined. A pattern is considered to be more specific than
    another if it contains more components (substrings separated by colons)

  I suppose * isn't really a 'substring' in this context, but it still seems
  like the pattern with more :*: should win based on there being more
  components, doesn't it?

  I'm guessing that * is weighted 0 so that :foo:* doesn't have more weight
  than :foo:, but could it work better? For example, might it work to change
  the weighting to this:

    0  First consecutive *-only component (first * in :foo:*:*:bar*)
    1  Subsequent consecutive *-only component (second * in :foo:*:*:bar*)
    2  Pattern component (bar* in :foo:*:*:bar*)
    3  Literal component (foo in :foo:*:*:bar*)

  ?

But i don't think my suggested change will fix the case you described. Maybe
give each *-only component a weight of 1 unless it's at the very end? Haven't
really thought about it since i wrote that, so there might be other
considerations

dana



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