refactor: early-init: distinguish failure/fallthrough states

If lisp/doom.el does not exist, then we assume the user isn't loading a
Doom config and fall through to $EMACSDIR/early-init.el, if it exists.
However, `load`'s NOERROR argument suppresses more than just
file-missing errors -- it suppress permissions errors and other
legitimate IO errors that I want to treat as error states, not
fall-through states. This commit fixes that.

* early-init.el (gc-cons-threshold): Set a reasonable more default for
  gc-cons-threshold for non-Doom configs (16mb), instead of
  most-positive-fixnum, which would eventually cause
  freezing/stuttering for non-Doom profiles.
This commit is contained in:
Henrik Lissner 2022-09-25 13:25:15 +02:00
parent e61af32307
commit fa345fcc62
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -102,17 +102,32 @@
;; -- I remove `.so' from `load-suffixes' and pass the `must-suffix' arg to ;; -- I remove `.so' from `load-suffixes' and pass the `must-suffix' arg to
;; `load'. See the docs of `load' for details. ;; `load'. See the docs of `load' for details.
(if (let ((load-suffixes '(".elc" ".el"))) (if (let ((load-suffixes '(".elc" ".el")))
;; I avoid `load's NOERROR argument because other, legitimate errors
;; (like permission or IO errors) should not be suppressed or
;; interpreted as "this is not a Doom config".
(condition-case _
;; Load the heart of Doom Emacs. ;; Load the heart of Doom Emacs.
(load (expand-file-name "lisp/doom" user-emacs-directory) (load (expand-file-name "lisp/doom" user-emacs-directory)
'noerror (not init-file-debug) nil 'must-suffix)) nil (not init-file-debug) nil 'must-suffix)
;; ...and prepare for the rest of the session. ;; Failing that, assume that we're loading a non-Doom config.
(doom-require (if noninteractive 'doom-cli 'doom-start)) (file-missing
;; Failing that, assume we're loading a non-Doom config and prepare. ;; Set `user-init-file' for the `load' call further below, and do so
(setq user-init-file (expand-file-name "early-init" user-emacs-directory) ;; here while our `file-name-handler-alist' optimization is still
;; I make no assumptions about the config we're about to load, so ;; effective (benefits `expand-file-name'). BTW: Emacs resets
;; to limit side-effects, undo any leftover optimizations: ;; `user-init-file' and `early-init-file' after this file is loaded.
load-prefer-newer t) (setq user-init-file (expand-file-name "early-init" user-emacs-directory))
nil)) ;; COMPAT: I make no assumptions about the config we're going to
;; load, so undo this file's global side-effects.
(setq load-prefer-newer t)
;; PERF: But make an exception for `gc-cons-threshold', which I
;; think all Emacs users and configs will benefit from. Still,
;; setting it to `most-positive-fixnum' is dangerous if downstream
;; does not reset it later to something reasonable, so I use 16mb
;; as a best fit guess. It's better than Emacs' 80kb default.
(setq gc-cons-threshold (* 16 1024 1024))
nil)))
;; ...But if Doom loaded then continue as normal.
(doom-require (if noninteractive 'doom-cli 'doom-start))))
;; Then continue on to the config/profile we want to load. ;; Then continue on to the config/profile we want to load.
(load user-init-file 'noerror (not init-file-debug) nil 'must-suffix)) (load user-init-file 'noerror (not init-file-debug) nil 'must-suffix))