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.
This commit is contained in:
James Cherti
2025-03-14 12:28:07 -04:00
parent 1cad028382
commit 15c8b4df1b

View File

@@ -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"))))) (error "Configuration error. Debug by starting Emacs with: emacs --debug-init")))))
(add-hook 'emacs-startup-hook #'minimal-emacs--check-success 102) (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) (defun minimal-emacs-load-user-init (filename)
"Execute a file of Lisp code named FILENAME." "Execute a file of Lisp code named FILENAME."
(let ((init-file (expand-file-name filename (let ((init-file (expand-file-name filename
minimal-emacs-user-directory))) minimal-emacs-user-directory)))
(when (file-exists-p init-file) (if (not minimal-emacs-load-compiled-init-files)
(load init-file nil :no-message)))) (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") (minimal-emacs-load-user-init "pre-early-init.el")