Enhance minimal-emacs--check-success and update README.md

This commit is contained in:
James Cherti
2025-03-08 09:21:27 -05:00
parent 8f8134a072
commit 3ecc85aa72
3 changed files with 20 additions and 9 deletions

View File

@@ -17,7 +17,7 @@ The author uses *minimal-emacs.d* as his `early-init.el` and `init.el`, alongsid
*(The theme shown in the screenshot above is the *[tomorrow-night-deepblue-theme.el](https://github.com/jamescherti/tomorrow-night-deepblue-theme.el)*, available on MELPA.)* *(The theme shown in the screenshot above is the *[tomorrow-night-deepblue-theme.el](https://github.com/jamescherti/tomorrow-night-deepblue-theme.el)*, available on MELPA.)*
In addition to *minimal-emacs.d*, startup speed is influenced by your computer's processing power and disk speed. To establish a baseline, start Emacs with only *minimal-emacs.d* and no additional configurations, then run `M-x emacs-init-time`. Incrementally modify your init files and observe the impact on startup time. For consistent comparisons, always test on the same computer and Emacs version. It's also important to ensure that all packages are deferred using `:defer t` and `:commands`, which makes Emacs load them only when needed (see additional examples in this README.md). In addition to *minimal-emacs.d*, startup speed is influenced by your computer's processing power and disk speed. To establish a baseline, start Emacs with only *minimal-emacs.d* and no additional configurations, then run `M-x emacs-init-time`. Incrementally modify your init files and observe the impact on startup time. For consistent comparisons, always test on the same computer and Emacs version. It's also important to ensure that all packages are deferred using `:defer t` and `:commands`, which makes Emacs load them only when needed (see additional examples in this README.md). While startup time is important, other factors, like native compilation, are even more important. Although native compilation may introduce some brief initial and negligible initial delay, it is beneficial in the long run as it significantly speeds up Emacs.
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc --> <!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
## Table of Contents ## Table of Contents

View File

@@ -32,7 +32,7 @@ turned on.")
(defvar minimal-emacs-frame-title-format "%b Emacs" (defvar minimal-emacs-frame-title-format "%b Emacs"
"Template for displaying the title bar of visible and iconified frame.") "Template for displaying the title bar of visible and iconified frame.")
(defvar minimal-emacs-debug nil (defvar minimal-emacs-debug (bound-and-true-p init-file-debug)
"Non-nil to enable debug.") "Non-nil to enable debug.")
(defvar minimal-emacs-gc-cons-threshold (* 16 1024 1024) (defvar minimal-emacs-gc-cons-threshold (* 16 1024 1024)
@@ -71,25 +71,35 @@ minimalistic appearance during startup.")
;;; Load pre-early-init.el ;;; Load pre-early-init.el
;; Prefer loading newer compiled files
(setq load-prefer-newer t)
(defvar minimal-emacs--success nil) (defvar minimal-emacs--success nil)
(defvar minimal-emacs--stage "early-init.el") (defvar minimal-emacs--stage "early-init.el")
(defun minimal-emacs--check-success () (defun minimal-emacs--check-success ()
"Verify that the Emacs configuration has loaded successfully." "Verify that the Emacs configuration has loaded successfully."
(unless minimal-emacs--success (unless minimal-emacs--success
(cond
((let ((user-init-basename (file-name-nondirectory user-init-file)))
(and (not (string= user-init-basename "init.el"))
(not (string= user-init-basename "early-init.el"))))
(error (concat "Emacs ignored loading 'init.el'. Please ensure "
"that files such as ~/.emacs or ~/.emacs.el do not exist, "
"as they may be preventing Emacs from loading the"
" 'init.el' file.")
(expand-file-name "init.el" minimal-emacs-user-directory)))
(error (concat "Configuration error in: '%s'. Debug by starting Emacs " (error (concat "Configuration error in: '%s'. Debug by starting Emacs "
"with: emacs --debug-init") "with: emacs --debug-init")
minimal-emacs--stage))) minimal-emacs--stage))))
(add-hook 'emacs-startup-hook #'minimal-emacs--check-success 102) (add-hook 'emacs-startup-hook #'minimal-emacs--check-success 102)
;; Prefer loading newer compiled files
(setq load-prefer-newer t)
(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) (when (file-exists-p init-file)
(setq minimal-emacs--stage init-file) (setq minimal-emacs--stage (file-name-nondirectory init-file))
(load init-file nil t t)))) (load init-file nil t t))))
(minimal-emacs-load-user-init "pre-early-init.el") (minimal-emacs-load-user-init "pre-early-init.el")

View File

@@ -15,6 +15,7 @@
;;; Code: ;;; Code:
;;; Load pre-init.el ;;; Load pre-init.el
(setq minimal-emacs--stage "init.el")
(minimal-emacs-load-user-init "pre-init.el") (minimal-emacs-load-user-init "pre-init.el")
(setq minimal-emacs--stage "init.el") (setq minimal-emacs--stage "init.el")