Gtags on emacs

In a previous post about emacs etags, I received a tip from Alex Ott suggesting gtags for C/C++.

Installing

On MacOS, you can get gtags through mac ports, installing the “global” package.

Usage

To build the symbols table, it’s simple as doing:

gtags

at the root of the project.

Usage on emacs

First, you need to add a gtags-mode on emacs and tell it where to find the gtags script if gtags.el file is not installed in the default location (mac ports install it on /opt/local/share/gtags by default). On the preferences files, I added these lines:

(setq load-path (cons "/opt/local/share/gtags/" load-path))                                                                                                             
(autoload 'gtags-mode "gtags" "" t)  

Some useful commands:

  • gtags-find-tag [tag name] — this command finds the definition of tag name.
  • gtags-find-rtag [tag name] — this command finds the usage of the tag name
  • gtags-find-tag-from-here — this command is a smart version of the above. It will look up the name that is pointed by your cursor. If your cursor is on a definition, it will look for usage. On the other hand, if your cursor is on a usage, it will look for the definition.

One may wish to bind this last command to some key.

Reference

http://www.gnu.org/s/global/globaldoc.html

About these ads

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s