Pragmatic Development Notes

2008-11-05

Emacs On Windows – First Part

Filed under: Emacs,Ruby & RubyOnRails — Boško Ivanišević @ 2:23
Tags: , , , , ,

This is first post in small series of articles about Emacs. Although its title indicates that it is only about Windows most of it can be applied on Linux. Actually there are just a few Windows specific things in it. The goal is to get excellent environment for Ruby, Ruby on Rails development and tool for writing posts.

In order to set up Emacs you, naturally, have to download it first. You can download Xemacs, EmacsW32 or GNU Emacs. My favorite is GNU Emacs. There are several reasons for it. First it doesn’t come with the installer so I can always completely remove it if I don’t like it, without any fear that some files will be left as is so usual for the most of the applications on Windows. Second, on GNU Emacs download site I can always download latest version as soon as it is released. I do not have to wait patches to be applied or some installers to be made. Simple and clean.

Installing Emacs on Linux depends on the flavor you use. Ubuntu is the one I like the best. Installing Emacs on Ubuntu is quite easy. If you want official release just use:

sudo apt-get install emacs22

On the other hand if you want to see what new version will look like do:

sudo apt-get install emacs-snapshot

By the way I’m writing this post in snapshot version (23.0.60.1) on Ubuntu 8.10.

I like to keep all good and useful things grouped, so I keep them in C:\Utils folder. After downloading zip archive I’ve unpacked Emacs in C:\Utils\emacs-22.3 folder. Of course, you can unpack it wherever you want. Anyway all customizations and additional packages will be in separate folder.

One small digression. I use Cygwin a lot on Windows. Unfortunately current official version of Emacs on Cygwin is 21.3. It is quite old version and some of Lisp add-ins I use do not work with it. Version 22.1.3 which is marked as experimental always hangs both on Vista and XP and I could not use it. So I’ve decided to use same version on Cygwin. Some of the customizations will be Cygwin specific but I’ll make a note so you can omit if you don’t need them.

Now when Emacs is up and running it is time to customize it. First little introduction. During start up Emacs reads .emacs file from home folder. On Linux everybody knows what home folder is (/home/[user_name]), but on Windows home folder is different if you are on Vista (it has everything different, unfortunately) or on some earlier version. On Vista, home folder is in C:\Users\[user_name]\AppData\Roaming, and on XP it is in C:\Documents And Settings\[user_name]\Application Data. If you don’t like where Emacs searches for its start up file you can always change it by setting HOME environment variable to something else what is more suitable for you. I do not do that because I try to keep things as they are by default because it is easier for me to restore complete system if I need it.

Finally here is the first part of my .emacs file:


; Library with common Lisp extensions for Emacs.
(require 'cl)

; Needed to see how fast Emacs loads.
; Loading time is printed at the and of the
; execution of .emacs file.
(defvar *emacs-load-start* (current-time))

; I really like this font. I also tried Monaco which you can
; see on lot of Railscasts but I couldn't find the one which
; supports Serbian Cyrillic and Latin letters.
(set-default-font "Bitstream Vera Sans Mono-9")

; All customizations will be saved in separate file. This way
; it is easy to remove customizations and keep this file clean.
(setq custom-file "~/.emacs-custom.el")

; Now load all customized values.
(load custom-file 'noerror)

; This should allegedly speed up Emacs starting by preventing
; some requests from the window manager back to the Emacs. Frankly
; speaking I didn't notice some speed up but I still keep it:(
(modify-frame-parameters nil '((wait-for-wm . nil)))

;Allows syntax highlighting to work, among other things
(global-font-lock-mode 1)

; Sets initial window position
(set-frame-position (selected-frame) 70 70)

; Sets initial window size to 85 columns and 47 rows
(set-frame-size (selected-frame) 85 47)

; Makes last line ends in carriage return
(setq requre-final-newline t)

; Sets Ctrl-x / key combination for easy commenting
; out of selected lines.
(global-set-key "\C-x/" 'comment-or-uncomment-region)

; Allow resizing of the mini-buffer when necessary
(setq resize-minibuffer-mode t)

; I know lot of you will criticize me for this but all this
; years spent on Windows platform made me to do this:(
; Turns Windows-like selection mode.
(pc-selection-mode)

; Auto magically read compressed files
(auto-compression-mode 1)

; Set standard indent to 2 rather then 4
(setq standard-indent 2)

; This tells Emacs to create backup files.
(setq make-backup-files t)

; And this will enable versioning with default values.
(setq version-control t)

; Remove annoying message about deleting excess backup of .recentf
; which is list of recent files used and will be explained in next
; post.
(setq delete-old-versions t)

; Finally do not spread backups all over the disk.
; Just save all backup files in this directory.
(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))

That’s it for now. This will make your Emacs a little bit better with nicer font and with backup files grouped in one directory.

In the next post we’ll add some useful extensions.

Advertisements

Blog at WordPress.com.