Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Completion script for the ctags program
- X-seq: zsh-workers 48104
- From: Jacob Gelbman <gelbman@xxxxxxxxx>
- To: Oliver Kiddle <opk@xxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: Completion script for the ctags program
- Date: Tue, 23 Feb 2021 22:45:37 -0600
- Archived-at: <https://zsh.org/workers/48104>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-02/FB722402-2CF7-489A-A968-F79E529E33CF%40gmail.com>
- In-reply-to: <31598-1614116362.902856@aI-l.maGv.3QD7>
- List-id: <zsh-workers.zsh.org>
- References: <CEA9AD4E-D429-43F1-AB41-92B40693B693@gmail.com> <31598-1614116362.902856@aI-l.maGv.3QD7>
Hey, thanks for looking at the script and adding it to the repo, although I think some of got pasted in wrong. There’s a lot to writing completion functions and I’m still not 100% sure how to do it right.
> On Feb 23, 2021, at 3:39 PM, Oliver Kiddle <opk@xxxxxxx> wrote:
>
> Jacob Gelbman wrote:
>> I wrote a completion script for the ctags program. Someone might be able to use it:
>
> Which ctags!?
I have Universal Ctags 5.9.0
> 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.
>
I located a few other ctags on my computers, I have BSD ctags that comes by default on the mac. Exuberant Ctags 5.8. and there’s etags that comes with emacs. I can probably add an if statement based on the output of ctags —version, and modify the function from that. If it’s etags, I’ll just:
_comps[ctags]=“_etags”; _etags
And exit.
> 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.
The -C argument and the context/curcontext variables are confusing me, a lot.
>
>> "--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.
They’d show up in the menu when you press tab, but if I filled in the actual values, the list would be too long.
>
>> 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.
I can do that.
>
>> 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.
This too.
>
> 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