Source Code Browsing In Emacs
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.
id-utilspackage for Mac using
brew install idutils
idutils.eland place it in
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/
Load the path (
~/.emacs.d/lisp) in your
.emacsfile by adding the following lines to your
~/.emacsfiles (create it it does not exist)
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp")) (autoload 'gid "idutils" nil t)
Build the ID database for your code.
Go to the directory that contains the source code that you wish to navigate via
gidand create the ID database using the following command:
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
alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs -nw'
And that’s it! So, here it is, gid on xv6 source code!