Tuesday, October 16, 2007

cscope with emacs

During my college days i have never heard of cscope at all. The first tool that my mentor asked me to study was cscope as it is often difficult to read large source codes without cscope. I found it difficult to first use cscope since by default opens the source code in vi which i have never used. Heard that cscope can be integrated and gave it a try. It was not a difficult process at all. All you have to do is to set the EDITOR environment variable to emacs, so that cscope opens the files in emacs. You can safely set the EDITOR environment variable in .profile so that it is set every time you login. And for navigation you need to creat TAG table file for Emacs. Emacs has the solution in hand. All you have to do is to use the etags binary that comes with emacs.

The command ( etags `find . -name "*.[h|c]"` )  would create the TAGS file which emacs uses for navigating tags. Now to navigate `M-.` would take you the definition of a function or variable. `C-u M-.` would take you to the next definition. To return back to the original place where the search started the key binding is `C-u M-*`. There are number of cscope.el files available in internet which makes the navigation job easier but i did not try them as i was contented with this.

1 comment:

Suresh Kanna said...

Even I am in the same boat. But along with etags I also use a small LISP emacs extension which I use to make the code navigation better. the M-. usually takes u to a different file and its irritating to break your code flow. But I hear CScope can be many times more effective then etags. and it does not break your main viewer.