Monthly Archives: June 2010

I am a saint in the church of emacs!

There’s always a war between the most powerful editors – emacs v/s vi. This rivalry has become a lasting part of hacker culture and the free software community. I was a happy user of vi, until I discovered the power of emacs. And now, trust me, I just love using emacs, its one of my passion. I believe, I can spend entire day with just emacs opened and without switching to any other window. This sweet editor has support for gdb, autocomplete, cscope, compilation, emails and even browser. What more could one wish for? In this post, I will talk about some tips to add wings to emacs and make it fly freely.

When you have a project with thousands of million lines of code, like linux kernel source or webkit source, it necessitates to have some source code navigation tools. Mostly obvious choice is cscope. How about integrating cscope with emacs? Well, you have xcscope!

Installation of xcscope is very simple,
a). Download xcscope. Make sure that, this file is saved in some path searchable by emacs.
b). Make sure cscope-indexer is installed.
c). Edit your emacs and this line
    (require 'xcscope)
d). Optionally, have key bindings for some of the common cscope commands,
    (define-key global-map [(ctrl f3)] 'cscope-set-initial-directory)
    (define-key global-map [(ctrl f4)] 'cscope-unset-initial-directory)
    (define-key global-map [(ctrl f5)] 'cscope-find-this-symbol)
    (define-key global-map [(ctrl f6)] 'cscope-find-global-definition-no-prompting)
    (define-key global-map [(ctrl f7)] 'cscope-find-egrep-pattern)
    (define-key global-map [(ctrl f8)] 'cscope-find-this-file)
    (define-key global-map [(ctrl f9)] 'cscope-next-symbol)
    (define-key global-map [(ctrl f10)] 'cscope-next-file)
    (define-key global-map [(ctrl f11)] 'cscope-prev-symbol)
    (define-key global-map [(ctrl f12)] 'cscope-prev-file)
    (define-key global-map [(meta f9)] 'cscope-display-buffer)
    (define-key global-map [(meta f10)] 'cscope-display-buffer-toggle)

Hmmm. My emacs looked better with cscope, but, we, the engineers are lazy typing lots of code. That when I found Emacs Auto Complete. This pretty lisp package has a very neat way of displaying drop-down with list of possible auto completion. Worth having it in your emacs.

Whats more? Want to integrate Git inside emacs? Check GIT emacs. Though I am not really impressed with the features of this packages, it does serve the purpose.

M-x compile allows you to invoke the compilation from within emacs. One issue which I had with compilation buffer is, some characters from compilation output were not getting displayed, instead their ascii codes used to get displayed. It turns out that, we need to tell emacs that compilation output is in UTF-8, so that it can interpret them correctly. To do so, have this line in you .emacs file.
(prefer-coding-system 'utf-8)

Other annoying part of compilation buffer is, its not used to get scrolled as compilation goes. To automatically scroll the compilation buffer and stop scrolling when an error occurs, add these line in .emacs.
(custom-set-variables
'(compilation-scroll-output first-error))

Cool. My emacs looks a lot prettier now, but, there is something that made it to look sad! Yes, the fonts. I really hated the default font of emacs!. I always wished to have ‘monospace’ font to which vim defaults to. Well, you got to do following steps to have monospace font.

echo "Emacs.font: Monospace-10" >> ~/.Xresources
xrdb -merge ~/.Xresources

Now my emacs is the most sexiest editor and I am one of the happy saints in the church of emacs!