/chemacs

Emacs profile switcher

Primary LanguageEmacs Lisp

     ___           ___           ___           ___           ___           ___           ___
    /  /\         /__/\         /  /\         /__/\         /  /\         /  /\         /  /\
   /  /:/         \  \:\       /  /:/_       |  |::\       /  /::\       /  /:/        /  /:/_
  /  /:/           \__\:\     /  /:/ /\      |  |:|:\     /  /:/\:\     /  /:/        /  /:/ /\
 /  /:/  ___   ___ /  /::\   /  /:/ /:/_   __|__|:|\:\   /  /:/~/::\   /  /:/  ___   /  /:/ /::\
/__/:/  /  /\ /__/\  /:/\:\ /__/:/ /:/ /\ /__/::::| \:\ /__/:/ /:/\:\ /__/:/  /  /\ /__/:/ /:/\:\
\  \:\ /  /:/ \  \:\/:/__\/ \  \:\/:/ /:/ \  \:\~~\__\/ \  \:\/:/__\/ \  \:\ /  /:/ \  \:\/:/~/:/
 \  \:\  /:/   \  \::/       \  \::/ /:/   \  \:\        \  \::/       \  \:\  /:/   \  \0.1 /:/
  \  \:\/:/     \  \:\        \  \:\/:/     \  \:\        \  \:\        \  \:\/:/     \__\/ /:/
   \  \::/       \  \:\        \  \::/       \  \:\        \  \:\        \  \::/        /__/:/
    \__\/         \__\/         \__\/         \__\/         \__\/         \__\/         \__\/



                                 ... ........,**********,...
                          .%*....       .,/(((#//(//*,*,,,*.,#%&(,,/(##.
                            %/..                          ,,  ,*,*/(%%.
                             %/*.                         .. .,,.,#%&
                              &(,.                       .. ....((%&.
                               ,#,.                     ..  ...*/#%
                                .#,..                   .  ..,/(%#
                                 .#,.                  ..  .,,(#%
                                   #*,.               .. .,,.(%(
                                  ***//((((((((//****,,**//,/  .
                                  ///((#%%%%%%%##(///////*./,,,,
                                   /#(##%%%%%%%%%##(((//*.(**,*
                                    .(/###%%%%%%##(((/// (/,,,
                                     */(##%%%%##(((/((/(/*.
                                     *((###%%%%%%%%%%%&&(*..
                                     .((###%%%%%%%%##((####/,//
                                     **//((###(###%%%#%%#&/%(%#(.
                                    **//(((((((/((##%#%#/%##%*/.
                                   ***///(/(((/////((((%**../..   //
                                  **//(((###(((((//////%/***(,..   /&
                                  ,####%%%%%%%%###((//(%,*/((/**    #*
                                  ./,,                *%..,..*&%    ,#
                                 ,(,.                 *%   .../%&    @
                                *#,.                  *%,  ....,%&   &.
                               (/,                   .&&&%/   ..,%&  %,
                              %/,                        ((.   .,,%&%%/,
                             #*.                                .*(%%%@,
                            #,.                                 ..,,%&.,
                           ,/....                              .... ,%%
                           %,,.....                  ......   ,* ....#&.
                           #,,,,..      .....................  ....,/#%*
                           #*,,*.......  ...................,,,****/(%%,
                           ,(*/**,.......................,,,,,**//###%#
                            /#/(((/**,...  .............,,,,/(##%%%##@
                             /.*/((/,,,,,.,/(###########(/(((((#%%#&&
                               ,(#(/,,.......,,,,,,,,/(///(#%%%%#
                                ./(*,..                  ..,*((#&/
                                    ...,..,..,/###(//(#(/*,.. .

Chemacs

Chemacs is an Emacs profile switcher, it makes it easy to run multiple Emacs configurations side by side.

Think of it as a bootloader for Emacs.

Rationale

Emacs configuration is either kept in a ~/.emacs file or, more commonly, in a ~/.emacs.d directory. These paths are hard-coded. If you want to try out someone else’s configuration, or run different distributions like Prelude or Spacemacs, then you either need to swap out ~/.emacs.d, or run Emacs with a different $HOME directory set.

This last approach is quite common, but has some real drawbacks, since now packages will no longer know where your actual home directory is.

All of these makes trying out different Emacs configurations and distributions needlessly cumbersome.

Various approaches to solving this have been floated over the years. There’s an Emacs patch around that adds an extra command line option, and various examples of how to add a command line option in userspace from Emacs Lisp.

Chemacs tries to implement this idea in a user-friendly way, taking care of the various edge cases and use cases that come up.

Installation

Clone the Git repository, and run install.sh

$ git clone https://github.com/plexus/chemacs.git
$ cd chemacs
$ ./install.sh
OK      Creating symlink ~/.emacs -> /home/arne/chemacs/.emacs

The install script will symlink ~/.emacs to the Chemacs script. If you already have a ~/.emacs you need to move it out of the way first

$ ./install.sh
WARN    chemacs can't be installed, ~/.emacs is in the way

By symlinking you can easily update Chemacs with a git pull. Chemacs is not available on ELPA/MELPA because its special position in the Emacs boot process would cause a chicken and egg problem.

Usage

Chemacs adds an extra command line option to Emacs, --with-profile. Profiles are configured in ~/.emacs-profiles.el. If this file does not exist Chemacs will create it with a default profile pointing at ~/.emacs.d.

If no profile is given at the command line then the default profile is used, so if you currently have your emacs configuration in ~/.emacs.d then Chemacs will, by default, use your existing configuration.

$ emacs --with-profile my-profile

.emacs-profiles.el

This file contains an association list, with the keys/cars being the profile names, and the values/cdrs their configuration.

The main thing to configure is the user-emacs-directory

(("default" . ((user-emacs-directory . "~/.emacs.d")))
 ("spacemacs" . ((user-emacs-directory . "~/spacemacs"))))

Chemacs will set this to be the user-emacs-directory in use, and load init.el from that directory.

Other things you can configure

  • custom-file : The file where Customize stores its customizations. If this isn’t configured, and the custom-file variable is still unset after loading the profile’s init.el, then this will get set to the profile’s init.el
  • server-name : Sets the server-name variable, so you can distinguish multiple instances with emacsclient -s <server-name>.
  • env An association list of environment variables. These will get set before loading the profile, so they can influence the initialization, and they are visible to any subprocesses spawned from Emacs.

Store .emacs-profile.el together with your dotfiles. If you’re not yet keeping a version controlled directory of dotfiles, then check out connect-the-dots for a helpful script to do that.

Changing the default profile (e.g. for GUI editors)

Where it is not possible to use the --with-profile flag, the default profile can be set using a ~/.emacs-profile file.

If your ~/.emacs-profiles.el file contains the following:

(("default" . ((user-emacs-directory . "~/.emacs.d")))
 ("spacemacs" . ((user-emacs-directory . "~/spacemacs")
 ("prelude" . ((user-emacs-directory . "~/prelude"))))

you can create a file called ~/.emacs-profile, containing the name of the profile you’d like to be used when none is given on the command line:

$ echo 'spacemacs' > ~/.emacs-profile

This will set the default profile to be the “spacemacs” profile, instead of “default”. You can change the default by simply changing the contents of this file:

$ echo 'prelude' > ~/.emacs-profile

If this file doesn’t exist, then “default” will be used, as before.

Spacemacs

Spacemacs is typically installed by cloning the Spacemacs repo to ~/.emacs.d, and doing extra customization from ~/.spacemacs or ~/.spacemacs.d/init.el. This makes it tedious to switch between version of Spacemacs, or between different Spacemacs configurations.

With Chemacs you can point your user-emacs-directory to wherever you have Spacemacs installed, and use the SPACEMACSDIR environment variable to point at a directory with customizations that are applied on top of the base install.

(("spacemacs" . ((user-emacs-directory . "~/spacemacs")
                 (env . (("SPACEMACSDIR" . "~/.spacemacs.d")))))

 ("spacemacs-develop" . ((user-emacs-directory . "~/spacemacs/develop")
                        (env . (("SPACEMACSDIR" . "~/.spacemacs.d")))))

 ("new-config" . ((user-emacs-directory . "~/spacemacs/develop")
                  (env . (("SPACEMACSDIR" . "~/my-spacemacs-config"))))))

DOOM emacs

You can add an entry similar to the following to your .emacs-profiles.el

In the following snippet ~/doom-emacs is where you have cloned doom emacs.

(Depending on when you read this) DOOMDIR support is only in develop branch of doom emacs. Check commit history of master branch of doom emacs

("doom" . ((user-emacs-directory . "~/doom-emacs")
           (env . (("DOOMDIR" . "~/doom-config")))))

Please refer to this discussion for details.

LICENSE

Copyright © Arne Brasseur 2018

Distributed under the terms of the GPL v3.