fix: ensure top-level file-name-handler-alist is affected

Ensures that lexical contexts are never taken into account, in the case
where Doom's core is loaded in an isolated environment (e.g. the
sandbox). Also improves my startup time by 10%? I'll take it.
This commit is contained in:
Henrik Lissner 2023-12-05 17:20:34 -05:00
parent f1e77e6692
commit a5ffbd8550
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -331,15 +331,16 @@ users).")
;; `file-remote-p'). You get a noteable boost to startup time by unsetting ;; `file-remote-p'). You get a noteable boost to startup time by unsetting
;; or simplifying its value. ;; or simplifying its value.
(let ((old-value (default-toplevel-value 'file-name-handler-alist))) (let ((old-value (default-toplevel-value 'file-name-handler-alist)))
(setq file-name-handler-alist (set-default-toplevel-value
;; HACK: If the bundled elisp for this Emacs install isn't 'file-name-handler-alist
;; byte-compiled (but is compressed), then leave the gzip file ;; HACK: If the bundled elisp for this Emacs install isn't byte-compiled
;; handler there so Emacs won't forget how to read read them. ;; (but is compressed), then leave the gzip file handler there so Emacs
;; won't forget how to read read them.
;; ;;
;; calc-loaddefs.el is our heuristic for this because it is built-in ;; calc-loaddefs.el is our heuristic for this because it is built-in to
;; to all supported versions of Emacs, and calc.el explicitly loads ;; all supported versions of Emacs, and calc.el explicitly loads it
;; it uncompiled. This ensures that the only other, possible ;; uncompiled. This ensures that the only other, possible fallback would
;; fallback would be calc-loaddefs.el.gz. ;; be calc-loaddefs.el.gz.
(if (eval-when-compile (if (eval-when-compile
(locate-file-internal "calc-loaddefs.el" load-path)) (locate-file-internal "calc-loaddefs.el" load-path))
nil nil
@ -352,7 +353,8 @@ users).")
;; needed for handling encrypted or compressed files, among other things. ;; needed for handling encrypted or compressed files, among other things.
(add-hook! 'emacs-startup-hook :depth 101 (add-hook! 'emacs-startup-hook :depth 101
(defun doom--reset-file-handler-alist-h () (defun doom--reset-file-handler-alist-h ()
(setq file-name-handler-alist (set-default-toplevel-value
'file-name-handler-alist
;; Merge instead of overwrite because there may have been changes to ;; Merge instead of overwrite because there may have been changes to
;; `file-name-handler-alist' since startup we want to preserve. ;; `file-name-handler-alist' since startup we want to preserve.
(delete-dups (append file-name-handler-alist old-value)))))) (delete-dups (append file-name-handler-alist old-value))))))