As you may know, I’m maintaining different little packages for Gnu Emacs:
- dracula theme, a dark and pink theme;
- flycheck-grammalecte, which integrate the french grammar checker Grammalecte with Flycheck;
- Elpher, a Gemini browser;
- Aeronaut, a little file browser.
When it comes to testing with various configuration environment, Emacs is not very flexible. The main idea is to be able to test completely different user settings, without polluting my own preferences.
I know about Chemacs, but I was looking for a more simple solution, for example to embed it easily in a Makefile.
The first path I follow was to prevent Emacs to load my init file. This is clearly documented in its man page, and as easy as doing:
emacs -Q -l custom_profile.el <file_to_open>
-Q here means "Similar to '-q –no-site-file –no-splash'".
turn, means "Do not load an init file". Said otherwise, with this lone
parameter, we load nothing and prevent Emacs to follow its traditional startup
-l is used to load a specific lisp file, which can be seen as a
For most of my tests, it did the trick and I was happy with that. However, as
Emacs does not really start as expected, a lot of thing may not work as we are
used to. Packaging, or
customize for example. And if you forgot to
deactivate some features, you will still be polluting your own settings (yes,
I’m looking at you
And I finally found an answer on StackOverflow to literally chroot Emacs in a fake home environment. It is a bit weird to write, but it does the job:
HOME=/path/to/my/fakehome emacs <file_to_open>
All we have to do to make it works as expected, is to put our new settings
file inside this fake home directory. Meaning either to put there a
file, or a
.emacs.d/init.el file, or a
And now, as Emacs will start as usually, we benefit from all its features, and it even lets us easily install new packages without breaking anything on our own profile.
To conclude, both methods are valid, but they answer different use-cases:
-Qmethod is useful for quick or light tests. I also use it a lot with the
-nwswitches when it comes to achieve headless tasks. In my case, I still use it to quickly test the dracula theme I maintain.
- the fake home method is useful for more complex test cases, with a lot of dependencies involved. Or to debug other users settings files. I now use this method to work on Flycheck Grammalecte.
Make your choice 😀