Subject: bug#79474: [PATCH] (register-preview-info): sort registers in preview buffer

From: Masatake YAMATO <[email-masked]>
Date: Sat, 20 Sep 2025 05:02:18 +0900 (JST)

Hi,

This change makes the "*Register Preview*" buffer show sorted items.
This change is helpful a user find a non-occupied register.

Thanks
>From 8dff73143c5001049b647303d4bd5d19a32c15e7 Mon Sep 17 00:00:00 2001
From: Masatake YAMATO <[email-masked]>
Date: Thu, 18 Sep 2025 03:21:22 +0900
Subject: [PATCH] (register-preview-info): sort registers in preview buffer

* lisp/register.el (register-preview): Sort alist returned from
`register-of-type-alist'.
---
 etc/NEWS         | 4 ++++
 lisp/register.el | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index bd928345283..b57440f2e0f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -799,6 +799,10 @@ with finer grained control.
 That was already the case for the "fancy" UI but is now also true in
 the default UI you get, i.e., when 'register-use-preview' is 'traditional'.
 
+---
+*** The "*Register Preview*" buffer shows sorted items.
+This is helpful a user find a non-occupied register.
+
 ** Tree-sitter
 
 +++
diff --git a/lisp/register.el b/lisp/register.el
index 9b2a10f02d7..7dbda04d176 100644
--- a/lisp/register.el
+++ b/lisp/register.el
@@ -246,7 +246,7 @@ register-preview
         nil
         (with-current-buffer standard-output
           (setq cursor-in-non-selected-windows nil)
-          (dolist (elem registers)
+          (dolist (elem (sort registers :key #'car))
             (when (cdr elem)
               (let ((beg (point)))
                 (insert (funcall register-preview-function elem))
-- 
2.51.0