I am using ctags to index my source code. For simplicity, I assemble some sample codes like below.
namespace test_space
{
template<typename TYPE>
class A
{
public:
void test_func(TYPE a);
void test_func_2(TYPE a);
void test_func_3(TYPE a);
}
class B
{
public:
void test_func_b();
}
void easy_func()
{
}
}
I named it as a.h
file, and used ctags a.h
to generate the tags file, but ctags only indexed namespace, classes and functions, but not my class member functions (like test_func
), why? How to enable this?
This is the tags file content generated:
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /[email protected]/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.6 //
A a.h /^class A$/;" c namespace:test_space
B a.h /^class B$/;" c namespace:test_space
easy_func a.h /^void easy_func()$/;" f namespace:test_space
test_space a.h /^namespace test_space$/;" n
It seems that exuberant-ctags by default only adds the tags when it sees a definition, not a declaration. Changing your class A
to
template<typename TYPE>
class A
{
public:
void test_func(TYPE a)
{
}
void test_func_2(TYPE a);
void test_func_3(TYPE a);
};
makes test_func
show up in the tags
file:
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /[email protected]/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.9~svn20110310 //
A a.h /^class A$/;" c namespace:test_space
B a.h /^class B$/;" c namespace:test_space
easy_func a.h /^void easy_func()$/;" f namespace:test_space
test_func a.h /^ void test_func(TYPE a)$/;" f class:test_space::A
test_space a.h /^namespace test_space$/;" n
but the other functions do not show up. I don't use ctags myself, but it makes sense that you usually want to be able to find definitions, not declarations.
If you tell ctags to index protoypes, you can get what you are looking for:
ctags --c-kinds=+p a.h
For your example, this results in
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /[email protected]/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.9~svn20110310 //
A a.h /^class A$/;" c namespace:test_space
B a.h /^class B$/;" c namespace:test_space
easy_func a.h /^void easy_func()$/;" f namespace:test_space
test_func a.h /^ void test_func(TYPE a);$/;" p class:test_space::A
test_func_2 a.h /^ void test_func_2(TYPE a);$/;" p class:test_space::A
test_func_3 a.h /^ void test_func_3(TYPE a);$/;" p class:test_space::A
test_func_b a.h /^ void test_func_b();$/;" p class:test_space::B
test_space a.h /^namespace test_space$/;" n
You can get more details on which things are tagged like this:
$ ctags --list-kinds=c
c classes
d macro definitions
e enumerators (values inside an enumeration)
f function definitions
g enumeration names
l local variables [off]
m class, struct, and union members
n namespaces
p function prototypes [off]
s structure names
t typedefs
u union names
v variable definitions
x external and forward variable declarations [off]
You can see that function prototypes are, by default, not tagged.