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

From: João Távora <[email-masked]>
Date: Tue, 11 Apr 2023 12:02:48 +0100

Philip Kaludercic <[email-masked]> writes:

> Will this not affect `package-update-all'?  I don't if we want that the
> command installs all packages from ELPA that it can find.

Thanks.  I've just tested 'M-x package-update-all' with my patch.  It
updates the built-in and the manually installed packages that can be
updated.  It _doesn't_ install any packages that weren't installed yet,
of course.

In this case, in a bare emacs-29/src/emacs -Q, it updates the Eglot
package, the Eldoc package and few others.  I think this is exactly what
M-x package-update-all is supposed to do (but see notes at the end of
this email).

So I think my change to the existing package-update and
package--updateable-packages fixes the bug cleanly.

>> Lots of consp, cdr-taking, vectorp and so on.  Besides that, it's
>> a question of taking the union of the two sets and operating on that.
> That is necessary complexity, so I don't think there is any way around it.

There is, but that's just an improvement, in this case to the
type-starved 'package--bi-desc' structure and the 'package--builtins'
built by finder.el.  A common structure format should be used.  Or,
better yet, CLOS.

Anyway, with the version of the patch I posted earlier, there are the 6
(six) packages updated currently from a "bare" emacs 29.

    (csharp-mode eglot eldoc jsonrpc transient verilog-mode)

Of these, csharp-mode and transient are mistakes.  But that's not my
patch's fault :-) 

- csharp-mode.el is merely missing version information, so package.el
  thinks that the ELPA version supersedes it (when in fact it doesn't:
  it's older). The patch adds version information to csharp-mode.el to
  fix that.

- transient.el has version information but in a header that finder.el
  doesn't recognize.  The patch has a minimal fix for that, too.

So the final patch that I'm proposing for emacs 29 is attached.  M-x
package-update-all fixes those cases and correctly finds and updates 4
packages to their newest released versions, exactly as it should.

   (eglot eldoc jsonrpc verilog-mode)

Eli, what do you think?  Who is package.el's main maintainer?  Everyone?
Lars added M-x package-update (for Emacs 29) so I'm pinging him as well.

João

>From 65e811a0fcf9ffd1f12b8b2a2d9d8a0474543b36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= <[email-masked]>
Date: Tue, 11 Apr 2023 11:52:46 +0100
Subject: [PATCH] Add ability to update built-in packages (bug#62720)

Previously package.el's M-x package-update command completely ignored
built-in packages.  With this patch in place, it updates them along
with any other manually installed non-built-in packages, as long as
the version available from ELPA is newer.

To prevent misupdates of the 'transient.el' and 'csharp-mode.el'
packages, which are built into emacs-29, version information is now
correctly collected from these two.

* lisp/finder.el (finder-compile-keywords): Be aware of
"Package-Version" header.

* lisp/emacs-lisp/package.el (package-update): Rework.
(package--updateable-packages): Rework.

* lisp/progmodes/csharp-mode.el: Add version information.
---
 lisp/emacs-lisp/package.el    | 26 ++++++++++++++++++--------
 lisp/finder.el                |  2 +-
 lisp/progmodes/csharp-mode.el |  1 +
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index f92afe56b76..286583100c3 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2243,11 +2243,16 @@ package-update
   (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))))
+         (nonbuiltin (assq package package-alist)))
+    (cond (nonbuiltin
+           (let ((desc (cadr nonbuiltin)))
+             (if (package-vc-p desc)
+                 (package-vc-update desc)
+               (package-delete desc 'force)
+               (package-install package 'dont-select))))
+          (t
+           (package-install
+            (cadr (assq package package-archive-contents)))))))
 
 (defun package--updateable-packages ()
   ;; Initialize the package system to get the list of package
@@ -2261,10 +2266,15 @@ package--updateable-packages
                  (assq (car elt) package-archive-contents)))
             (and available
                  (version-list-<
-                  (package-desc-version (cadr elt))
+                  (if (vectorp (cdr elt))
+                      (aref (cdr elt) 0)
+                    (package-desc-version (cadr elt)))
                   (package-desc-version (cadr available)))))
-          (package-vc-p (cadr (assq (car elt) package-alist)))))
-    package-alist)))
+          (and (consp (cdr elt))
+               (package-desc-p (cadr elt))
+               (package-vc-p (cadr elt)))))
+    (seq-union package-alist package--builtins
+               (lambda (a b) (eq (car a) (car b)))))))
 
 ;;;###autoload
 (defun package-update-all (&optional query)
diff --git a/lisp/finder.el b/lisp/finder.el
index 5aec0149b89..ddc6d6f03da 100644
--- a/lisp/finder.el
+++ b/lisp/finder.el
@@ -231,7 +231,7 @@ finder-compile-keywords
 		  summary  (or (cdr
 			        (assq package finder--builtins-descriptions))
 			       (lm-synopsis))
-		  version  (lm-header "version")))
+		  version  (or (lm-header "package-version") (lm-header "version"))))
 	  (when summary
 	    (setq version (or (ignore-errors (version-to-list version))
                               (alist-get package package--builtin-versions)))
diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 47cd13e7fdb..cd045cd14d1 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -8,6 +8,7 @@
 ;;              Jostein Kjønigsen <[email-masked]>
 ;; Created    : September 2022
 ;; Keywords   : c# languages oop
+;; Version    : 3.0.0
 
 ;; This file is part of GNU Emacs.
 
-- 
2.39.2