HOME

Toby's Emacs Configuration

My Emacs Configuration

Emacs outshines all other editing software in approximately the same way that the noonday sun does the stars. It is not just bigger and brighter; it simply makes everything else vanish.

– Neal Stephenson, "In the Beginning was the Command Line"

Testing out a Literate emacs configuration.

This file should catalog my keybindings as well as my language mode settings, such as for Clojure and Ruby.

TODO Keep the tangled elisp in a separate directory that is in .gitignore

Decorations

Turn off tool-bars and scroll bars and other features I deem unnecessary.

(if (fboundp 'tool-bar-mode)   (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(setq inhibit-splash-screen t)

Instead of a splash screen, let's start with the Bookmark List:

(require 'bookmark)
(bookmark-bmenu-list)
(switch-to-buffer "*Bookmark List*")

Disable backup files. That's what source-conrol is for.

(setq make-backup-files nil)
(setq auto-save-default nil)

Hide the fringe.

(set-fringe-style 0)

Highlight the current line in the buffer.

(global-hl-line-mode 1)

Over-write selection to make things slightly less uncomfortable to others.

(delete-selection-mode t)

Enable some features that the Emacs developers have deemed scary.

(put 'ido-exit-minibuffer 'disabled nil)
(put 'upcase-region       'disabled nil)
(put 'narrow-to-region    'disabled nil)
(put 'scroll-left         'disabled nil)
(put 'set-goal-column 'disabled nil)
(put 'downcase-region 'disabled nil)

Initialize Load Paths

Add some directories to the load path so we can require files in them later.

(defvar dotfiles-dir user-emacs-directory)

Make a path to add libraries installed from source.

(defvar vendor-dir (concat dotfiles-dir "vendor/"))

(let ((default-directory vendor-dir))
  (add-to-list 'load-path default-directory)
  (normal-top-level-add-subdirs-to-load-path))

Also create a place to put my various initialization hooks.

(defvar lib-dir (concat dotfiles-dir "elisp/"))
(add-to-list 'load-path lib-dir)
(defvar org-lib-dir (concat dotfiles-dir "org-init/"))
(add-to-list 'load-path org-lib-dir)

Change the Destination of Customization Settings

These are the settings saved from the customize menus and prompts within Emacs.

(setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror)

Setup Environment Variables and Path

I keep these in a separate file to make it easy to find them.

(load "env.el")

Install and Load Packages

(require 'init-packages)

Load Third-Party Libraries from Vendor

First, load some libraries that are likely to be used in every session:

  • uniquify configures how buffer names are disambiguated
  • ansi-color supports translating ANSI color codes into Emacs faces
  • recentf allows for fast switching between recently edited files
(require 'uniquify)
(require 'ansi-color)
(require 'recentf)

Then load anything we find in the vendor directory:

(mapc (lambda (path)
     (add-to-list 'load-path (concat vendor-dir "/" path)))
   (directory-files vendor-dir nil "^[a-z]"))

Org-Babel

Let's make it easy to tangle, load, and compile other configuration files written in org-mode.

(require 'org-install)
(require 'ob-tangle)

(defun toby/babel-load-file (relative-path)
  "Load the given file using org-babel-load-file.  Path should be
relative to lib-dir"
  (org-babel-load-file (expand-file-name relative-path org-lib-dir)))

Load Configurations

First, pre-load some custom function definitions that may be used in my extensions.

(require 'defuns)

Now, load every elisp file in the lib diectory. Demote errors to warnings so that a problem in a particular extension doesn't bring start-up to a halt.

(with-demoted-errors
  (mapc #'load
        (mapcar #'file-name-sans-extension
                (directory-files lib-dir nil ".*\.el$")))
  (mapc #'toby/babel-load-file
        (remove "index.org" (directory-files org-lib-dir nil ".*org$"))))

(byte-recompile-directory org-lib-dir 0)
(byte-recompile-directory lib-dir 0)

Errors encountered while loading these libraries will show up in the Messages buffer after start-up.

Toby Mode

I push some keybindings and behaviors into my own minor mode so that, should I ever sit with an experienced Emacs user, we can turn them off easily. This way Emacs can behave in a more “standard” way for a while.

toby-mode is defined in toby-mode.org.

(require 'toby-mode)
(global-toby-mode)

Mode-Specific Configurations

If Something Goes Wrong

Sometimes it helps to launch the debugger when an error occurs. By default, I've turned that off:

(setq debug-on-error       nil)

to turn it on:

(setq debug-on-error       t)

Author: Toby Tripp

Created: 2015-02-04 Wed 10:41

Emacs 24.3.1 (Org mode 8.2.10)

Validate