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

From: Philip Kaludercic <[email-masked]>
Date: Fri, 14 Apr 2023 16:40:01 +0000

Eli Zaretskii <[email-masked]> writes:

>> From: Philip Kaludercic <[email-masked]>
>> Cc: [email-masked],  [email-masked],  [email-masked],
>>   [email-masked]
>> Date: Thu, 13 Apr 2023 19:14:37 +0000
>> 
>> > Are we still sure we want to change package-install, not
>> > package-upgrade?  AFAIU, there were several voices that preferred the
>> > latter, with the rationale that a built-in package is always
>> > "installed", so "installing" it makes little or no sense.
>> 
>> If you want that, here is one proposal.  Should be the smallest so far:
>
> Hmm... looks identical to the previous patch you sent, which changes
> package-install?  Or what am I missing?
>
> As for the question I asked: I'm okay with changing package-install if
> there are no objections from those who proposed to change
> package-upgrade instead.

Did I send the wrong patch.  I double-checked now and this one should be
using package-update:

>From 7b3ca355785b7539dd417317442054647e66c045 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <[email-masked]>
Date: Thu, 13 Apr 2023 21:12:31 +0200
Subject: [PATCH] Allow 'package-update' to upgrade built-in packages

* lisp/emacs-lisp/package.el (package-update): Add support for
upgrading a built-in package to a version available from
ELPA.  (Bug#62720)
---
 lisp/emacs-lisp/package.el | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index f92afe56b76..8e7bc115a73 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2236,18 +2236,32 @@ package-install
 
 ;;;###autoload
 (defun package-update (name)
-  "Update package NAME if a newer version exists."
+  "Update package NAME if a newer version exists.
+When invoked with a prefix argument, the prompt will also include
+built-in packages that can be upgraded via a package archive."
   (interactive
    (list (completing-read
-          "Update package: " (package--updateable-packages) nil t)))
+          "Update package: "
+          (append
+           (and current-prefix-arg
+                (mapcan
+                 (lambda (elt)
+                   (and (not (assq (car elt) (package--alist)))
+                        (package-built-in-p (car elt))
+                        (list (symbol-name (car elt)))))
+                 package-archive-contents))
+           (package--updateable-packages))
+          nil t)))
   (let* ((package (if (symbolp name)
                       name
                     (intern name)))
-         (pkg-desc (cadr (assq package package-alist))))
-    (if (package-vc-p pkg-desc)
-        (package-vc-update pkg-desc)
-      (package-delete pkg-desc 'force)
-      (package-install package 'dont-select))))
+         (old-desc (cadr (assq package package-alist)))
+         (new-desc (cadr (assq package package-archive-contents))))
+    (if (and old-desc (package-vc-p old-desc))
+        (package-vc-update old-desc)
+      (when old-desc
+        (package-delete old-desc 'force))
+      (package-install new-desc 'dont-select))))
 
 (defun package--updateable-packages ()
   ;; Initialize the package system to get the list of package
-- 
2.39.2