Subject: bug#78844: 30.1; feature request: public interface for querying builtin packages and versions

From: Xiyue Deng <[email-masked]>
Date: Fri, 20 Jun 2025 21:43:09 -0700

Hi Sean,

Sean Whitton <[email-masked]> writes:

> Hello,
>
> It would be great to stabilise this interface.  We would like to add
> package system metadata to the Emacs packages in Debian to track all the
> built-in packages.  We could do various useful things with that.
>
> Thanks to Xiyue for working on this, both here and over in the Debian
> BTS.  The sample interface looks good to me.
>

Thanks for pre-approving!  I have attached a draft patch for adding
those functions.  A slight change is to query `package--builtins' for
builtin package names as it contains a larger list of builtin packages
that may not have a version defined in `package--builtin-versions'.  I
also dropped "get" from the function names as it seems not to have been
used in the current code base.

Also, for completeness, I actually find there is a `package-built-in-p'
function for checking built-in packages.  But there is no way to get a
complete list of builtin packages, so package-builtin-packages is still
needed.  I also don't check whether a package is builtin in the added
`package-builtin-package-version' function and return nil for both
non-builtin packages and builtin packages without a version, as we can
use `package-built-in-p' to check the former.

> [...]

-- 
Regards,
Xiyue Deng
From 5c49ede7ab36b2d4870941bd9b0a7cafc706ef2b Mon Sep 17 00:00:00 2001
From: Xiyue Deng <[email-masked]>
Date: Fri, 20 Jun 2025 21:34:45 -0700
Subject: [PATCH] Add public interfaces for accessing builtin package info
 (Bug#78844)

* lisp/emacs-lisp/package.el (package-builtin-packages): Add
* lisp/emacs-lisp/package.el (package-builtin-package-version): Add
---
 lisp/emacs-lisp/package.el | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 82fcf439a11..86606373ac3 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -669,6 +669,20 @@ package-alist
 loaded and/or activated, customize `package-load-list'.")
 (put 'package-alist 'risky-local-variable t)
 
+;;;; Public interfaces for accessing builtin package info
+
+(defun package-builtin-packages ()
+  "Return a list of builtin package symbols.
+The returned list is not guaranteed to be sorted."
+  (mapcar #'car package--builtins))
+
+(defun package-builtin-package-version (package)
+  "Return the version-list of PACKAGE (symbol).
+The format of the returned version-list is as returned by the
+`version-to-list' function.  Returns nil if the package is not a builtin
+package or does not have a version."
+  (alist-get package package--builtin-versions))
+
 ;;;###autoload
 (defvar package-activated-list nil
   ;; FIXME: This should implicitly include all builtin packages.
-- 
2.47.2