Skip to content

Commit

Permalink
tweak(init): simplify the file-name-handler-alist hack
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Mar 21, 2023
1 parent 8b025d0 commit 9dd1345
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,22 @@
(when (and (version< emacs-version min-ver) (not (getenv "MINEMACS_IGNORE_VERSION_CHECK")))
(error "Emacs v%s is not supported, MinEmacs requires v%s or higher" emacs-version min-ver)))

;; HACK: Setting `file-name-handler-alist' to nil (or a useful yet simpler
;; value) should boost startup time. For more info, take a look at:
;; PERF: Setting `file-name-handler-alist' to nil should boost startup time.
;; reddit.com/r/emacs/comments/3kqt6e/2_easy_little_known_steps_to_speed_up_emacs_start
(let ((orig-value (default-toplevel-value 'file-name-handler-alist)))
(setq file-name-handler-alist
;; HACK: Adapted from Doom Emacs. If the bundled Elisp for this Emacs
;; installation isn't byte-compiled 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 purpose because it is
;; built-in to all supported versions of Emacs, and `calc' explicitly
;; loads it not compiled. This ensures that the only other, possible
;; fallback would be "calc-loaddefs.el.gz".
(unless (eval-when-compile (locate-file-internal "calc-loaddefs.el" load-path))
(list (rassq 'jka-compr-handler orig-value))))
;; Make sure the new value survives any current let-binding.
(set-default-toplevel-value 'file-name-handler-alist file-name-handler-alist)
;; Remember it so it can be reset where needed.
(put 'file-name-handler-alist 'original-value orig-value)
;; After Emacs startup, we restore `file-name-handler-alist' while conserving
;; the potential edits during startup.
(add-hook
'emacs-startup-hook
(defun +mineamcs--restore-file-handler-alist-h ()
(setq file-name-handler-alist
(delete-dups (append file-name-handler-alist
(get 'file-name-handler-alist 'original-value))))
101)))
;; Store the current value so we can reset it after Emacs startup.
(put 'file-name-handler-alist 'original-value (default-toplevel-value 'file-name-handler-alist))
;; Make sure the new value survives any current let-binding.
(set-default-toplevel-value 'file-name-handler-alist nil)
;; After Emacs startup, we restore `file-name-handler-alist' while conserving
;; the potential edits made during startup.
(add-hook
'emacs-startup-hook
(defun +mineamcs--restore-file-name-handler-alist-h ()
(setq file-name-handler-alist
(delete-dups
(append file-name-handler-alist
(get 'file-name-handler-alist 'original-value)))))
101)

;; HACK: At this point, MinEmacs variables defined in `me-vars' should be
;; already loaded (in "early-init.el"). However, we double-check here and load
Expand Down

0 comments on commit 9dd1345

Please sign in to comment.