/emacs-init

My emacs initialization file and the code needed to build it

Primary LanguageEmacs Lisp

-*- mode: org; -*-

Version Information

What: Emacs Initialization File (and Builder) Author: Christopher Genovese Version: 2.5.5 Update #: 261 Last Updated: Tue 18 Jan 2011 Tested with: Emacs 23.2.1, 22.2 (Mac OS X 10.5.8)

Introduction and Main Features

This emacs initialization has grown over years of use, tweaking, and experimentation. Nonetheless, I’ve worked to maintain a useful organization that will make modification and sharing easier. Although it is a truism that everyone loves their own customizations, it’s my hope (belief) there are features here that are generally useful, and I hope that others can benefit from this init file, in part or in whole.

The following are some of the notable features. These are mostly small things, but I want to highlight them because they might be hard to spot in all this code. Detailed documentation for the features is given in the component files, linked to below.

  • Efficient Key Bindings

    Like many emacs users, I prefer to avoid mouse use as much as possible. I also try to avoid pinky extension in either hand. And I have attempted to configure commonly used operations to be as parsimoniously represented as possible and to make accessible as many commands as possible.

    The keybindings here are, I think, quite efficient and memorable. Note for example: although \M-x works, I have alternate bindings \C-x\C-m and \C-c\C-m that are faster. I have moved help to \M-\C-h, which leaves the easy keys \C-h and \M-h for more commonly used operations delete-backward-char and backward-kill-word. Once you get used to that, you will never hit backspace again. Also, in most cases one can use \C-m instead of return, eliminating a common pinky stretch. \M-<space> (mark-sexp) is very useful even in text modes for grabbing and extending over reasonable units. Rectangles, bookmarks, abbrevs, tags, icicles, org, and several other commonly used features have their own sub-maps that are mnemonically arranged.

    See keybindings.el for details.

    (Note: My quick-nav mode takes this farther for even greater efficiency.)

    See also the note below for an important issue with the keybindings.

  • Navigation

    Many of the builtin emacs movement commands issue errors at boundary cases (e.g., scroll-up near the beginning of the buffer). I have modified versions of these commands that avoid errors and “do what I mean”.

    See file move-funcs.el for examples.

  • Help Navigation

    The emacs help system is very nice, but to make it convenient it helps to have some navigation keys. \M-\C-h g takes you to the help buffer and g in the help buffer takes you back, leaving the help buffer where it was (q does the same while dismissing the help buffer). Various other keybindings in the help mode have been overridden to provide smooth navigation with a minimum of stretching or disruption.

    See file nav-modes.el for details.

  • Dired

    It took me many years to truly appreciate dired, but now that I have, it has more and more supplanted the shell for many commands. The key to this (excuse the pun :), I think, is some additional functionality that makes common operations easier. This is especially important for the case where subdirectories are listed in the same buffer, which is the default here, because the standard dired setup does not adequately support that case. With this in place, I can do much of what I traditionally did in the shell with dired, and more efficiently.

    See file nav-modes.el for details.

  • Shell Directory Tracking

    The tcsh shell has a directory stack feature that I’ve found very convenient. In particular, it is easy to keep track of and access directories on the stack. This is pretty old code but I’ve been using it continuously for years, so it’s also very stable. Coming version will include a more general mechanism that I’m experimenting with now.

    See file shell-mode.el for details.

  • Ibuffer

    A nice (and flexible) default filter setup, some nice navgation bindings, and a function for classifying files in the IBuffer listing.

    See file aux.el for details.

  • Icicles

    The icicles package is just terrific. I’ve added functionality to ease navigation in the completions buffer, to indicate results sorting, and to fix a problem with default strings.

    See file nav-modes.el for details.

  • SLIME

    Superior Lisp Interaction Mode for Emacs (SLIME) is a nice way to deal with various lisp dialects. Although there is a swank support through lein that does work with SLIME, it forces one to invoke swank externally and then connect using a different mechanism (slime-connect) than with other dialects. Here, I give an alternative interface that lets one add and modify lisp implemenations in a variety of ways, unifying starting and stopping across implementations. Clojure works directly this way, automatically connecting to swank from within emacs.

    See file prog-modes.el for details.

  • TeX

    Addition of commands and tags, including especially support for using make to construct documents.

    See file tex-modes.el for details.

  • ESS

    A simple customization (should be the default, I think) that makes it easier to work in an ess-mode buffer while evaluating expressions.

    See file ess-modes.el for details.

  • Some Useful Functions

    The files *-funcs.el contain a variety of emacs lisp functions that can be useful more generally. The file aliases.el introduces a few scheme/clojure style predicates and other function aliases. The file macros.el has several common and other control-flow macros. The file import-funcs.el has the first version of an import facility for managing requires and autoloads (and other types of loads). It doesn’t do everything I want it to yet but it is functional.

