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

From: Xiyue Deng <[email-masked]>
Date: Fri, 27 Jun 2025 05:54:18 -0700

Hi Sean,

Sean Whitton <[email-masked]> writes:

> Hello,
>
> On Fri 27 Jun 2025 at 03:34am -07, Xiyue Deng wrote:
>
>> Hi Sean,
>>
>> Sean Whitton <[email-masked]> writes:
>>
>>> Hello Xiyue,
>>>
>>> Please add a NEWS entry
>>
>> Added as a second patch.
>
> Please merge them into one patch.
>

Squashed into one now.

>>> and see if these packages need documentation in the Elisp manual (they
>>> may or may not).
>>>
>>
>> I don't seem to find any Elisp manual for package.el (there is one in
>> the Emacs manual but only has documents for user facing interfaces for
>> the package buffer).  But do let me know if there is.
>
> I don't know, that's why I was asking you to look :)
>

Ah OK, guess there is no need to update then.

> If there isn't anywhere to update, then you should use "---" not "+++"
> in etc/NEWS.
>

Didn't notice the difference.  Now changed to "---".

> -- 
> Sean Whitton

PTAL.

-- 
Regards,
Xiyue Deng
From c6fd97bfa83c9bbd234bee48029e526033e5c11b 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)
(package-builtin-package-version): New functions.
* etc/NEWS: add entry for 'package-builtin-packages' and
'package-builtin-package-version'.
---
 etc/NEWS                   |  7 +++++++
 lisp/emacs-lisp/package.el | 14 ++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index eb85baae341..9a5c46947a8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2607,6 +2607,13 @@ sleep state.
 and set the top-level buffer-local value of a variable.  A top-level
 value is the one that variable has outside of any let-bindings.
 
+---
+** New functions to query builtin package information.
+'package-builtin-packages' returns a list of symbols of built-in
+packages; 'package-builtin-package-version' returns the version-list of
+a given package symbol.  These functions provide stable interfaces for
+external tools to query built-in package information.
+
 
 * Changes in Emacs 31.1 on Non-Free Operating Systems
 
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 9bcffb1df0b..a5e04413c72 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 built-in 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--builtin-versions))
+
+(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