fix: early-init.el: don't suppress legit file errors

The NOERROR argument on `load` no only suppress file-missing errors, but
file permission errors, so I avoided it. However, if any
`require` *inside* `doom.el` throws `file-missing`, this bootstrapper
will assume this means we're loading a non-Doom config.
This commit is contained in:
Henrik Lissner 2024-09-11 15:00:07 -04:00
parent 19d68887b1
commit de6a077669
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -105,38 +105,37 @@
;; To reduce that burden -- and since Doom doesn't load any dynamic modules ;; To reduce that burden -- and since Doom doesn't load any dynamic modules
;; this early -- I remove `.so' from `load-suffixes' and pass the ;; this early -- I remove `.so' from `load-suffixes' and pass the
;; `must-suffix' arg to `load'. See the docs of `load' for details. ;; `must-suffix' arg to `load'. See the docs of `load' for details.
(if (let ((load-suffixes '(".elc" ".el"))) (if (let ((load-suffixes '(".elc" ".el"))
(doom-file (expand-file-name "lisp/doom" user-emacs-directory)))
;; I avoid `load's NOERROR argument because it suppresses other, ;; I avoid `load's NOERROR argument because it suppresses other,
;; legitimate errors (like permission or IO errors), which gets ;; legitimate errors (like permission or IO errors), which gets
;; incorrectly interpreted as "this is not a Doom config". ;; incorrectly interpreted as "this is not a Doom config".
(condition-case-unless-debug _ (if (file-exists-p (concat doom-file ".el"))
;; Load the heart of Doom Emacs. ;; Load the heart of Doom Emacs.
(load (expand-file-name "lisp/doom" user-emacs-directory) (load doom-file nil (not init-file-debug) nil 'must-suffix)
nil (not init-file-debug) nil 'must-suffix) ;; Failing that, assume we're loading a non-Doom config...
;; Failing that, assume that we're loading a non-Doom config. ;; HACK: `startup--load-user-init-file' resolves $EMACSDIR from a
(file-missing ;; lexical (and so, not-trivially-modifiable)
;; HACK: `startup--load-user-init-file' resolves $EMACSDIR from a ;; `startup-init-directory', so Emacs will fail to locate the
;; lexical (and so, not-trivially-modifiable) ;; correct $EMACSDIR/init.el without help.
;; `startup-init-directory', so Emacs will fail to locate the (define-advice startup--load-user-init-file (:filter-args (args) reroute-to-profile)
;; correct $EMACSDIR/init.el without help. (list (lambda () (expand-file-name "init.el" user-emacs-directory))
(define-advice startup--load-user-init-file (:filter-args (args) reroute-to-profile) nil (nth 2 args)))
(list (lambda () (expand-file-name "init.el" user-emacs-directory)) ;; (Re)set `user-init-file' for the `load' call further below, and do
nil (nth 2 args))) ;; so here while our `file-name-handler-alist' optimization is still
;; (Re)set `user-init-file' for the `load' call further below, and ;; effective (benefits `expand-file-name'). BTW: Emacs resets
;; do so here while our `file-name-handler-alist' optimization is ;; `user-init-file' and `early-init-file' after this file is loaded.
;; still effective (benefits `expand-file-name'). BTW: Emacs resets (setq user-init-file (expand-file-name "early-init" user-emacs-directory))
;; `user-init-file' and `early-init-file' after this file is loaded. ;; COMPAT: I make no assumptions about the config we're going to
(setq user-init-file (expand-file-name "early-init" user-emacs-directory)) ;; load, so undo this file's global side-effects.
;; COMPAT: I make no assumptions about the config we're going to (setq load-prefer-newer t)
;; load, so undo this file's global side-effects. ;; PERF: But make an exception for `gc-cons-threshold', which I think
(setq load-prefer-newer t) ;; all Emacs users and configs will benefit from. Still, setting it
;; PERF: But make an exception for `gc-cons-threshold', which I ;; to `most-positive-fixnum' is dangerous if downstream does not
;; think all Emacs users and configs will benefit from. Still, ;; reset it later to something reasonable, so I use 16mb as a best
;; setting it to `most-positive-fixnum' is dangerous if downstream ;; fit guess. It's better than Emacs' 80kb default.
;; does not reset it later to something reasonable, so I use 16mb (setq gc-cons-threshold (* 16 1024 1024))
;; as a best fit guess. It's better than Emacs' 80kb default. nil))
(setq gc-cons-threshold (* 16 1024 1024))
nil)))
;; ...Otherwise, we're loading a Doom config, so continue as normal. ;; ...Otherwise, we're loading a Doom config, so continue as normal.
(doom-require (if noninteractive 'doom-cli 'doom-start)))) (doom-require (if noninteractive 'doom-cli 'doom-start))))