As an extension of nik's answer, and their comment here, here's what I did, in the end:
;;; -*- lexical-binding: t -*-
;;
;; Added to appease the package.el gods
;; (package-initialize)
;; Select the profile based on which command-line argument used
(defvar *emacs-config-switcher/profiles-alist* nil
"An alist for the profiles that are registered here")
(defun emacs-config-switcher/register-profile (key path &optional file)
"Register profiles to global variable, referenced by KEY.
PATH points to the directory where the profile is stored. By default, will use init.el,
but it can be specified using FILE."
(or file (setq file "init.el"))
(setq *emacs-config-switcher/profiles-alist* (cons (cons key (list
:directory (file-name-as-directory path)
:file (expand-file-name file path)))
*emacs-config-switcher/profiles-alist*)))
(defun emacs-config-switcher/load-profile (switch)
"Load profile based on key."
(let ((key (pop command-line-args-left)))
(if (assoc key *emacs-config-switcher/profiles-alist*)
(progn (let ((directory-path
(plist-get (cdr (assoc key *emacs-config-switcher/profiles-alist*)) :directory))
(init-file
(plist-get (cdr (assoc key *emacs-config-switcher/profiles-alist*)) :file)))
(setq user-emacs-directory directory-path)
(load init-file)))
(error "Profile %s does not exist." key))))
; Register profiles here
(emacs-config-switcher/register-profile "emacs-starter-kit" "~/emacs-profiles/emacs24-starter-kit")
(emacs-config-switcher/register-profile "spacemacs" "~/emacs-profiles/spacemacs")
; Add the custom switches
(add-to-list 'command-switch-alist '("-S" . emacs-config-switcher/load-profile))
(add-to-list 'command-switch-alist '("--startup" . emacs-config-switcher/load-profile))
;;; init.el ends here
One thing I noted was that, if you're using stuff like spacemacs, it'll fail because what it's looking for isn't load-path
but instead user-emacs-directory
. Also, putting the load-path
into the spacemacs folder made Emacs complain that load-path
had your .emacs.d
file, which would cause problems.
As it is, this works both with spacemacs and emacs-starter-kit. Haven't tried any other configurations, but I might start looking into that.
emacs-starter-kit
for example can't provide? – Brunei