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

Re: matcher-list question

On Tue, 27 Nov 2007 09:56:53 +0000
Peter Stephenson <pws@xxxxxxx> wrote:
> Andy Spiegl wrote:
> lama:~>zsh -f
> lama% autoload -U compinit; compinit -C
> lama% zstyle ":completion:*" matcher-list 'r:|[-./_]=* r:|=*' '+l:|=*'

Note that

  zstyle ":completion:*" matcher-list 'r:|[-./_]=* r:|=* l:|=*'

shows the same problem slightly more simply.

> lama% ls         
> foo-bar-abc  foo-bar-def  foo-bar-geh
> lama% ls bar<TAB>
> lama% ls -foobar-
> There's a bug somewhere in the code that assembles partial lines using
> matching in this fashion (the code that generates the lists seems to be
> OK, or at least the list of matches is correct).

I've got at least somewhere...

This is mostly for my benefit, in case I forget.  I can't imagine
anyone else taking the slightest bit of interest.

add_match_part() in compatch.c is responsible for assembling the bits of
the match ("cline" structures), including prefixes, anchors, and
suffixes.  In the case in question,  "-" is the anchor with "foo"
as a prefix.  However, the code at line 352,

    if (m && (m->flags & CMF_LEFT)) {
	lp->flags |= CLF_SUF;
	lp->suffix = lp->prefix;
	lp->prefix = NULL;

kicks in because this is a left anchor, which swaps the suffix and the
prefix.  I confirmed that commenting out this code gets the completion
right in this particular case (with no obvious side effectis, though it
presumably screws up in other completions or with other matchers).

Still to understand: where left anchoring is actually coming in seeing
as the "-" in the matcher in use is in an expression which is marked as
a right anchor (yes, I checked that even in Svenland an 'l' in the
matcher is associated with CMF_LEFT).  The only left anchor is the
'l:|=*', which anchors to the start of the command line; it should be
this that's matching the "foo" because it's only matched by virtue of
the wildcard at the start of the line, but I don't see why it's handling
the first "-".  If I could understand why the "-" appeared here instead
of associated with a matcher with CMF_RIGHT, I might get further.

However, that's quite enough for one night.

Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/

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