Merge pull request #45 from jamescherti/develop

Enhance pre/post*.el files loading, package refresh contents, and repositories
This commit is contained in:
James Cherti
2025-03-12 17:31:09 -04:00
committed by GitHub
3 changed files with 21 additions and 57 deletions

View File

@@ -59,7 +59,7 @@ In addition to *minimal-emacs.d*, startup speed is influenced by your computer's
- [Configuring elpaca (package manager)](#configuring-elpaca-package-manager) - [Configuring elpaca (package manager)](#configuring-elpaca-package-manager)
- [Frequently asked questions](#frequently-asked-questions) - [Frequently asked questions](#frequently-asked-questions)
- [How to display Emacs startup duration?](#how-to-display-emacs-startup-duration) - [How to display Emacs startup duration?](#how-to-display-emacs-startup-duration)
- [How to give more priority to MELPA over MELPA stable?](#how-to-give-more-priority-to-melpa-over-melpa-stable) - [How to use MELPA stable?](#how-to-use-melpa-stable)
- [How to load a local lisp file for machine-specific configurations?](#how-to-load-a-local-lisp-file-for-machine-specific-configurations) - [How to load a local lisp file for machine-specific configurations?](#how-to-load-a-local-lisp-file-for-machine-specific-configurations)
- [How to load Emacs customizations?](#how-to-load-emacs-customizations) - [How to load Emacs customizations?](#how-to-load-emacs-customizations)
- [How to increase gc-cons-threshold?](#how-to-increase-gc-cons-threshold) - [How to increase gc-cons-threshold?](#how-to-increase-gc-cons-threshold)
@@ -1070,44 +1070,21 @@ Add the following to your `~/.emacs.d/pre-early-init.el` file:
(Alternatively, you may use the built-in `M-x emacs-init-time` command to obtain the startup duration. However, `emacs-init-time` does not account for the portion of the startup process that occurs after `after-init-time`.) (Alternatively, you may use the built-in `M-x emacs-init-time` command to obtain the startup duration. However, `emacs-init-time` does not account for the portion of the startup process that occurs after `after-init-time`.)
### How to give more priority to MELPA over MELPA stable? ### How to use MELPA stable?
**Warning:** MELPA Stable is generally more reliable and thoroughly tested, as it contains stable versions of packages. On the other hand, MELPA provides bleeding-edge versions, which often include new features but may also introduce changes that could potentially break functionality. The author of *minimal-emacs.d* uses MELPA over MELPA Stable without encountering issues, but this is provided as a caution to allow you to make an informed decision based on your stability versus feature needs. To add MELPA Stable for accessing stable package versions, you can adjust the `package-archive-priorities` variable in your `~/.emacs.d/post-early-init.el` file.
By default, the *minimal-emacs.d* configuration assigns specific priorities to various package archives, which determines the order in which packages are fetched from these archives. The default priorities are as follows:
```elisp ```elisp
(customize-set-variable 'package-archive-priorities '(("gnu" . 99) (push '("melpa-stable" . "https://stable.melpa.org/packages/") package-archives)
("nongnu" . 80)
("melpa-stable" . 70)
("melpa" . 0)))
``` ```
In this configuration, the GNU, Nongnu, and MELPA Stable archives (which contain stable versions of MELPA packages) are assigned higher priorities than MELPA (which contains the latest versions of packages). As a result, packages will be fetched from MELPA Stable before MELPA. However, the packages can sometimes be outdated.
To prioritize MELPA over MELPA Stable, to access bleeding-edge package versions, you can adjust the `package-archive-priorities` variable accordingly:
```elisp
;; This change increases MELPA's priority to 75, above MELPA Stable's
;; priority of 70, ensuring that MELPA is preferred for package installations
;; over MELPA Stable.
;;
;; MELPA Stable offers reliable, tested versions, while MELPA provides newer
;; features at the risk of potential instability; for your information,
;; the author of minimal-emacs.d has been using MELPA (and not MELPA stable)
;; for years without any major issues.
(customize-set-variable 'package-archive-priorities '(("gnu" . 99)
("nongnu" . 80)
("melpa-stable" . 70)
;; MELPA priority has been changed to 75
("melpa" . 75)))
```
### How to load a local lisp file for machine-specific configurations? ### How to load a local lisp file for machine-specific configurations?
Add the following line to the end of your `post-init.el` file: Add the following line to the end of your `post-init.el` file:
```lisp ```lisp
(minimal-emacs-load-user-init "local.el") (minimal-emacs-load-user-init "local")
``` ```
This allows `local.el` to load, enabling custom configurations specific to the machine. This allows `local.el` to load, enabling custom configurations specific to the machine.
@@ -1147,7 +1124,7 @@ Add the following to the top of the `~/.emacs.d/pre-early-init.el` file to make
(unless (string= minimal-emacs-user-directory (unless (string= minimal-emacs-user-directory
previous-minimal-emacs-user-directory) previous-minimal-emacs-user-directory)
;; Load pre-early-init.el from the new directory ;; Load pre-early-init.el from the new directory
(minimal-emacs-load-user-init "pre-early-init.el"))) (minimal-emacs-load-user-init "pre-early-init")))
``` ```
### Are post-early-init.el and pre-init.el the same file in terms of the logic? ### Are post-early-init.el and pre-init.el the same file in terms of the logic?

View File

@@ -75,33 +75,25 @@ When set to non-nil, Emacs will automatically call `package-initialize' and
(setq debug-on-error minimal-emacs-debug) (setq debug-on-error minimal-emacs-debug)
(defvar minimal-emacs--success nil) (defvar minimal-emacs--success nil)
(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 (cond
((and (or (string= minimal-emacs--stage "pre-early-init.el") ((or (file-exists-p (expand-file-name "~/.emacs.el"))
(string= minimal-emacs--stage "early-init.el") (file-exists-p (expand-file-name "~/.emacs")))
(string= minimal-emacs--stage "post-early-init.el"))
(or (file-exists-p (expand-file-name "~/.emacs.el"))
(file-exists-p (expand-file-name "~/.emacs"))))
(error "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")) (error "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"))
(t (t
(error "Configuration error in: '%s'. Debug by starting Emacs with: emacs --debug-init" (error "Configuration error. Debug by starting Emacs with: emacs --debug-init")))))
minimal-emacs--stage)))))
(add-hook 'emacs-startup-hook #'minimal-emacs--check-success 102) (add-hook 'emacs-startup-hook #'minimal-emacs--check-success 102)
(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) (load init-file :no-error :no-message)))
(setq minimal-emacs--stage (file-name-nondirectory init-file))
(load init-file nil t))))
(minimal-emacs-load-user-init "pre-early-init.el") (minimal-emacs-load-user-init "pre-early-init")
(setq minimal-emacs--stage "early-init.el")
(setq custom-theme-directory (setq custom-theme-directory
(expand-file-name "themes/" minimal-emacs-user-directory)) (expand-file-name "themes/" minimal-emacs-user-directory))
@@ -389,7 +381,6 @@ this stage of initialization."
(setq use-package-always-ensure t) (setq use-package-always-ensure t)
(setq use-package-enable-imenu-support t) (setq use-package-enable-imenu-support t)
(setq package-archives '(("melpa" . "https://melpa.org/packages/") (setq package-archives '(("melpa" . "https://melpa.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/") ("gnu" . "https://elpa.gnu.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/"))) ("nongnu" . "https://elpa.nongnu.org/nongnu/")))
(customize-set-variable 'package-archive-priorities '(("gnu" . 99) (customize-set-variable 'package-archive-priorities '(("gnu" . 99)
@@ -398,7 +389,7 @@ this stage of initialization."
("melpa" . 0))) ("melpa" . 0)))
;;; Load post-early-init.el ;;; Load post-early-init.el
(minimal-emacs-load-user-init "post-early-init.el") (minimal-emacs-load-user-init "post-early-init")
(provide 'early-init) (provide 'early-init)

16
init.el
View File

@@ -1,4 +1,4 @@
;;; init.el --- Init -*- lexical-binding: t; -*- ;;; init.el --- Init -*- no-byte-compile: t; lexical-binding: t; -*-
;; Author: James Cherti ;; Author: James Cherti
;; URL: https://github.com/jamescherti/minimal-emacs.d ;; URL: https://github.com/jamescherti/minimal-emacs.d
@@ -15,11 +15,9 @@
;;; Code: ;;; Code:
;;; Load pre-init.el ;;; Load pre-init.el
(setq minimal-emacs--stage "init.el")
(if (fboundp 'minimal-emacs-load-user-init) (if (fboundp 'minimal-emacs-load-user-init)
(minimal-emacs-load-user-init "pre-init.el") (minimal-emacs-load-user-init "pre-init")
(error "The early-init.el file failed to loaded")) (error "The early-init.el file failed to loaded"))
(setq minimal-emacs--stage "init.el")
;;; Before package ;;; Before package
@@ -44,16 +42,14 @@
(when (bound-and-true-p minimal-emacs-package-initialize-and-refresh) (when (bound-and-true-p minimal-emacs-package-initialize-and-refresh)
;; Initialize and refresh package contents again if needed ;; Initialize and refresh package contents again if needed
(package-initialize) (package-initialize)
(unless (seq-empty-p package-archive-contents)
(package-refresh-contents))
;; Install use-package if necessary ;; Install use-package if necessary
(unless (package-installed-p 'use-package) (unless (package-installed-p 'use-package)
(unless (seq-empty-p package-archive-contents)
(package-refresh-contents))
(package-install 'use-package)) (package-install 'use-package))
;; Ensure use-package is available ;; Ensure use-package is available
(eval-when-compile (require 'use-package))
(require 'use-package)))
;;; Features, warnings, and errors ;;; Features, warnings, and errors
@@ -518,7 +514,7 @@
;;; Load post init ;;; Load post init
(when (fboundp 'minimal-emacs-load-user-init) (when (fboundp 'minimal-emacs-load-user-init)
(minimal-emacs-load-user-init "post-init.el")) (minimal-emacs-load-user-init "post-init"))
(setq minimal-emacs--success t) (setq minimal-emacs--success t)
(provide 'init) (provide 'init)