From 7c6d5e8ff13da6900843d073a8c8856bdb536e45 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 19 Jun 2024 16:35:56 -0400 Subject: [PATCH] Reload -loaddefs when replacing built-in packages * lisp/emacs-lisp/package.el (package--reload-previously-loaded): Add new optional argument to display a specified warning upon reloading. (package-activate-1): Always reload libraries when loading built-in packages. This avoids ELPA versions of built-in packages to be mixed with the built-in package autoloads. Link: https://yhetil.org/emacs-devel/87y1adrria.fsf@localhost/ (cherry picked from commit 5878c9ae7c958af1828e85a7b4d922c1a8c1b6bf) --- lisp/emacs-lisp/package.el | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 1bc861ffaf0..f9cce4f1149 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -837,11 +837,15 @@ PKG-DESC is a `package-desc' object." (unless (equal file result) (throw 'done result)))))) -(defun package--reload-previously-loaded (pkg-desc) +(defun package--reload-previously-loaded (pkg-desc &optional warn) "Force reimportation of files in PKG-DESC already present in `load-history'. New editions of files contain macro definitions and redefinitions, the overlooking of which would cause -byte-compilation of the new package to fail." +byte-compilation of the new package to fail. +If WARN is a string, display a warning (using WARN as a format string) +before reloading the files. WARN must have two %-sequences +corresponding to package name (a symbol) and a list of files loaded (as +sexps)." (with-demoted-errors "Error in package--load-files-for-activation: %s" (let* (result (dir (package-desc-dir pkg-desc)) @@ -877,6 +881,10 @@ byte-compilation of the new package to fail." (unless (equal (file-name-base library) (format "%s-autoloads" (package-desc-name pkg-desc))) (push (cons (expand-file-name library dir) recent-index) result)))) + (when (and result warn) + (display-warning 'package + (format warn (package-desc-name pkg-desc) + (mapcar #'car result)))) (mapc (lambda (c) (load (car c) nil t)) (sort result (lambda (x y) (< (cdr x) (cdr y)))))))) @@ -904,8 +912,11 @@ correspond to previously loaded files." (if (listp package--quickstart-pkgs) ;; We're only collecting the set of packages to activate! (push pkg-desc package--quickstart-pkgs) - (when reload - (package--reload-previously-loaded pkg-desc)) + (when (or reload (assq name package--builtin-versions)) + (package--reload-previously-loaded + pkg-desc (unless reload + "Package %S is activated too late. +The following files have already been loaded: %S"))) (with-demoted-errors "Error loading autoloads: %s" (load (package--autoloads-file-name pkg-desc) nil t))) ;; Add info node. -- 2.39.5