source code navigation using tags is a lifesaver in large projects … i have been using the system for sometime but was vexed with a problem for a long time. i m on ubuntu 8.04 which has the exuberant ctags package available. my makefiles have a phony target called `tags’ that generate the TAGS file to use in emacs. this is how i generate the TAGS file by writing make tags at the command line
tags: find -L $(srcDirs) -name '*.cpp' -o -name '*.h' | etags -L -
when ever i searched for a tag in emacs using M-. i was always taken to the function definition in the .cpp files (source files) but never to the .h files (header files)
the reason for this is two fold
- i practice separation of interface and implementation i.e. the function declaration and function definition are in separate files viz. .h files and .cpp files.
- i did not know the use of –<LANG>-kinds=[+|-]kinds option available with ctags
–<LANG>-kinds=[+|-]kinds is then the key to the solution of this vexing problem. since the language i use is c++ then LANG becomes c++, that is –c++-kinds=[+|-]kinds while kinds for c++ could be any of the following
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
p function prototypes [off]
s structure names
u union names
v variable definitions
x external and forward variable declarations [off]
notice that p (function prototypes) is off by default … which means that etags was skipping over the function declaration in header files… so i could not go to them when searching for a tag. so the solution to my problem is that i should generate tags using the following:
tags: find -L $(srcDirs) -name '*.cpp' -o -name '*.h' | etags --c++kinds=+p -L -
+p simply turns on (+) the tagging of funtion prototypes (p) .
that’s it and happy days r here!