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

Re: how to customize _all_matches use?

On Jun 15, 10:25pm, Vadim Zeitlin wrote:
}  I'd like to have a key binding which would complete all matches which I
} would get by pressing TAB at once.
} 	% zstyle ':completion:all-matches:*' completer _all_matches
} However this doesn't seem to work

There's an important bit in the docs under _all_matches:

     Note that this does not generate completions by itself.  First use
     any of the standard ways of generating a list of completions, then
     use ^Xa to show all matches.

} I do get the behaviour I want if I do
} 	% zstyle ':completion:all-matches:*' completer _all_matches _complete
} but with one extremely annoying side-effect:
} 	% ls ^Xa
} 	% ls bar baz foo # this is the same line completed by the shell
} 	bar baz foo
} 	bar  baz  foo
} i.e. although I do get all the completions I also get *2* lists of them
} below.

Nope, that's only one list.  It's a list containing (1) the single match
that was built by _all_matches containing all the other strings at once,
and (2 through 4) the individual matches generated by _complete.

The reason you're getting the listing is because four matches are an
ambiguous situation: zsh doesn't know which of the four you wanted.  It
also inserts the first one because of MENU_COMPLETE (or at least that's
my best guess as to what's happening based on other things you wrote).

} Also, I'd like to not see anything at all if possible. So what am I
} doing wrong?

As far as I can tell, there's no simple way to get what you want, because
you must first generate matches before you can add another match that
consists of all the previous matches; which means you're guaranteed to
get an ambiguous completion (unless there's only one match from _complete
in the first place).  The tag-order style doesn't help here because it's
checked inside _tags and hence inside _complete where the all-matches
tag doesn't yet exist.

So you'll have to play a game like _approximate does, where compadd is
redefined as a function to capture all the matches that other completers
attempt to add, and then don't really add them until the end.  The idea
is to check for the -O/-A/-D options, and if none are present, then add
a -O option for your own array, and in eiher case call through to
"builtin compadd ...".  Finally, in a comppostfunc, remove the compadd
function and call the real compadd with the string resulting from a
join of your array.
} For example, it would be very useful to have for "cvs diff" [...]
} so that pressing TAB after "cvs di" normally completes only the
} modified files. But pressing ^Xa also completes the sub-directories --
} is there any way I could avoid this?

Unfortunately there you're stuck by _cvs_modified_entries which adds
all the entries and subdirectories under the single tag "files".  It has
nothing to do with _all_matches.

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