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

Re: Using CVS Completion Functions

Chris Johnson wrote:
> Hi.  A few weeks ago I posted about trying to get a subset of cvs
> completion for a script of mine.  This was the solution I came up with,
> based on Peter's suggestion:
>    _cvs_changed_files() {
>      autoload +X _cvs
>      _cvs_files_modified "$@" || _cvs_files "$@"
>    }
>    compdef _cvs_changed_files cvsvimdiff
> This seemed to work for a while, but occasionally I get this error when
> I try to complete:
>    $ cvsvimdiff my_fi<TAB>_cvs_changed_files:2: command not found:
>    _cvs_files_modified
>    _cvs_changed_files:2: command not found: _cvs_files
> Reading up on autoload, it seems that I should be autoloading not _cvs,
> but _cvs_files_modified and _cvs_files.

_cvs_files_modfied and _cvs_files are within the _cvs function, so you
have to load *and run* _cvs to acquire them, which I missed before.  This
version of _cvs redefines _cvs to the real completion function when it
runs.  Unfortunately, running it has the obvious effect of calling
normal _cvs completion.  There is a truly horrible hack...

autoload +X _cvs

This removes the last line of the initial _cvs function, which happens
to be the one that calls the redefined function.  As the function is
still redefined, future cvs completion will still work fine.

Defining multiple functions in the same body is convenient but
annoyingly limited... there's the additional problem of whether or not
you want to override any existing definition, as witness all the tests
like (( $+functions[_cvs_path_prefixes] )).  It would be nice to have
some mechanism like library files which told the shell to search for
undefined functions in there.  That would take some effort to parse

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


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