possible work-around to find variable definitions
http://www.gnu.org/software/global/plans.html has this line:
Treat variable definitions as a definition tag (GTAGS).
I interpret this to mean that gtags currently does not yet support variable definitions, i.e., ggtags-find-definition will not work for C/C++ global variables, e.g.,
int some_global_variable;
My experiments indicate that this is indeed the case. Trying to jump to any global variable via ggtags-find-definition fails and "Global found 0 definitions" is printed in the mini-buffer.
Is this indeed the case, i.e., GNU global cannot find variable definitions?
If so, I would like to implement a work-around to this problem via using etags as a backup since the built-in find-tag has no problem locating variable definitions. My idea is to first detect if ggtags-find-definition failed. If it did, then attempt to just call find-tag. If you think this is a viable solution, can you point me to ggtags.el code where I can attach a call to find-tag? Thanks.
Hi @emacs18,
May be attach find-tag as an advice to ggtags-global-handle-exit or ggtags-global-exit-message-function.
HTH, Leo
Thanks for your pointers. I added one advice based on one of your suggestions as shown below. It is a bit crude, but it works if ggtags-find-definition is called. However it does not work if ggtags-find-tag-dwim is called. I'll use this for a while to see if I can improve it a bit. Feedbacks are of course welcome.
(defadvice ggtags-global-exit-message-function
(around try-etags-on-failure activate compile)
"On failure to find any item, try normal find-tag'. This is to locate global variable definitions." (let ((status ad-do-it)) (when (equal status '("found 0 definitions" . 0)) ;; (message "Tryingfind-tag' on %s" ggtags-current-tag-name)
(find-tag ggtags-current-tag-name))
status))
hi @emacs18,
ggtags-find-tag-dwim can give you "found 0 <TAGTYPE>" where TAGTYPE can be definitions references etc. You probably need to take that into account.
Leo