DEV Community

Elsa Gonsiorowski
Elsa Gonsiorowski

Posted on • Originally published at on

Configuring for Emacs 22 and 25

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.

Old Initialization File Setup

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 .emacs-custom.el file.

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).

New Scheme

The new scheme has four files, three of which are called from the root .emacs file.


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.

Checking The Emacs Version

The 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"))
Enter fullscreen mode Exit fullscreen mode

Checking for a Package

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"))
Enter fullscreen mode Exit fullscreen mode

Package Initialization

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 .emacs file.

;; package.el will check for this comment; it's actually called from init.el
;; (package-initialize)
Enter fullscreen mode Exit fullscreen mode


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.

Top comments (2)

attilavm profile image
Attila Molnar • Edited

I use my local Emacs with tramp to access remotes, which connects to them with SSH.

It is capable to use dired, magit or the interpreters/compilers on the remote machine.

It can also use su so, you do not have to start Emacs as root to edit files as root on your local, and it is also possible with remotes, so you can forbid root ssh login.

This a tramp hop proxy definition to ssh into a server as normal user then elevate to root.

(add-to-list 'tramp-default-proxies-alist
         '("host" "root" "/ssh:user@host#7822:"))

Tramp is cranky with fancy propmts, but it can be solved easily

I hope this helps.

gonsie profile image
Elsa Gonsiorowski

You're right that remote access to files is great way to avoid the Emacs version problems.

My main motivation was to get Emacs 22 to stop complaining when I started it up to look at files on a server or make quick edits. Tramp is key for working on code/doing advanced things with remote files.

Thanks for the additional information!