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)
- [Frequently asked questions](#frequently-asked-questions)
- [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 Emacs customizations?](#how-to-load-emacs-customizations)
- [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`.)
### 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.
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:
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.
```elisp
(customize-set-variable 'package-archive-priorities '(("gnu" . 99)
("nongnu" . 80)
("melpa-stable" . 70)
("melpa" . 0)))
(push '("melpa-stable" . "https://stable.melpa.org/packages/") package-archives)
```
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.
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)))
```
However, the packages can sometimes be outdated.
### How to load a local lisp file for machine-specific configurations?
Add the following line to the end of your `post-init.el` file:
```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.
@@ -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
previous-minimal-emacs-user-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?

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)
(defvar minimal-emacs--success nil)
(defvar minimal-emacs--stage "early-init.el")
(defun minimal-emacs--check-success ()
"Verify that the Emacs configuration has loaded successfully."
(unless minimal-emacs--success
(cond
((and (or (string= minimal-emacs--stage "pre-early-init.el")
(string= minimal-emacs--stage "early-init.el")
(string= minimal-emacs--stage "post-early-init.el"))
(or (file-exists-p (expand-file-name "~/.emacs.el"))
(file-exists-p (expand-file-name "~/.emacs"))))
((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"))
(t
(error "Configuration error in: '%s'. Debug by starting Emacs with: emacs --debug-init"
minimal-emacs--stage)))))
(error "Configuration error. Debug by starting Emacs with: emacs --debug-init")))))
(add-hook 'emacs-startup-hook #'minimal-emacs--check-success 102)
(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)
(setq minimal-emacs--stage (file-name-nondirectory init-file))
(load init-file nil t))))
(let* ((init-file (expand-file-name filename
minimal-emacs-user-directory)))
(load init-file :no-error :no-message)))
(minimal-emacs-load-user-init "pre-early-init.el")
(setq minimal-emacs--stage "early-init.el")
(minimal-emacs-load-user-init "pre-early-init")
(setq custom-theme-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-enable-imenu-support t)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")))
(customize-set-variable 'package-archive-priorities '(("gnu" . 99)
@@ -398,7 +389,7 @@ this stage of initialization."
("melpa" . 0)))
;;; 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)

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
;; URL: https://github.com/jamescherti/minimal-emacs.d
@@ -15,11 +15,9 @@
;;; Code:
;;; Load pre-init.el
(setq minimal-emacs--stage "init.el")
(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"))
(setq minimal-emacs--stage "init.el")
;;; Before package
@@ -44,16 +42,14 @@
(when (bound-and-true-p minimal-emacs-package-initialize-and-refresh)
;; Initialize and refresh package contents again if needed
(package-initialize)
(unless (seq-empty-p package-archive-contents)
(package-refresh-contents))
;; Install use-package if necessary
(unless (package-installed-p 'use-package)
(unless (seq-empty-p package-archive-contents)
(package-refresh-contents))
(package-install 'use-package))
;; Ensure use-package is available
(eval-when-compile
(require 'use-package)))
(require 'use-package))
;;; Features, warnings, and errors
@@ -518,7 +514,7 @@
;;; Load post 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)
(provide 'init)