refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes: - Doom now fully and dynamically generates (and byte-compiles) your profile and its init files, which includes your autoloads, loading your init files and modules, and then some. This replaces doom-initialize-modules, doom-initialize-core-modules, and doom-module-loader, which have been removed. This has also improved startup time by a bit, but if you use these functions in your CLIs, for instance, this will be a breaking change. - `doom sync` is now required for Doom to see your profiles (and must be run whenever you change them, or when you up/downgrade Emacs across major versions). - $DOOMDIR/init.el is now read much earlier than it used to be. Before any of doom-{ui,keybinds,editor,projects}, before any autoloads are loaded, and before your load-path has been populated with your packages. It now runs in the context of early-init.el, giving users freer range over what they can affect, but a more minimalistic environment to do it in. If you must have some logic run when all that is set up, add it to one of the module hooks added in e08f68b or 283308a. This also poses a significant change to Doom's load order (see the commentary change in lib/doom.el), along with the following (non breaking) changes: 1. Adds a new `doom profiles sync` command. This will forcibly resync your profiles, while `doom sync` will only do so if your profiles have changed. 2. Doom now fully and dynamically generates (and byte-compiles) your user-init-file, which includes loading all your init files, modules, and custom-file. This replaces the job of doom-initialize-modules, doom-initialize-core-modules, and doom-module-loader, which have been removed. This has also improved startup time by a bit. 3. Defines new doom-state-dir variable, though not used yet (saving that and the other breaking changes for the 3.0 release). 4. Redesigns profile directory variables (doom-profile-*-dir) to prepare for future XDG-compliance. 5. Removed unused/unimportant profile variables in doom.el. 6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's enough to power the system as it is now. 7. Updates the "load order" commentary in doom.el to reflect these changes.
This commit is contained in:
parent
3d6e0311b9
commit
b914830403
15 changed files with 981 additions and 402 deletions
|
@ -62,39 +62,16 @@
|
|||
(when profile
|
||||
;; FIX: Discard the switch to prevent "invalid option" errors later.
|
||||
(push (cons "--profile" (lambda (_) (pop argv))) command-switch-alist)
|
||||
;; While processing the requested profile, Doom loosely expects
|
||||
;; `user-emacs-directory' to be changed. If it doesn't, then you're using
|
||||
;; profiles.el as a glorified, runtime dir-locals.el (which is fine, if
|
||||
;; intended).
|
||||
(catch 'found
|
||||
(let ((profiles-file (expand-file-name "profiles.el" user-emacs-directory)))
|
||||
(when (file-exists-p profiles-file)
|
||||
(with-temp-buffer
|
||||
(let ((coding-system-for-read 'utf-8-auto))
|
||||
(insert-file-contents profiles-file))
|
||||
(condition-case-unless-debug e
|
||||
(let ((profile-data (cdr (assq (intern profile) (read (current-buffer))))))
|
||||
(dolist (var profile-data (if profile-data (throw 'found t)))
|
||||
(if (eq (car var) 'env)
|
||||
(dolist (env (cdr var)) (setenv (car env) (cdr env)))
|
||||
(set (car var) (cdr var)))))
|
||||
(error (error "Failed to parse profiles.el: %s" (error-message-string e))))))
|
||||
;; If the requested profile isn't in profiles.el, then see if
|
||||
;; $EMACSDIR/profiles/$DOOMPROFILE exists. These are implicit
|
||||
;; profiles, where `emacs --profile foo` will be equivalent to `emacs
|
||||
;; --init-directory $EMACSDIR/profile/foo', if that directory exists.
|
||||
(let ((profile-dir
|
||||
(expand-file-name
|
||||
profile (or (getenv-internal "DOOMPROFILESDIR")
|
||||
(expand-file-name "profiles/" user-emacs-directory)))))
|
||||
(when (file-directory-p profile-dir)
|
||||
(setq user-emacs-directory profile-dir)
|
||||
(throw 'found t)))
|
||||
(user-error "No %S profile found" profile)))
|
||||
(when init-file-debug
|
||||
(message "Selected profile: %s" profile))
|
||||
;; Ensure the selected profile persists through the session
|
||||
(setenv "DOOMPROFILE" profile)))
|
||||
;; Running 'doom sync' will (re)generate a lightweight profile
|
||||
;; bootstrapper in $EMACSDIR/profiles/init.el, after reading
|
||||
;; $EMACSDIR/profiles.el, $DOOMDIR/profiles,
|
||||
;; $XDG_CONFIG_HOME/doom-profiles.el, and ~/.doom-profiles.el. All it
|
||||
;; needs is for `$DOOMPROFILE' to be set.
|
||||
(setenv "DOOMPROFILE" profile)
|
||||
(or (load (expand-file-name (format "profiles/init.%d" emacs-major-version)
|
||||
user-emacs-directory)
|
||||
'noerror 'nomessage nil t)
|
||||
(user-error "Profiles not initialized yet; run 'doom sync' first"))))
|
||||
|
||||
;; PERF: When `load'ing or `require'ing files, each permutation of
|
||||
;; `load-suffixes' and `load-file-rep-suffixes' (then `load-suffixes' +
|
||||
|
@ -110,29 +87,10 @@
|
|||
(if (load (expand-file-name "lisp/doom" user-emacs-directory)
|
||||
'noerror 'nomessage nil 'must-suffix)
|
||||
;; ...and prepare for the rest of the session.
|
||||
(if noninteractive
|
||||
(doom-require 'doom-cli)
|
||||
;; HACK: This advice hijacks Emacs' initfile resolver to replace
|
||||
;; $EMACSDIR/init.el (and ~/.emacs or ~/_emacs) with a
|
||||
;; a Doom-provided init file. Later, this file will be
|
||||
;; generated by 'doom sync' for the active Doom profile;
|
||||
;; `doom-start' is its stand-in until that's implemented.
|
||||
;;
|
||||
;; This effort spares Emacs the overhead of searching for
|
||||
;; initfiles we don't care about, enables savvier hackers to
|
||||
;; use $EMACSDIR as their $DOOMDIR, and gives us an opportunity
|
||||
;; to fall back to a "safe mode", so we can present a more
|
||||
;; user-friendly failure state.
|
||||
(define-advice startup--load-user-init-file (:filter-args (args) init-doom)
|
||||
"Initialize Doom Emacs in an interactive session."
|
||||
(list (lambda ()
|
||||
(file-name-concat doom-core-dir "doom-start"))
|
||||
(lambda ()
|
||||
(file-name-concat doom-profiles-dir "safe-mode" "init.el"))
|
||||
(caddr args))))))
|
||||
(doom-require (if noninteractive 'doom-cli 'doom-start))))
|
||||
;; Failing that, assume we're loading a non-Doom config and prepare.
|
||||
(ignore
|
||||
(setq early-init-file (expand-file-name "early-init" user-emacs-directory)
|
||||
(setq user-init-file (expand-file-name "early-init" user-emacs-directory)
|
||||
;; I make no assumptions about the config we're about to load, so
|
||||
;; to limit side-effects, undo any leftover optimizations:
|
||||
load-prefer-newer t))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue