refactor: startup--load-user-init-file@init-doom advice

- Since its arguments aren't used, make the advice n-arity, to future
  proof the advice.
- Add commentary on load's side-effect on user-init-file.
- Add NOSUFFIX arg to load call, to spare Emacs the file IO of searching
  for init.%d.elc{.{so{,.gz},elc{,.gz},el{,.gz},,gz}}.
This commit is contained in:
Henrik Lissner 2022-09-19 00:02:58 +02:00
parent b65da762b8
commit 869852aed9
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -338,7 +338,7 @@ If RETURN-P, return the message as a string instead of displaying it."
;; 3. Cut down on unnecessary logic in Emacs' bootstrapper. ;; 3. Cut down on unnecessary logic in Emacs' bootstrapper.
;; 4. Offer a more user-friendly error state/screen, especially for errors ;; 4. Offer a more user-friendly error state/screen, especially for errors
;; emitted from Doom's core or the user's config. ;; emitted from Doom's core or the user's config.
(define-advice startup--load-user-init-file (:override (file-fn _ _) init-doom 100) (define-advice startup--load-user-init-file (:override (&rest _) init-doom 100)
(let ((debug-on-error-from-init-file nil) (let ((debug-on-error-from-init-file nil)
(debug-on-error-should-be-set nil) (debug-on-error-should-be-set nil)
(debug-on-error-initial (if (eq init-file-debug t) 'startup init-file-debug)) (debug-on-error-initial (if (eq init-file-debug t) 'startup init-file-debug))
@ -363,17 +363,18 @@ If RETURN-P, return the message as a string instead of displaying it."
;; the file that it loads into `user-init-file'. ;; the file that it loads into `user-init-file'.
(setq user-init-file t) (setq user-init-file t)
(when init-file-name (when init-file-name
(load init-file-name 'noerror 'nomessage nil 'must-suffix)) (load init-file-name 'noerror 'nomessage 'nosuffix))
;; If we did not find the user's init file, set user-init-file ;; If `user-file-name' is `t' when `load' is called, it will
;; conclusively. Don't let it be set from default.el. ;; change `user-file-name' to the loaded file (assuming it
;; successfully loaded).
(when (eq user-init-file t) (when (eq user-init-file t)
(signal 'doom-nosync-error (list init-file-name)))) (signal 'doom-nosync-error (list init-file-name)))
;; If we loaded a compiled file, set `user-init-file' to the source ;; If we loaded a compiled file, set `user-init-file' to the
;; version if that exists. ;; source version if that exists.
(setq user-init-file (setq user-init-file
(concat (string-remove-suffix (format ".%d.elc" emacs-major-version) (concat (string-remove-suffix (format ".%d.elc" emacs-major-version)
user-init-file) user-init-file)
".el"))) ".el"))))
;; TODO: Add safe-mode profile. ;; TODO: Add safe-mode profile.
;; (error ;; (error
;; ;; HACK: This is not really this variable's intended purpose, but it ;; ;; HACK: This is not really this variable's intended purpose, but it