Ctags - pass option for different categories of lookup

I missed the [<Tab> command from Vim, which is used to find C function declarations in header files.

I found that Universal Ctags could record different classes of occurrences of symbols. My idea was to generate a tags file that had separate entries for the declarations.

After some experimenting, I found that ctags *.[ch] ; ctags -a --kinds-c='{prototype}' *.h worked to generate a tags file with this information. Then you can look up declarations with readtags, as in readtags -Q '(eq? $kind "p")' FUNCTION.

However, I had difficulty passing these extra options to readtags. ctags.kak has a line

${kak_opt_readtagscmd} -t "$tags" "$tagname"

- but it appears to be impossible to place an argument like -Q '(eq? $kind "p")' inside a shell variable. The problem is that the single quotes are not interpreted in the right way by the shell after expansion of the variable, leading to the arguments containing quote characters and being split incorrectly. So using set window readtagscmd %{readtags -Q '(eq? $kind "p")'} in my kakrc did not work.

So I found an alternative approach, which was to use two separate tags files, I generate them with

ctags *.[ch] ; ctags -f tag.prototype --kinds-c='{prototype}' *.h

Then in my kakrc, I have two commands:

define-command my-ctags-search %{
    set window ctagsfiles 'tags'

define-command my-ctags-search-prototype %{
    set window ctagsfiles 'tags.prototype'

map global normal <c-]> <a-i>w:my-ctags-search<ret>
map global user   -docstring 'ctags find prototype' <c-]> <a-i>w:my-ctags-search-prototype<ret> 

However, it would provide more flexibility if there was some way of doing it the first way, allowing passing arguments to readtags. This would make more functionality available.

The easiest thing to do would just be to make a wrapper shell-script somewhere on your $PATH, called something like readtags-prototypes, that looks like:

readtags -Q '(eq? $kind "p")' "$@"

…and then you can set the readtagscmd option to readtags or readtags-prototypes as appropriate.

Good idea, that would work.