Search code examples
ctagsexuberant-ctags

Ctags langmap files with multiple extensions


In our codebase we have some files that are generated by a python script, so they are named cpp_filename.cpp.py, java_filename.j.py, etc. I have setup my ctags to map .cpp files to C++ and .j files to Java, however I can't figure out how to set it up to map .cpp.py files to C++ and .j.py files to Java. If I try to map just .py files to C++, it will also map the .j.py file which I don't want to happen obviously. Is this something I can do with ctags, or is ctags limited in its ability to only look at the last file extension? I am using ctags 5.8


Solution

  • With Universal ctags, an unofficial fork of Exuberant ctags, the following command line may help you:

    $  ctags --options=NONE  --map-Python=-.py --map-Java=+'(*.j.py)' --map-C++=+'(*.cpp.py)' --print-language foo.j.py  ...
    

    You can verify the language choice in Universal ctag with the --print-language option:

    $ touch foo.j.py foo.cpp.py
    $ ctags --print-language foo.j.py foo.cpp.py
    foo.j.py: Python
    foo.cpp.py: Python
    $ ctags --map-Python=-.py --map-Java=+'(*.j.py)' --map-C++=+'(*.cpp.py)' --print-language foo.j.py foo.cpp.py
    foo.j.py: Java
    foo.cpp.py: C++
    

    With Exuberant ctags, I cannot find a solution.

    I expected ctags --options=NONE --map-Python=-.py --map-Java=+'.j.py' --map-C++=+'.cpp.py' --print-language foo.j.py foo.cpp.py works expectedly. However, it doesn't work well. It may be a bug of Universal ctags.