Source code browsing using GNU ID and Emacs

Posted on March 10, 2013

Source code comprehension programs are amongst the most important tools that every software developer needs to master. Using these tools in an integrated way from the comfort of you favourite editor is important to minimise the context switches that kill the developer’s productivity (you know, “the zone…”).

Here it is a short HowTo on how I use GNU ID Utils from Emacs. This assumes some Linux/Debian derivative (in my case Ubuntu 12.04) and a C/C++ project, but other languages like Perl or Java are also supported by GNU ID.

Verify that the id-utils Debian package is installed

Alternatively, install it

$ sudo apt-get install id-utils

</p>

Download idutils.el and put it somewhere in your Emacs search path

The idutils source distribution comes with idutils.el, an Emacs interface to gid, the utility that comes with idutils and that let’s you query the ID database from the command line. At the time of writing, 4.6 is the latest version of the idutils package. However, it probably is safer to use the idutils.el from the same release as the idutils package installed on your system (in my case that is 4.5).

Build the ID database

The next step is to run mkid to build the identifier database. The following commands will produce an ID file in you project’s root directory. This will index your system headers as well as your project’s source code. E.g.:

$ cd "your favorite project"
$ mkid -s /usr/include/ .

Run gid from within Emacs

Open up any source file from your project, point your cursor at some identifier and run M-x gid. Emacs will ask you something like this:

Run gid (with args): thread_mutex_create

Just hit enter and Emacs will bring up a *compilation* buffer with the results: