Toby's Emacs Configuration

My Emacs Configuration

A Literate emacs configuration.

HTML version available at http://tobytripp.github.io/emacs.d/

Emacs out-shines 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"

This file catalogs my key-bindings as well as my language mode settings, such as for Clojure and Ruby.

ADOPTED Decorations

  • State "ADOPTED" from "EXPERIMENTAL" [2018-02-23 Fri 10:03]
  • State "EXPERIMENTAL" from [2017-09-07 Thu 10:00]

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 Book-mark List:

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

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

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

Hide the fringe.

(when (display-graphic-p) (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)
  • 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)
(setq uniquify-buffer-name-style 'forward)

(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]"))


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

(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 directory. Demote errors to warnings so that a problem in a particular extension doesn't bring start-up to a halt.

  (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 key-bindings 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)

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)

There is also an elisp package that looks as though it would be helpful for this: elisp-bug-hunter.

(require-package 'bug-hunter)

(autoload 'bug-hunter-init-file "bug-hunter"
  "Debug issues with emacs start-up")

Author: Toby Tripp

Created: 2018-03-04 Sun 00:38