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,16 +105,15 @@
;; 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.
(file-missing
;; HACK: `startup--load-user-init-file' resolves $EMACSDIR from a ;; HACK: `startup--load-user-init-file' resolves $EMACSDIR from a
;; lexical (and so, not-trivially-modifiable) ;; lexical (and so, not-trivially-modifiable)
;; `startup-init-directory', so Emacs will fail to locate the ;; `startup-init-directory', so Emacs will fail to locate the
@ -122,21 +121,21 @@
(define-advice startup--load-user-init-file (:filter-args (args) reroute-to-profile) (define-advice startup--load-user-init-file (:filter-args (args) reroute-to-profile)
(list (lambda () (expand-file-name "init.el" user-emacs-directory)) (list (lambda () (expand-file-name "init.el" user-emacs-directory))
nil (nth 2 args))) nil (nth 2 args)))
;; (Re)set `user-init-file' for the `load' call further below, and ;; (Re)set `user-init-file' for the `load' call further below, and do
;; do so here while our `file-name-handler-alist' optimization is ;; so here while our `file-name-handler-alist' optimization is still
;; still effective (benefits `expand-file-name'). BTW: Emacs resets ;; effective (benefits `expand-file-name'). BTW: Emacs resets
;; `user-init-file' and `early-init-file' after this file is loaded. ;; `user-init-file' and `early-init-file' after this file is loaded.
(setq user-init-file (expand-file-name "early-init" user-emacs-directory)) (setq user-init-file (expand-file-name "early-init" user-emacs-directory))
;; COMPAT: I make no assumptions about the config we're going to ;; COMPAT: I make no assumptions about the config we're going to
;; load, so undo this file's global side-effects. ;; load, so undo this file's global side-effects.
(setq load-prefer-newer t) (setq load-prefer-newer t)
;; PERF: But make an exception for `gc-cons-threshold', which I ;; PERF: But make an exception for `gc-cons-threshold', which I think
;; think all Emacs users and configs will benefit from. Still, ;; all Emacs users and configs will benefit from. Still, setting it
;; setting it to `most-positive-fixnum' is dangerous if downstream ;; to `most-positive-fixnum' is dangerous if downstream does not
;; does not reset it later to something reasonable, so I use 16mb ;; reset it later to something reasonable, so I use 16mb as a best
;; as a best fit guess. It's better than Emacs' 80kb default. ;; fit guess. It's better than Emacs' 80kb default.
(setq gc-cons-threshold (* 16 1024 1024)) (setq gc-cons-threshold (* 16 1024 1024))
nil))) 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))))