Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Programmatically loading completion for another command?
On Fri, May 27, 2022 at 12:58 PM Vorpal <zsh@xxxxxxxxx> wrote:
>
> > Bart Schaefer wrote on Fri, 27 May 2022 17:03 +00:00:
> >>
> >> service=makepkg _sequence $_comps[makepkg]
>
> Thanks a lot! That works mostly as expected. There is one issue in that
> exclusivity in the argument completion of makepkg is ignored.
It looks like _sequence assumes that whatever function it calls will
understand the -F -S and -r options of compadd (and won't fail if
passed them anyway). Most of the uses of _sequence in the Completion/
tree are "_sequence compadd ..." and several others call functions
that eventually just do "compadd $@ ...". For a completion function
that uses _arguments to have any hope of working with this, it would
at least have to include something like
local -a compadd_args=( "$@" )
...
_arguments ... -O compadd_args ...
and even that might not work in many cases, because _arguments doesn't
pass those options to every possible compadd.
A helper function for _sequence could be created to assist with this.
> However it seems to me that a generic helper on the following form would
> a useful addition to the standard zsh distribution in that case:
>
> _complete_for()
> {
> service=$1 $_comps[$1]
> }
If you have a wrapper, you might as well go all the way:
_complete_for () {
local service=$1
shift
local compadd_args=(${(q)@})
{
eval "function compadd { builtin compadd $compadd_args \"\$@\" }"
$_comps[$service]
} always {
unfunction compadd
}
}
That needs some work to avoid conflicting with other helpers that
redefine compadd, but seems to get the basic job done.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author