作为nik的回答的延伸,以及他们在这里的评论,这就是我所做的,最后:
;;; -*- 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
我注意到的一件事是,如果您使用的是spacemacs之类的东西,它会失败,因为它正在寻找的不是load-path
而是user-emacs-directory
。此外,将load-path
文件放入 spacemacs 文件夹会使 Emacs 抱怨load-path
有您的.emacs.d
文件,这会导致问题。
事实上,这适用于spacemacs和emacs-starter-kit。没有尝试任何其他配置,但我可能会开始研究。