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:
parent
dd83c455ba
commit
5108ffc44d
1 changed files with 44 additions and 26 deletions
|
@ -69,33 +69,51 @@
|
||||||
;;
|
;;
|
||||||
;;; 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)))
|
||||||
|
|
||||||
;; Load the heart of Doom Emacs
|
initfile)
|
||||||
(load (concat user-emacs-directory "core/core") nil 'nomessage)
|
|
||||||
|
|
||||||
;; We hijack Emacs' initfile resolver to inject our own entry point. Why do
|
;; But discard the switches later to prevent "invalid option" errors.
|
||||||
;; this? Because:
|
(when initdir
|
||||||
;;
|
(add-to-list 'command-switch-alist (cons "--init-directory" (lambda (_) (pop argv)))))
|
||||||
;; - It spares Emacs the effort of looking for/loading useless initfiles, like
|
|
||||||
;; ~/.emacs and ~/_emacs. And skips ~/.emacs.d/init.el, which won't exist if
|
;; Detect emacs directory
|
||||||
;; you're using Doom (fyi: doom hackers or chemacs users could then use
|
(setq user-emacs-directory
|
||||||
;; $EMACSDIR as their $DOOMDIR, if they wanted).
|
(cond (initdir (expand-file-name initdir))
|
||||||
;; - Later, 'doom sync' will dynamically generate its bootstrap file, which is
|
((getenv-internal "EMACSDIR"))
|
||||||
;; important for Doom's soon-to-be profile system (which can replace Chemacs).
|
(user-emacs-directory)))
|
||||||
;; Until then, we'll use core/core-start.el.
|
|
||||||
;; - A "fallback" initfile can be trivially specified, in case the bootstrapper
|
;; Load the heart of Doom Emacs
|
||||||
;; is missing (if the user hasn't run 'doom sync' or is a first-timer). This
|
(if (load (expand-file-name "core/core" user-emacs-directory) t t)
|
||||||
;; is an opportunity to display a "safe mode" environment that's less
|
;; ...and prepare it for an interactive session.
|
||||||
;; intimidating and more helpful than the broken state errors would've left
|
(setq initfile (expand-file-name "core-start" doom-core-dir))
|
||||||
;; Emacs in, otherwise.
|
;; ...but if that fails, then assume this isn't a Doom config.
|
||||||
;; - A generated config allows for a file IO optimized startup.
|
(setq early-init-file (expand-file-name "early-init" user-emacs-directory))
|
||||||
(define-advice startup--load-user-init-file (:filter-args (args) init-doom)
|
(load early-init-file t t))
|
||||||
"Initialize Doom Emacs in an interactive session."
|
|
||||||
(list (lambda ()
|
;; We hijack Emacs' initfile resolver to inject our own entry point. Why do
|
||||||
(expand-file-name "core-start" doom-core-dir))
|
;; this? Because:
|
||||||
nil ; TODO Replace with safe mode initfile
|
;;
|
||||||
(caddr args)))
|
;; - It spares Emacs the effort of looking for/loading useless initfiles, like
|
||||||
|
;; ~/.emacs and ~/_emacs. And skips ~/.emacs.d/init.el, which won't exist if
|
||||||
|
;; you're using Doom (fyi: doom hackers or chemacs users could then use
|
||||||
|
;; $EMACSDIR as their $DOOMDIR, if they wanted).
|
||||||
|
;; - Later, 'doom sync' will dynamically generate its bootstrap file, which is
|
||||||
|
;; important for Doom's soon-to-be profile system (which can replace Chemacs).
|
||||||
|
;; Until then, we'll use core/core-start.el.
|
||||||
|
;; - A "fallback" initfile can be trivially specified, in case the bootstrapper
|
||||||
|
;; is missing (if the user hasn't run 'doom sync' or is a first-timer). This
|
||||||
|
;; is an opportunity to display a "safe mode" environment that's less
|
||||||
|
;; intimidating and more helpful than the broken state errors would've left
|
||||||
|
;; Emacs in, otherwise.
|
||||||
|
;; - A generated config allows for a file IO optimized startup.
|
||||||
|
(define-advice startup--load-user-init-file (:filter-args (args) init-doom)
|
||||||
|
"Initialize Doom Emacs in an interactive session."
|
||||||
|
(list (lambda ()
|
||||||
|
(or initfile
|
||||||
|
(expand-file-name "init.el" user-emacs-directory)))
|
||||||
|
nil ; TODO Replace with safe mode initfile
|
||||||
|
(caddr args))))
|
||||||
|
|
||||||
;;; early-init.el ends here
|
;;; early-init.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue