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

From: Xiyue Deng <[email-masked]>
Date: Fri, 27 Jun 2025 03:34:25 -0700

Hi Sean,

Sean Whitton <[email-masked]> writes:

> Hello Xiyue,
> Please add a NEWS entry

Added as a second patch.

> 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.

> On Tue 24 Jun 2025 at 04:45pm -07, Xiyue Deng wrote:
>
>> * lisp/emacs-lisp/package.el (package-builtin-packages): Add
>> * lisp/emacs-lisp/package.el (package-builtin-package-version): Add
>
> Better would be:
>
> * lisp/emacs-lisp/package.el (package-builtin-packages)
> (package-builtin-package-version): New functions.
>

Updated the commit message accordingly in the first patch.

> -- 
> Sean Whitton

PTAL.

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

* lisp/emacs-lisp/package.el (package-builtin-packages)
(package-builtin-package-version): New functions.
---
 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 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

From ceaa2b9bca4cd5a4b2023a83b7d58811d76378a8 Mon Sep 17 00:00:00 2001
From: Xiyue Deng <[email-masked]>
Date: Fri, 27 Jun 2025 03:10:24 -0700
Subject: [PATCH 2/2] Add NEWS entry for the new package public functions

* etc/NEWS: add entry for 'package-builtin-packages' and
'package-builtin-package-version'.
---
 etc/NEWS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index eb85baae341..e940b5fce17 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
 
-- 
2.47.2