Search code examples
c++vimctagsexuberant-ctags

Avoid C++ object files from being added to Ctags tags file


I had used the following command to generate my tags file to be used by vim in a C++ project:

ctags -R --c++-kinds=+p --fields=+iamS --extra=+fq --language-force=C++ /usr/include /home/user/audioprism/lib/essentia/ --exclude=.git --exclude=/home/user/audioprism/lib/essentia/src/examples -f /home/user/audioprism/tags

In a certain case I see the following:

# pri kind tag               file
> 1 F   v    Pool              
/home/user/audioprism/lib/essentia/bui...ia/streaming/algorithms/poolstorage.cpp.1.o               
/
  2 F   c    Pool              /home/user/audioprism/lib/essentia/src/essentia/pool.h
           namespace:essentia
           class Pool {
  3 F   v    Pool              
/home/user/audioprism/lib/essentia/src/examples/tutorial/example_onsetdetection.py
           from essentia import Pool, array

So, a :ta or <Ctrl>+] takes me to poolstorage.cpp.1.o, being the first entry. But how to avoid object files being added. Since the whole purpose is to navigate through the source code, I would like to avoid this situation. Tried the flag --exclude=*.o but that didn't help either.

How can I stop the object files from being added to tags file?


Solution

  • Do you really need --langage-force? My experiments with lh-tags and my everyday work on C++ projects taught me that ex-ctags and universal-ctags are already able to sort out C++ files on their own based on the extension. I may use this parameter when running ctags on a temporary (extension-less) file where I've dumped the content of the current buffer. I don't need it otherwise to parse normal C++ files. We may also need it to parse the extension-less header files from the C++ standard library. I highly doubt this is what you are doing.

    Eventually, we can simply restrict the analysis to specific languages instead. Its the --languages= option with Universal Ctags (I don't remember what it is (/was) with the deprecated Exhuberant Ctags. I'd have to delve into the code of my lh#tags#add_indexed_ft() (vimscript) function. But honestly, if you're using ex-ctags, migrated to universal-ctags, in particular if you work with C++).

    Using this option would also prevent ctags from parsing Python files as if they where C++ files. And you could also ask Python files to be parsed, or not.