Acknowledgements: This code has been written over many years, inspired by and sometimes with reference to a lot of code written by others in the emacs community. Thanks to all for the good examples and wonderful packages.

Note on C-w and M-k bindings

Besides the new and modified keybindings set here, there is an important difference between these bindings and the GNU defaults. In particular, the GNU default global map uses C-v/M-v for scrolling, C-w for killing the region, and M-k for kill-sentence, with beginning and end of buffer exiled to M-< and M->. From almost the beginning of my time with emacs, I’ve found these unnatural. Instead, I use the following:

C-w Scrolling down (or beginning of buf when close) C-v Scrolling up (or end of buf when close) M-w Beginning of Buffer M-v End of Buffer M-k Kill region M-c Copy region and save in kill ring

There are some other differences from the default, of course, but these are the major thematic differences. I use all of these commands very frequently. Understanding that everyone likes what they are used, I’d urge you to try these; but if you want the defaults, there are only a handful of places where they are used. Search for “\(?:[MC]-w\|M-k\)” in the main file. In the next version, I will include a new function, called use-gnu-scroll-and-kill-bindings, to rearrange these bindings to the GNU default theme. I will also introduce additional “intelligent” mark and kill commands, which I’ve developed for my quick-nav mode.

Contents

The file is crg-emacs-init.el is the standalone “.emacs” file constructed from the other components in this directory. The compiled version crg-emacs-init.elc was byte compiled with Emacs 23.2.1. See below for installation instructions.

