GNU Emacs Customisation with .emacs
Customisation of applications is a two-edged sword. On the one hand, you get to make the tool work closer to the way you would have done it yourself. On the other hand, particularly with a tool like a text editor, you are bound to use it in different locations, and thus, likely, with different levels of customisation.
When starting up, Emacs will look for a .emacs initialization file in your home directory. This file can contain Emacs Lisp instructions which makes Emacs work like you want it to.
Minimal customisation
To minimise the impact of switching between the default and my personal favourite configuration, I try to keep my customisation cosmetic. Rebinding key combinations is at a strict minimum - I would have loved rebinding C-u to undo, but there's a world of difference between that and the default binding ("Do whatever comes next 4 times"), which spells trouble for when I end up in an Emacs without my customisations, so I stuck with the default C-xu for undo.
Stay in control
I want to know what I'm doing when customising Emacs. Thus, I don't use the Easy Customisation Interface, which is nice, but it adds a level of indirection that I would prefer to avoid. It makes changes to my .emacs, and to me, the best way of ensuring that I know what's going on in my .emacs is to only modify it directly.
Of course, there is no law against making a change using the easy interface, and then manually integrating the change that was made into my own config.
My customisation
Here follows a detailed description of my Emacs customisation file. If you prefer, here's the raw .emacs.
Nillify C-xC-c
Remap C-xC-c to C-xc, which is a lot harder to type by mistake:
(global-set-key "\C-x\C-c" nil) (global-set-key "\C-xc" 'save-buffers-kill-emacs)
I regularly hit C-xC-c by mistake, which is a pain. With backup, autosave and Desktop, you don't lose much, but still.
Nillify C-z
In many other applications, C-z is Undo, which means that with the default Emacs binding, I frequently end up unwillingly minimising - so I prefer rebinding C-z to do nothing:
(global-set-key "\C-z" nil)
Add C-zSomething shortcuts
Map useful functions which don't have a default binding to C-zSomething. I used to have a couple more of these, because the default bindings are sometimes... Difficult. I guess C-x^ might qualify as a shortcut on an american keyboard, but with other layouts, it would be more aptly named "hard-to-hit-cut" - several of the default shortcuts I have never figured out how to type.
Hippie expand ( C-zC-z)
Enhanced completion at point - does a very imaginative job of guessing what you want:
(global-set-key "\C-z\C-z" 'hippie-expand)
Looks in open buffers, the file system, the kill ring, etc. for
a possible completion of the text preceding point.
See also:
The
hippie-expand documentation.
Revert buffer ( C-zC-r)
Reload the file in the current buffer from disk - prompts if there are changes which will be lost:
; revert-buffer reloads the file, prompts if there are changes (global-set-key "\C-z\C-r" 'revert-buffer)
This function does not seem to be linked to a default shortcut, and autocompletion is little help when invoking it using M-x, since other functions have similar names.
Disable the startup screen ( inhibit-startup-screen)
Once you've seen it 50 times, it gets old:
(setq inhibit-startup-screen t)
Make the point not blink ( blink-cursor-mode)
I grew up with an Emacs point that did not blink, it reminds me of youth and for-fun nocturnal hacking:
(blink-cursor-mode nil)
Display column numbers ( column-number-mode)
It's always nice to know exactly where you are in a file - display the current column number in the mode-line:
(column-number-mode t)
Menubars, scrollbars, and toolbars are for mouse-users
This is a bit extreme, but I know that in Emacs, anything can be done using the keyboard, which IMHO is more efficient. Hiding all the things that make you want to go for the mouse is a good thing in the long term:
(menu-bar-mode nil) (scroll-bar-mode nil) (tool-bar-mode nil)
If I really really need the menubar, it is easily reactivated using M-x menu-bar-mode.
Disable tooltip-mode
I don't generally use the mouse in Emacs, so tooltips don't get displayed a lot, but when they do, I much prefer seeing them in the echo area:
(tooltip-mode nil)
See also: The Emacs Manual: Tooltips.
Move the mouse pointer out of the way ( mouse-avoidance-mode)
Move the mouse pointer if it is in the way:
(setq mouse-avoidance-mode 'animate)
See also The Emacs Manual: Mouse Avoidance.
Use visible rather than audible bell ( visible-bell)
I don't like the "error bell" (me and my editor, we play for the same team, and shouldn't beep at each other...), and neither do the people sitting next to me. I prefer visible notification that something went wrong:
(setq visible-bell t)
Visually match parentheses ( show-paren-mode)
Eventually, the compiler will set you straight, but time is gained when Emacs subtly confirms that you are grouping your statements like you intended to:
(show-paren-mode t)
Make buffer names unique ( uniquify-buffer-name-style)
Sometimes, I work on many files with the same name: log files, index.html files, etc. Display enough of the path to make buffer names unique:
(require 'uniquify) (setq uniquify-buffer-name-style 'forward)
See also: The Emacs Manual: Uniquify.
Point stays at the end of lines ( track-eol)
When moving point up or down while at the end of a line, stay at the end of the line:
(setq track-eol t)
Saves an occasional C-e.
Display buffer size ( size-indication-mode)
Display the buffer size in human readable format:
(size-indication-mode t)
Selection highlighting
Highlight the current region:
(transient-mark-mode t)
See also: The Emacs Manual: Transient Mark Mode.
Autosave Bookmarks
Enable autosaving of bookmarks:
(setq bookmark-save-flag 1)
Backup and autosave
Write backups and autosave files to a dedicated directory:
(setq version-control t ; Use version numbers for backups kept-new-versions 10 ; Keep the 10 most recent versions kept-old-versions 1 ; Also keep the oldest version delete-old-versions t ; Ask to delete excess backup backup-by-copying t ; Copy files, don't rename versions? backup-directory-alist '((".*" . "~/.emacs-backup")) ; backups in dedicated dir ) (defun force-backup-of-buffer () (let ((buffer-backed-up nil)) (backup-buffer))) (add-hook 'before-save-hook 'force-backup-of-buffer)
See also Emacs wiki: ForceBackups and The Emacs Manual: Save and Backup.
Saving session information (desktop.el)
In Emacs 22 and newer, Desktop will startup with the buffers from when Emacs last quit:
(desktop-save-mode 1)