Subject: bug#62720: 29.0.60; Not easy at all to upgrade :core packages like Eglot

From: Philip Kaludercic <[email-masked]>
Date: Sat, 15 Apr 2023 13:21:53 +0000

Eli Zaretskii <[email-masked]> writes:

>> From: Philip Kaludercic <[email-masked]>
>> Cc: [email-masked],  [email-masked],  [email-masked]
>> Date: Sat, 15 Apr 2023 11:37:40 +0000
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> 
>> >> I have no preference either way.  If you think that package-install is
>> >> fine, and João has expressed interest in that route as well, we might as
>> >> well go that way.
>> >
>> > OK, then let's do that, and thanks.
>> 
>> Great, then just to that we are on the same page, what approach do we
>> finally want to decide on?
>> 
>> - User option to enable upgrading built-in packages
>> - Prefix argument to enable upgrading built-in packages
>> - Always upgrade built-in packages
>
> The first two on emacs-29, the last one on master (if enough people
> think it's a good idea; me, I think we should wait for a while before
> deciding).

OK, so let us use this change:

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index f92afe56b76..842a475290d 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -797,6 +797,17 @@ package-built-in-p
         (require 'finder-inf nil t) ; For `package--builtins'.
         (assq package package--builtins))))))
 
+(defun package--upgradable-built-in-p (package)
+  "Return non-nil if PACKAGE if the built-in version is used."
+  (and (not (assq (cond
+                   ((package-desc-p package)
+                    (package-desc-name package))
+                   ((stringp package) (intern package))
+                   ((symbolp package) package)
+                   ((error "Unknown package format: %S" package)))
+                  (package--alist)))
+       (package-built-in-p package)))
+
 (defun package--autoloads-file-name (pkg-desc)
   "Return the absolute name of the autoloads file, sans extension.
 PKG-DESC is a `package-desc' object."
@@ -2187,7 +2198,9 @@ package-install
   "Install the package PKG.
 PKG can be a `package-desc' or a symbol naming one of the
 available packages in an archive in `package-archives'.  When
-called interactively, prompt for the package name.
+called interactively, prompt for the package name.  When invoked
+with a prefix argument, the prompt will include built-in packages
+that can be upgraded via an archive.
 
 Mark the installed package as selected by adding it to
 `package-selected-packages'.
@@ -2205,11 +2218,13 @@ package-install
      (package--archives-initialize)
      (list (intern (completing-read
                     "Install package: "
-                    (delq nil
-                          (mapcar (lambda (elt)
-                                    (unless (package-installed-p (car elt))
-                                      (symbol-name (car elt))))
-                                  package-archive-contents))
+                    (mapcan
+                     (lambda (elt)
+                       (and (or (and current-prefix-arg
+                                     (package--upgradable-built-in-p (car elt)))
+                                (not (package-installed-p (car elt))))
+                            (list (car elt))))
+                     package-archive-contents)
                     nil t))
            nil)))
   (package--archives-initialize)
@@ -2220,6 +2235,8 @@ package-install
     (unless (or dont-select (package--user-selected-p name))
       (package--save-selected-packages
        (cons name package-selected-packages)))
+    (when (package--upgradable-built-in-p pkg)
+      (setq pkg (cadr (assq name package-archive-contents))))
     (if-let* ((transaction
                (if (package-desc-p pkg)
                    (unless (package-installed-p pkg)

(I intentionally picked this one without the user option since that
will probably become unnecessary with Emacs 30+).  I believe there was
an issue with the name `package--upgradable-built-in-p' and the
docstring?

>> I argue the last option should be safe.  Semantically it would also make
>> sense, since invoking the command can be taken to be take to be an
>> explicit request, and if it is not what a user wants (I assume that João
>> think this is not probable), then it is easy to revert.
>> 
>> If we decide that this is not acceptable, then we can fall back onto the
>> patch that uses a prefix argument or a user option.
>
> Yes, that is what I think we should install on emacs-29.
>
> Thanks.

-- 
Philip Kaludercic