During startup, the init file is loaded, followed by the emacs-custom.el file in my-home-lisp-dir (e.g., ~/.emacs.d) and then my-env.el in my-home-lisp-dir, if it exists, for additional environment- or system-specific adjustments that you want to keep out of the main file. (For instance on Mac OS X, one can set the PATH environment variable here if you don’t want to adjust ~/.MacOSX/environment.plist on your system.) (Note the file system-settings.el in the main build can be used for a similar purpose.

The crg-emacs-init.el file is built from the other components in this directory using make. The file includes a hyper-linked table of contents (via linkd-mode) and extensive documentation. The makefile is also documented, but here I will describe the main pieces that are used in a less terse manner.

Files are roughly grouped by name according to the following patterns, matched successively (cond-like):

PatternCategory
*-funcs.elUtility functions on a related theme
*-modes.elCustomizes related group of major or minor modes
*.elSupport functionality (headers, keybindings, etc.)
[A-Z][-A-Za-z]*Configuration data, documentation, or build support

More specifically, the components are as follows:

Document Structure
header.elDocumentation and version information
toc.elTable of contents
utility-header.elTable of contents for utility functions
Utility Functions
aliases.elReadable aliases for common functions
predicate-funcs.elPredicates for list filtering
list-funcs.elOperations on lists and vectors
macros.elFlow control and other macros
name-funcs.elFile and directory names
move-funcs.elScrolling and cursor movement commands
op-funcs.elModifications to Emacs’s operation
import-funcs.elA simple module import interface
tool-funcs.elMiscellaneous useful tools
setter-funcs.elSetters and toggles for mode hooks
Mode Config
ess-modes.elESS configuration
nav-modes.elNavigation and file modes
prog-modes.elProgramming language modes
shell-modes.elShell/command interpreter modes
tex-modes.elTeX/AucTeX configuration
text-modes.elText-based modes
Settings
aux.elIBuffer setup + miscellaneous features
faces.elFace definitions
imports.elLibrary and package import
keybindings.elGlobal keybindings and keymaps
settings.elSetup of Emacs’s operating state
system-settings.elSystem specific configuration
Local Config
init.elInitializes emacs state
whoami.elGenerated personal settings file
Build Files
ConfigPersonal configuration settings
MakeTOC*Script to make table of contents
MakeWho*Script to construct whoami.el
MakefileBuild manager
READMEDocumentation
VERSIONVersion information
WhoAmIBase file for personal settings

Build and Installation

  1. Edit the keys in Config to personalize locations of files and directories, as well as various parameters.
  2. (Optional) You can add additional customizations to WhoAmI and add corresponding keys in Config. Config keys are of the form

    KEY: VALUE

    and these show up as __KEY__ in WhoAmI. The values will be substituted for the keys directly.

    The file WhoAmI is emacs lisp with Config keys in place. These keys will be substituted directly.

    Note that the variables that are currently defined in this file should not be removed as they are used later in the code. Take care when changing these definitions.

  3. (Optional) If you want to byte compile the init file, you should set the location of the emacs executable (make variable EMACS). The current setting is for installation on MacOS X because that’s what I’m currently using.
  4. (Optional) You should also configure the executable paths for perl and python (variables PERL and PYTHON) in the makefile if these are in non-standard locations. (Note: this step will not be necessary in the next version.) You can also change the default install and archive locations (INSTALL and ARCHIVE, see the makefile for details and more refined options.)
  5. (Optional) Only if you want to make the full archive, you should set the location of the emacs executable (EMACS) and the directories of the various lisp libraries (EMAPP_LIB, EMACS_LIB, LOCAL_LIB) and the location of the build directory (EMACS_INI), as described in the makefile.
  6. See Makefile for build and installation options. In short, you can get a byte-compiled initialization file by typing:

    make make install make clean

    at the shell prompt. (Verify successful compilation before proceeding to the second step. Emacs will give some compilation warnings, which you can probably ignore).

    To get an emacs-lisp source file, type

    make elisp make install INSTALL_SUFX=.el make fullclean

    This will install a .emacs file in your home directory by default. You can edit the Makefile options to customize the build further.

Current Requirements

I have tested this init file both explicitly and through long use on Emacs 22 and 23, on both Mac OS X and Linux. Emacs 22 users may wish to re-byte-compile the main file, as the version included here was compiled with emacs 23.

This configuration takes advantage of several built-in and third party modes/packages when they are available. Links to the source for third party packages are given below. Most of these can be obtained at http://www.emacswiki.org unless otherwise specified. None of these is strictly required for the init file to work. The packages that are referred to, directly or indirectly, are listed below with version information.

Multi-file add-on packages

PackageLinkVersionNotes
anythingEmacsWiki1.287plus anything-config.el
bookmark+EmacsWiki3.2.0Update #14946
essR-Project5.11
iciclesEmacsWiki22.0Update #22776
linkdEmacsWiki1.64Update #629
org-modeOrgMode.org7.01h
yasnippetGoogle Code0.6.1cnot the bundle
cedetSourceForge1.0emacs23 uses builtin version
ecbSourceForge2.40
jdeSourceForge2.4.0.1emacs23 uncertain

Single file add-on packages

PackageLinkVersionNotes
col-highlight.elEmacsWiki22.0Update #313
constants.elEmacsWiki2.2
crosshairs.elEmacsWiki22.0Update #394
dired+.elEmacsWiki21.2Update #2810
filladapt.elEmacsWiki2.12
hexrgb.elEmacsWiki21.0Update #733
hl-line+.elEmacsWiki22.0Update #424
icomplete+.elEmacsWiki21.0Update #880 (with icicles)
imenu+.elEmacsWiki21.1Update #567
info+.elEmacsWiki21.1Update #4374
lacarte.elEmacsWiki22.0Update #632 (with icicles)
replace+.elEmacsWiki21.0Update #1051
synonyms.elEmacsWiki1.0Update #2440 (with icicles)
thingatpt+.elEmacsWiki21.0Update #831