feat: backport --init-directory for 27/28 users

--init-directory was added in Emacs 29. This backports it for 27/28
users, so users can trivially load an Emacs config living in another
directory (will be necessary for future versions of Doom's sandbox).
However, for this to work, Doom needs to live in ~/.emacs.d or
~/.config/emacs.

Ref: emacs-mirror/emacs@8eaf04de83
This commit is contained in:
Henrik Lissner 2022-07-27 11:15:30 +02:00
parent dd83c455ba
commit 5108ffc44d
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -69,11 +69,28 @@
;; ;;
;;; Bootstrap ;;; Bootstrap
;; Ensure Doom is running out of this file's directory (let (;; DEPRECATED Backported from 29. Remove when 27/28 support is removed.
(setq user-emacs-directory (file-name-directory load-file-name)) (initdir (cadr (member "--init-directory" command-line-args)))
initfile)
;; But discard the switches later to prevent "invalid option" errors.
(when initdir
(add-to-list 'command-switch-alist (cons "--init-directory" (lambda (_) (pop argv)))))
;; Detect emacs directory
(setq user-emacs-directory
(cond (initdir (expand-file-name initdir))
((getenv-internal "EMACSDIR"))
(user-emacs-directory)))
;; Load the heart of Doom Emacs ;; Load the heart of Doom Emacs
(load (concat user-emacs-directory "core/core") nil 'nomessage) (if (load (expand-file-name "core/core" user-emacs-directory) t t)
;; ...and prepare it for an interactive session.
(setq initfile (expand-file-name "core-start" doom-core-dir))
;; ...but if that fails, then assume this isn't a Doom config.
(setq early-init-file (expand-file-name "early-init" user-emacs-directory))
(load early-init-file t t))
;; We hijack Emacs' initfile resolver to inject our own entry point. Why do ;; We hijack Emacs' initfile resolver to inject our own entry point. Why do
;; this? Because: ;; this? Because:
@ -94,8 +111,9 @@
(define-advice startup--load-user-init-file (:filter-args (args) init-doom) (define-advice startup--load-user-init-file (:filter-args (args) init-doom)
"Initialize Doom Emacs in an interactive session." "Initialize Doom Emacs in an interactive session."
(list (lambda () (list (lambda ()
(expand-file-name "core-start" doom-core-dir)) (or initfile
(expand-file-name "init.el" user-emacs-directory)))
nil ; TODO Replace with safe mode initfile nil ; TODO Replace with safe mode initfile
(caddr args))) (caddr args))))
;;; early-init.el ends here ;;; early-init.el ends here