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

two anchor forms of matching control (was Re: Improvements to the gcc completion script)



"Jun. T" wrote:
> > It seems 'r:|[_-][^-]=* r:|=*' works _slightly_ better
>
> No. It doesn't work.

It's easiest to view matching controls as converting the command-line
into a pattern. [_-][^-] matches in --b at the second char position and
because this is a right anchor, that's converted to -*-b* (second * is
from cursor position) which in turn matches -foo-bar or --baz.

I'm still inclined to think that 'r:[^-]||-=*' ought to work. Why that
allows --b to match -foo-bar is a mystery to me. 'r:[^-]||-=X' does not
allow it to match -X-b. In general, I wonder if there is some subtlty to
the single * not matching anchors that I've missed.

From experimenting, it would seem that lanchor only needs to match the
trial completion. This is documented for ranchor with l: but it could
be more explicit. I get the impression that the intention at least is
that where * rather than ** is used on the rhs, it is only the ranchor
that it won't insert for r: and lanchor for l:. Again this could be more
explicit in the documentation. The documentation patch also covers that
but this is questionable because, assuming I've understood the intent,
it is most definitely buggy.

The one use of this by Sven was 'r:[^ A-Z0-9]||[ A-Z0-9]=*' 'r:|=*' for
camel case and I think that reflects what it was intended to support.
That allows anything before an initial uppercase character including
other uppercase characters. 'r:|[:upper:]=* r:|=*' tends to work better
in practice but also has quirks (consecutive uppercase)

A good test pattern is
  compadd -M 'r:[A-N]||[O-Z]=* b:=*' ABCDEFGHIJKLMNOPQRSTUVWXYZ
And then various two letter combinations on the command-line. Quite a
few combinations produce results that I can't explain.

Oliver

diff --git a/Doc/Zsh/compwid.yo b/Doc/Zsh/compwid.yo
index 0b98d07b2..3e86d3b42 100644
--- a/Doc/Zsh/compwid.yo
+++ b/Doc/Zsh/compwid.yo
@@ -959,6 +959,9 @@ As tt(l), tt(L), tt(b) and tt(B), with the difference that the command
 line and trial completion patterns are anchored on the right side.
 Here an empty var(ranchor) and the tt(e) and tt(E) forms force the
 match to the end of the command line or trial completion string.
+
+In the form where var(lanchor) is given, the var(lanchor) only needs
+to match the trial completion string.
 )
 item(tt(x:))(
 This form is used to mark the end of matching specifications:
@@ -1022,8 +1025,10 @@ any number of characters in the trial completion. In this case the
 pattern must be anchored (on either side); in the case of a single
 star, the var(anchor) then determines how much of the trial completion
 is to be included DASH()- only the characters up to the next appearance of
-the anchor will be matched. With two stars, substrings matched by the
-anchor can be matched, too.
+the anchor will be matched. With two stars, substrings matched by
+the anchor can be matched, too. In the forms that include two
+anchors, `tt(*)' can match characters from the additional anchor
+DASH()- var(lanchor) with tt(r) or var(ranchor) with tt(l).
 
 Examples:
 




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