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

Re: Completion script for the ctags program



Jacob Gelbman wrote:
> I wrote a completion script for the ctags program. Someone might be able to use it:

Which ctags!?
This doesn't match what I have installed on any of my systems. There
are multiple implementations of ctags, with it often being just a link
to etags - for which there is a completion albeit not a well maintained
one. One of the main reasons, a completion doesn't already exist is
that it would ideally need to detect the variant and at least have sane
fallbacks for variants that aren't handled. It could be useful to check
what the existing _etags is handling - that might be the exhuberant or
emacs variant.

In general, please follow the conventions outlined in
Etc/completion-style-guide in the zsh source distribution. For example,
completion functions usually use just 2 spaces for indentation.

> #compdef ctags
>
> local state

If you use states, you need to also handle the context which means
either passing -C to _arguments and setting up $curcontext or declaring
context local and passing it to later functions like _values.

>     "--alias-<lang>=[add a pattern detecting a name, can be used as an alt name for lang]:pattern" \
>     "--input-encoding-<lang>=[specify encoding of the <lang> input files]:encoding" \
>     "--kinddef-<lang>=[define new kind for <lang>]:kind" \
>     "--kinds-<lang>=[enable/disable tag kinds for <lang>]:kind" \

These would not complete especially helpfully. I suspect that <lang> there is
supposed to be substituted.

> if [ "$state" = "language" ]; then
>     compadd `ctags --list-languages | cut -d" " -f1`

It would be nicer to use a description by calling for example, _wanted
here.

> elif [ "$state" = "languages" ]; then
>     _values -s , "languages" `ctags --list-languages | cut -d" " -f1`
> fi

I'd probably use _sequence here as it is smaller and simpler. But
_values is fine if none of the languages contain characters that need
quoting from it.

The return status from this function will not be correct in all cases.
This can have effects like approximate completion being activated
despite matches having been added by earlier completers. Where states
are needed, you nearly always need to either save the status from
_arguments, typically via a ret variable or check $compstate[nmatches]
on exit.

Oliver




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