Showing posts with label global. Show all posts
Showing posts with label global. Show all posts

[Emacs] Adding gtags support to emacs on OSX

OS X does not have global (gtags) by default. I am a big fan of gtags on emacs and I can't function without it. Homebrew has a Mac port for global which is very easy to install.

brew install global

Once installed, you would need to find out the path to the gtags.el file for emacs. On my Mac it was installed into /usr/local/share/gtags.

Finally,  update the .emacs file with the following:

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

Voila, gtags is now working. Now I need to figure out how to enable it for Aquaemacs.

Update: No worries, Aquaemacs is able to read ~/.emacs file as well. The only thing that does not seem to work with Aquaemacs is emacsclient. Well, that is a different fire.

"global" just got sexy

Ever since I got used to the OpenGrok based code navigation server at work I was itching to try something similar with gtags. I have been using gtags with emacs for a long time now. Today I found about htags that provides an HTML based front end to global and ain't it sexy!

Just run "htags" on the folder where "gtags" was run earlier. If you are running it for the first time simply run "htags -g". This creates all the G* tag files and also an HTML folder.

To view the tag you can use gozilla. For example,


$ global -x foo
foo 100 src/foo.cpp
foo 200 src/bar.cpp
$ gozilla -b firefox +100 src/foo.cpp

This will open firefox and from there on you can navigate the code as each and every tag is clickable. Otherwise you can open the HTML/mains.html file in the browser of your choice.

To update the tags run "global -uv" followed by "htags" again. As simple as that.

Using gtags (global)

As a follow up to the last post, I tried emacs+gtags and it is really powerful when compared to emacs+etags.

Important things to get started.

First run gtags on the code.
$ gtags

This would create four files GPATH, GRTAGS, GSYMS, GTAGS

Open emacs and enable gtags
M-x gtags-mode RET

To enable auto completion of function names\symbols etc use,
M-x gtags-make-complete-list
NOTE: This is deprecated and not required now.

To locate a function use,
M-x gtags-find-tag function_name.
You can also use M-.

If more than one is found a stack is returned. Select one and hit RET. In order to get the stack use,
M-x gtags-pop-stack.
You can also use M-*

To find a symbol use,
M-x gtags-find-symbol m_myVar

To find anything use,
M-x gtags-find-with-grep "gtags rules"

Once you modify the code, just update the code
global -u -v

To visit the tags folder use,
M-x gtags-visit-rootdir and point it to the folder that has the TAGS!

global and gtags

I have heard a lot about GNU GLOBAL source code tag system, need to try it out.

GNU global