From 15c8b4df1be3da77b8945dbad803bbcc0f8a031e Mon Sep 17 00:00:00 2001 From: James Cherti <60946298+jamescherti@users.noreply.github.com> Date: Fri, 14 Mar 2025 12:28:07 -0400 Subject: [PATCH] Add minimal-emacs-load-nosuffix and enhance the minimal-emacs-load-user-init This will enable minimal-emacs to load byte-compiled or possibly native-compiled init files for the following initialization files: pre-init.el, post-init.el, pre-early-init.el, and post-early-init.el. --- early-init.el | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/early-init.el b/early-init.el index 0fab298..8613c6f 100644 --- a/early-init.el +++ b/early-init.el @@ -87,12 +87,33 @@ When set to non-nil, Emacs will automatically call `package-initialize' and (error "Configuration error. Debug by starting Emacs with: emacs --debug-init"))))) (add-hook 'emacs-startup-hook #'minimal-emacs--check-success 102) +(defvar minimal-emacs-load-compiled-init-files nil + "If non-nil, attempt to load byte-compiled .elc for init files. +This will enable minimal-emacs to load byte-compiled or possibly native-compiled +init files for the following initialization files: pre-init.el, post-init.el, +pre-early-init.el, and post-early-init.el.") + +(defun minimal-emacs--remove-el-file-suffix (filename) + "Remove the Elisp file suffix from FILENAME and return it (.el, .el.gz...)." + (let ((suffixes (mapcar (lambda (ext) (concat ".el" ext)) + load-file-rep-suffixes))) + (catch 'done + (dolist (suffix suffixes filename) + (when (string-suffix-p suffix filename) + (setq filename (substring filename 0 (- (length suffix)))) + (throw 'done t)))) + filename)) + (defun minimal-emacs-load-user-init (filename) "Execute a file of Lisp code named FILENAME." (let ((init-file (expand-file-name filename minimal-emacs-user-directory))) - (when (file-exists-p init-file) - (load init-file nil :no-message)))) + (if (not minimal-emacs-load-compiled-init-files) + (load init-file :no-error :no-message :nosuffix) + ;; Remove the file suffix (.el, .el.gz, etc.) to let the `load' function + ;; select between .el and .elc files. + (setq init-file (minimal-emacs--remove-el-file-suffix init-file)) + (load init-file :no-error :no-message)))) (minimal-emacs-load-user-init "pre-early-init.el")