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

Re: completion with globbing, take 2



On Sep 18, 10:08pm, Andrej Borsenkow wrote:
} Subject: RE: completion with globbing, take 2
}
} > Not quite; he's written a stripped-down version of "_expand with the
} > completions style defaulted to true, followed by _match".
} 
} I tentatively disagree. The main difference between _expand and
} _match is who generates matches. Completion aside, _expand generates
} "matches" (that are actually expansions in this case) itself.

Not when the completions style is set.  Then it assigns compstate[insert]
and returns, leaving it to the following completers to generate matches.

} _match takes all possible completions and tries to match them against
} given pattern. See the difference?

Yes, but ... _match doesn't "take" anything; it, too, calls _complete,
maybe more than once, with different values of compstate[pattern_match].

Try this in zsh -f:

zstyle ':completion:*' completer _expand _match
zstyle ':completion:*' completions true
autoload -U compinit ; compinit -D

and then look at a trace from ^X?.  The only interesting things that
happen before _complete is called are assignments to compstate[insert]
and compstate[pattern_match], exactly as in Jay's little function.

} To write stripped-down version of _expand means [...]

I didn't say "stripped-down version of _expand", I said "stripped-down
version of _expand with the completions style defaulted to true", which
takes a completely different code branch.

} As I wrote, it is just a coincidence that file completion is using the same
} pattern from command line, hence _expand and _match look alike.

I'd mostly agree with you if _match were replaced by _complete in the
style above.

} BTW thank you all for finally making it clear to me :-)))

It's getting a lot clearer to me, too ...
 
} > The most obvious thing would be to have _match itself recognize the
} > completions style.
} 
} Is is not enough. See later.

Not enough for what?

} O.K. about adding completions style to _match. Note, that if
} completions style is set for _expand it just calls _complete.

No.  If the completions style is set for _expand it doesn't call anything.
It only calls _complete in the expand-word:* context; we're talking about
the :completion:* context.

} If no matches were generated, it does it itself and now has full
} control over possible tags.

No, it always returns without doing anything itself when the completions
style is set.  expand-word:* just determines whether it returns success,
otherwise it always returns failure.

} But what we actually need, is to get completions that _complete just
} generated

No, we just need to call complete and let it generate things, just like
_match always does.  We just have to tell _complete to insert everything
that it generates.  Try the following patch with

zstyle ':completion:*' completer _match
zstyle ':completion:*' completions true
bindkey '\t' complete-word

(Arguably "completions" is not the best name for this style as it's used
here, but for purposes of example ...)

Index: Completion/Core/_match
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-3.1/Completion/Core/_match,v
retrieving revision 1.14
diff -c -r1.14 _match
--- Completion/Core/_match	2000/04/11 15:07:44	1.14
+++ Completion/Core/_match	2000/09/19 01:58:57
@@ -20,6 +20,7 @@
 
 zstyle -s ":completion:${curcontext}:" match-original orig
 zstyle -b ":completion:${curcontext}:" insert-unambiguous ins
+zstyle -t ":completion:${curcontext}:" completions && compstate[insert]=all
 
 # Try completion without inserting a `*'?
 


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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