Source Code Browsing using Emacs


Recently, I took the time to learn Emacs, and I have come away much impressed with it. I used to scoff at vi and emacs enthusiasts, who treat the editors like a religion. And I secretly dreaded having to learn all the weirdo hotkeys associated with the two editors. So I stayed away from them. Recently, I did try to learn vi but I didn’t enjoy it very much. Even the simplest task was made daunting.

Then, one fine day, I saw a teacher browsing source code on emacs. With lightning spped, he would jump from function calls to definitions across files in different directories to follow the flow of code! With the proper amount of reverence and humility (:P), I asked him how he could possibly know where each function definition was. And then he showed me the TAGS feature of emacs. I was instantly converted.

So I took the time to learn emacs, and I have found the effort immensely satisfying. It is a superb tool, and cannot be called just an editor. Coming back to the post topic, here’s how you can make reading source code a far more comfortable experience:

Enter your source directory: (/usr/src generally)

open a terminal and run the command make TAGS
This should create a file TAGS which is used by emacs to store the necessary information

now go ahead, open any source file in Emacs.

if you come across a function call, and decide that you have to check out the code, just hit META-. (the Meta key is generally the Alt key)
to go to the next definition of the tag, META-,
and once you are done, return to original point using META-*

So there you go. Instant and easy source browsing. At your finger tips.


Tags: ,

One Response to “Source Code Browsing using Emacs”

  1. @$%deja vu$% Says:

    how do you use etags for a user-written directory tree??

    search karun saang… i googled a lot.. got nothin 😦

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: