Emacs from scratch

Wednesday, 05 January 2011

Emacs 24 is almost upon us as I write this (Jan, 2011). I have seen many experienced users of emacs recommending building emacs from the latest source repository. So, I'm going to do just that.

bzr branch bzr://bzr.savannah.gnu.org/emacs/trunk emacs

This took a long time to checkout the code, so I installed emacs version 23 using homebrew on my Macbook.

$ brew install emacs

which installed the emacs binary to /usr/local/bin/.

Emacs is said to be "programmable programmer's editor". Almost every behaviour of Emacs can be customized and new features can be added with "plugins", which are called "packages" in emacs-lingo. There are thousands of emacs packages written by programmers which can do everything from customising the environment for programming languages (eg: python-mode), markup (eg: sgml-mode, pandoc-mode, ReST mode) to even editing videos!

Discovering these packages can be a fun and sometimes exhausting activity. There are many attempts to make the discovery and installation of these packages easy for the user. The most popular method at the moment is ELPA and the emacs-starter-kit .

However, following technomany's recent post on packages, I'm going to use the package.el recommended by him.

When emacs starts up, it looks for the init file under $HOME/.emacs.d. So, let's create that directory.

$ cd
$ mkdir .emacs.d
$ cd .emacs.d
$ wget http://repo.or.cz/w/emacs.git/blob_plain/HEAD:/lisp/emacs-lisp/package.el
$ emacs init.el

Add ~/.emacs.d to the package search path.

(setq dotfiles-dir (file-name-directory
                    (or (buffer-file-name) load-file-name)))

(add-to-list 'load-path dotfiles-dir)

Tell emacs to load the package package.

(require 'package)

Add a couple of package archives;

(add-to-list 'package-archives
             '("marmalade" .
               "http://marmalade-repo.org/packages/") t)
(add-to-list 'package-archives
             '("technomancy" .
               "http://repo.technomancy.us/emacs/") t)

M-x list-packages will fetch all the available packages from the package-archives and display them in a buffer.

Move to the package-list buffer. Select the packages that you want to install by pressing I and press x when you are done to install the selected packages.