# Source Code Browsing In Emacs

1 minute read

Published:

Its extremely important to be able to navigate a large code base effectively. I have been taking good tools for source code navigation for granted at my workplace. But most of my personal, side projects were small enough for me to get by without such tools. Either that or I was being lazy.

Now that I stare at the xv6 OS code (more on that later!) everyday, I have been sorely missing the gid utility in Emacs. Setting it up took me a little while and here’s what I did to enable GNU id-utils based gid search in Emacs on OSX.

1. Install the id-utils package for Mac using brew

 brew install idutils

2. Download idutils.el and place it in ~/.emacs.d/lisp

 wget http://ftp.gnu.org/gnu/idutils/idutils-4.5.tar.xz
$xz -d idutils-4.5.tar.xz$ tar xvf idutils-4.5.tar
\$ cp idutils-4.5/lisp/idutils.el ~/.emacs.d/lisp/

3. Load the path (~/.emacs.d/lisp) in your .emacs file by adding the following lines to your ~/.emacs files (create it it does not exist)

 (add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp"))
(autoload 'gid "idutils" nil t)

4. Build the ID database for your code.

Go to the directory that contains the source code that you wish to navigate via gid and create the ID database using the following command:

 mkid -s

5. Run gid

By now you should be ready to use gid. But for me there was a minor complication. When I ran gid (with M-x gid), the Emacs minibuffer conveyed this error:

 Symbol's function definition is void: read-shell-command"


I searched and found that the bug that causes this error has been fixed in the newer versions of Emacs. By default, I had Emacs version 22.X installed. So, I upgraded my Emacs to the latest version from emacsforosx and then aliased “emacs” to the new Emacs app by adding the following line to my ~/.bash_profile:

 alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs -nw'


And that’s it! So, here it is, gid on xv6 source code!