I work in high performance computing (HPC). This means I work on some of biggest and best supercomputers in the world. It also means that I work on some biggest and best supercomputers from 5 or 10 years ago.
Recently, I found myself on a machine with Emacs 22. This post documents some of the changes I had to make to my Emacs configuration files to ensure that they could be used for any Emacs version I was likely to come across.
Ever since I’ve restarted using Emacs (from SublimeText), I’ve been using a few configuration files. I wanted my
.emacs to be pretty generic and high level. This would call an
init.el file which had a bunch of settings and packages. I also put a bunch of machine-specific configurations in a
Looking at Emacs 22, I don’t think there is any support for
package.el. I could roll with an old version, but after a quick search I could only find a snapshot for Emacs 23. In reality, I don’t need full Emacs package support, I just want to ensure my basic settings are on (I love my colors and hate auto-save files).
The new scheme has four files, three of which are called from the root
This file contains all vanilla Emacs 22 settings. Some packages, such as autopair or org, have at one point been included in the Emacs distribution, but are not guaranteed. That said, the settings in this file should be safe for all versions of Emacs.
This file contains any machine-specific settings (such as the ispell path) or customize settings. Note that you have to manually
touch this file when getting set up on a new machine or Emacs will complain.
This file contains everything to do with packages. It has the set-up for MELPA and then use-package for everything else. I actually really like how clean and single purpose this file turned out to be.
This file contains all the settings for my color theme. This file must be correct (i.e., not throwing errors) for all versions of Emacs as well. Any package-specific colors must be properly protected in case the package isn’t loaded.
For my particular setup, I am only able to achieve this because I include the
color-theme package/elisp files with my dotfiles distribution. Colors are notoriously tricky, so I’ve got something that works and I’m not changing it.
Here are a few snippets I used to make everything work.
init.el should only be called from Emacs 25 or greater. My
init.el would probably work for Emacs 24 as well, but I’ll leave it for now.
(when (< 24 emacs-major-version) (load "~/.config/emacs/init.el"))
Some package specific colors can only be set if the package is loaded. I suppose this could be done through use-package, but I have org outside of that for now.
(when (require 'org nil 'noerror) (set-face-attribute 'org-table t :foreground "#536fd6"))
Since my packages are all loaded in the
init.el file (and the file is only loaded for specific Emacs versions), I put the MELPA setup and
(package-initialize) calls in there. This causes
package.el to complain and automatically put a call to
(package-initalize) in the
.emacs file. Thus, to use a setup like this, I needed to add a comment at the beginning of my
;; package.el will check for this comment; it's actually called from init.el ;; (package-initialize)
I think this new scheme is quite slick. I get my favorite colors and settings no matter what machine I’m working on. Plus, there are no complaints/warnings/errors when I start up Emacs.
Need to keep up with a fast-moving software industry?