Can universal-ctags generate a flag in output, describing kind of tag?

195 views Asked by At

I would like to display a type of tag in my tool that parses TAGS file. I.e.: to append "[func]", "[macro]", "[var]", etc. after tag identifiers in some lists that I'm displaying with the tool.

Can Universal-Ctags recognize tag types and store it into output file? If yes, how to run it for this to happen?

1

There are 1 answers

0
Masatake YAMATO On

ctags generates a TAGS file if you specify -e option. TAGS file doesn't include type information.

If you don't specify the -e option, ctags generates a tags file including type information. Your tool can utilize the information.

$ cat input.py 
def f():
    pass
v = []
$ ./ctags --fields=+K input.py 
$ cat tags
!_TAG_FILE_FORMAT   2   /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED   1   /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_EXCMD  mixed   /number, pattern, mixed, or combineV2/
!_TAG_OUTPUT_FILESEP    slash   /slash or backslash/
!_TAG_OUTPUT_MODE   u-ctags /u-ctags or e-ctags/
!_TAG_PATTERN_LENGTH_LIMIT  96  /0 for no limit/
!_TAG_PROC_CWD  /home/jet/var/ctags-github/ //
!_TAG_PROGRAM_AUTHOR    Universal Ctags Team    //
!_TAG_PROGRAM_NAME  Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL   https://ctags.io/   /official site/
!_TAG_PROGRAM_VERSION   5.9.0   /p5.9.20210314.0/
f   input.py    /^def f():$/;"  function
v   input.py    /^v = []$/;"    variable

If you just want to print the names of identifiers and types, you can use -x option of ctags:

$ ./ctags --_xformat='%{name} [%{kind}]' -x -o - --fields=+K input.py 
f [function]
v [variable]