Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Completion script for the ctags program
On Wed, 2021-03-03 at 14:39 -0600, Jacob Gelbman wrote:
> I got a little bit hung up on one of the points, which was what to do
> about option names that can include the language such as
> —alias-<lang>, —extras-<lang>, —fields-<lang>, —input-encoding-<lang>,
> and many more. If I actually added what the <lang> could be, the
> listing would be too long to read. I like it to just show the format
> of the option, just so you can see it in the listing when you press
> tab, but not overwhelm the output.
I suspect this is over the over the top, but I'll send it anyway in case
there are some hints here...
It's starting to get complicated, but you could treat the <lang> as an
argument to complete until there's a non-zero string there, then
treat -alias-blah matched from the command line as the option. That's
significantly more work, though, well beyond just a first pass using
_arguments, but it is doable.
With the version I have (Emacs), you can generate a list by running a
function like the one below. That would need a version guard and also
combining with the usual _call_program set up you'll see in a lot of existing
functions. It doesn't work directly for the case you're after (though it
could complete the language for the Emacs version) because you're talking
about a different version of ctags, but it might give some ideas.
pws
_ctags_languages() {
integer found
local -a match mbegin mend
ctags --help | while IFS= read -r line; do
[[ $line = *"supported languages"* ]] && found=1
if (( found )); then
if [[ $line = (#b)[[:space:]]##([^[:space:]]##)* ]]; then
print $match[1]
found=2
elif (( found == 2 )); then
found=0
fi
fi
done
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author