Using Emacs profiles side-by-side
Table of Contents
This is very short note about Chemacs2, “an Emacs profile switcher, [which] makes it easy to run multiple Emacs configurations side by side”. It’s something I need to do that every now and then, for example when I want to test-drive the latest Spacemacs without affecting my main development environment.
Emacs 29 and later support the command-line option --init-directory=DIR
to
specify where Emacs should for its init files. Sometimes I have to use an older
Emacs version which makes that solution less ideal1. Until now I managed my
Emacs profiles using stow, which is a nice tool to manage symlinks. However, its
use case is not “Emacs profile switching” and that makes it somewhat cumbersome
to use.
This note is primarily meant as a quick recap for me. I’ve noticed that if I mostly use one profile, I always have to do a Google on how to select or create another profile. Most of the information here (and more) you can also find in the Chemacs2 repo README.
Installation
You install Chemacs2 in the $HOME/.emacs.d
directory, which is a directory
that Emacs can search for its initialization file. That directory is used by
Emacs configurations like Spacemacs and Doom, so if it already exists, make sure
you create a backup first. Then to install Chemacs2, clone it to
$HOME/.emacs.d
:
git clone https://github.com/plexus/chemacs2.git ~/.emacs.d
Configuration and profile selection
Chemacs2 uses Emacs lisp file $HOME/.emacs-profiles
to configure the different
profiles in use. At the time of writing, on my main development machine that
file looked like this:
(("doom" .
((user-emacs-directory . "~/repos/swinkels/emacs-doomemacs/emacs-28.2-doomemacs-20240517/.emacs.d")
(env . (("DOOMDIR" . "~/repos/swinkels/emacs-doomemacs/emacs-28.2-doomemacs-20240517/.doom.d")))))
("spacemacs" .
((user-emacs-directory . "~/repos/swinkels/emacs-spacemacs/emacs-28.2-spacemacs-20240201/.emacs.d")
(env . (("SPACEMACSDIR" . "~/repos/swinkels/emacs-spacemacs/emacs-28.2-spacemacs-20240201/.spacemacs.d"))))))
Its format is self-explanatory. It defines profiles “doom” and “spacemacs”, their Emacs user directories and their profile directories, the latter through the use of environment variables.
By default Chemacs2 uses the profile named “default” but you can easily select another one:
- I specify my default profile in
$HOME/.emacs-profile
, a text file that is picked up by Chemacs2 and that only contains the name of the profile to use. At the time of writing, my default profile is the Spacemacs one so this file contains the namespacemacs
. - When I want to use another profile, I specify its name using command-line
option
--with-profile
, which is added by Chemacs2. So to specify the use of Doom, call Emacs like this: ~emacs –with-profile doom
For completeness, you can also specify the profile to select via environment variable
CHEMACS_PROFILE
.
Closing thoughts
Nothing more to say here, Emacs profile switching using Chemacs2 works like a charm!
I prefer to use the same solution for every one of my Emacs installations. ↩︎