My emacs setup

Sun 26 December 2010 by Thejaswi Puthraya

Cross posted from my work blog...

My colleague Javed had written a fantastic article a short while back on "Seven reasons why you should switch to Vim" and as an emacs user I thought I should share my setup too. One of the coolest things at Agiliq is that we are free to use the development tools of our choice. As a case to explain the point, everyone at agiliq uses a different editor and if someday a flame war would escalate to the third world war, I assure you it would start from Agiliq ;-)

Though I have been using emacs for more than two years now, I still am an amateur. In this post, I am not going to exhort you to switch to emacs but explain my setup.

If you are planning to give emacs a try, I would suggest you start with the inbuilt emacs tutorial (C-h t). After you've gone through the tutorial, start using emacs while noting your most repetitive actions. Later, bind these repetitive actions to suitable shortcuts so that you can maximize your productivity and reduce keystrokes. Whenever in doubt, refer to emacswiki for clarifications. Another wonderful reference would be Steve Yegge's articles on emacs.

Before I explain my setup, let me make it clear that most editors already have a lot of the functionality and I am not being judgemental in this post. If you've come here to see me bash other editors or proclaim that emacs is the best editor, you are going to be disappointed. Emacs has worked for me and a lot of other people and may work for you. Give a couple of editors out there in the market a try (atleast for a fortnight for each editor) and decide the one that you are most comfortable with.

I use emacs without a window system (emacs -nw) and have an alias entry in my .bashrc to load it in this mode by default.

Here are the contents on my .emacs.d/init.el file and I will explain them below line by line:

;; .emacs

;; enable visual feedback on selections
(setq transient-mark-mode t)

;;; interfacing with ELPA, the package archive.
;;; Move this code earlier if you want to reference
;;; packages in your .emacs.
     (expand-file-name "~/.emacs.d/elpa/package.el"))

;; My customizations
(ido-mode 1)
(icomplete-mode 1)
(column-number-mode 1)
(menu-bar-mode 1)

(setq tags-file-name "~/TAGS")
(global-set-key (kbd "<f5>") 'find-tag)
(global-set-key (kbd "<f6>") 'rgrep)
(global-set-key (kbd "<f7>") 'magit-status)

(setq yas/root-directory "~/.emacs.d/snippets")
(yas/load-directory yas/root-directory)

(load (expand-file-name "~/.emacs.d/multi-term.el"))

The transient-mark-mode symbol when enabled gives feedback while marking regions (highlighting selected regions).

I use ELPA (Emacs Lisp Package Archive) for installing and managing my packages. Though currently, there are a few packages only in ELPA, they've been sufficient for me. There's another emacs package manager that I am looking forward to called epkg which will install packages from the EmacsMirror.

I have a few modes enabled by default like ido-mode (for intelligent auto completion in the minibuffer), icomplete-mode (for helping me complete commands in the minibuffer without remembering the full names), column-number-mode (to display the column number at which the point is currently located, useful if you follow PEP-8 for python) and disable the menu-bar as I hardly use it. The menu-bar is a distraction especially when you are using emacs on a separate display in a maximized state.

I use emacs tags to jump between function calls and definitions very frequently and hence bound this invocation to the F5 key. One thing to note is that F5-F9 are generally unassigned and can be bound to your most frequently used actions.

I also search very often for files or content within files and use rgrep and this has been bound to the F6 key.

I use git a lot and hence use magit, a fantastic emacs mode to interact with git. This mode has been bound to the F7 key of the keyboard.

I am not a big fan of auto-complete but use some snippet based auto-completion using yasnippets. It's very easy to write your own snippets and I've written lots of them for django and some dom elements.

Whenever I start emacs, I also start a shell and multi-term is very useful in this regard. It handles unicode and ncurses based output very well. This is where I run the django development server or deploy using the fabric scripts.

Apart from these elisp packages, I run erc (an IRC client written for emacs) occasionally to lurk on #django. I manage my tasks using the org-mode and synchronize these tasks with my home workstation using the mobileorg android app and dropbox.

As you would've observed my emacs setup is fairly minimal but suffices most of my django and python development. If you are an emacs user and have tips for me and other users, leave your comments. There's always a lot to learn in emacs :)