20
Use Emacs with Different User Profile
When it comes to testing with various configuration environment, Gnu 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>
The -Q
here means “Similar to ‘-q --no-site-file --no-splash’”. -q
, in 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 process.
Then, -l
is used to load a specific lisp file, which can be seen as a profile replacement.
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 auto-save-list
).
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 .emacs
file, or a .emacs.d/init.el
file, or a .config/emacs/init.el
one.
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:
- the
-Q
method is useful for quick or light tests. I also use it a lot with the--batch
and-nw
switches 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 😀
20