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

Re: Questions about completion matchers

On Tue, Sep 21, 2021 at 2:23 AM Marlon Richert <marlon.richert@xxxxxxxxx> wrote:
> How can I make a matcher that completes the right-most part (and only
> the right-most part) of each subword?

I would not try to do this with a matcher specification ... someone
else (Oliver?) may be able to give a more accurate answer, but I don't
think matchers are very good at splitting up words unless there is an
anchor character ("." or "-" for example) to subdivide the words.  I
know there's an example that purports to handle a similar situation,
but the more you want to constrain it ("only the right-most part") the
uglier it gets.

Instead I'd probably write a completer function that creates a
modified words array using match-words-by-style, then compset the
appropriate prefix and suffix.  But I haven't gone very far down that

> * What is the exact difference between l:lanchor||ranchor=tpat and
> r:lanchor||ranchor=tpat ?

Again I'm not the ultimate expert here, but "lanchor" always has to
appear on the command line and with "l:" it has to appear to the left
of the matched substring (but not inside it) and with "r:" it has to
appear to the right of the matched substring (but again not inside
it).  In both cases ranchor has to appear in the potential completion
result (the "trial completion") but might bound a range on the command
line if it does match there.

In practice I've nearly always seen these to be empty strings.

> * Why do the examples in the manual add r:|=* to the end of each
> matcher? This appears to make no difference at all.

All of my real-life uses are "r:|=**" ... I don't know the answer to this one.

> * How are the match descriptions inside a matcher evaluated
> and what causes the difference between these?

I believe they're applied left to right and each one constrains the
possibilities seen by the next, based on what's already on the command
line when you invoke completion.

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