From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Thierry Volpiatto <thievol@posteo.net>
Newsgroups: gmane.emacs.bugs
Subject: bug#66394: 29.1; Make register-read-with-preview more useful
Date: Fri, 15 Dec 2023 14:45:49 +0000
Message-ID: <87r0jn4j8i.fsf@posteo.net>
References: <87il7ib6cu.fsf@posteo.net> <83il5pbnmh.fsf@gnu.org>
 <87zfz1cz7s.fsf@posteo.net> <83bkbc7j1o.fsf@gnu.org>
 <8734wov2wv.fsf@posteo.net> <83v89j6arv.fsf@gnu.org>
 <87cyvpf8y6.fsf@posteo.net> <83plzp82mb.fsf@gnu.org>
 <87a5qhxf05.fsf@posteo.net> <83jzpkvs4z.fsf@gnu.org>
 <87v8947ulo.fsf@posteo.net> <871qbsk5le.fsf@posteo.net>
 <f7f749d1-3a2d-0ea0-a106-6c586f4faca7@gutov.dev>
 <87v894hr2e.fsf@posteo.net> <87cyvbepi0.fsf@posteo.net>
 <87bkavk9nv.fsf@posteo.net>
 <8eebbb30-9366-e869-a39a-8100638cb99a@gutov.dev>
 <87o7etgxeb.fsf@posteo.net> <83v891qlcn.fsf@gnu.org>
 <jwvfs04hjm9.fsf-monnier+emacs@gnu.org>
 <CADwFkmm3H9+-nrYi0JQM9YT0_ZYU3SYvcqfmEnEpJWWaZzHTGQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: multipart/signed; boundary="==-=-=";
 micalg=pgp-sha512; protocol="application/pgp-signature"
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="34726"; mail-complaints-to="usenet@ciao.gmane.io"
Cc: michael_heerdegen@web.de, dmitry@gutov.dev, Eli Zaretskii <eliz@gnu.org>,
 Stefan Monnier <monnier@iro.umontreal.ca>, 66394@debbugs.gnu.org
To: Stefan Kangas <stefankangas@gmail.com>
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 15 15:47:31 2023
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1rE9TO-0008qy-GV
	for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Dec 2023 15:47:30 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces@gnu.org>)
	id 1rE9Sz-0004iK-SD; Fri, 15 Dec 2023 09:47:06 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1rE9Sx-0004hi-Fv
 for bug-gnu-emacs@gnu.org; Fri, 15 Dec 2023 09:47:04 -0500
Original-Received: from debbugs.gnu.org ([2001:470:142:5::43])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1rE9Sw-0005HG-TB
 for bug-gnu-emacs@gnu.org; Fri, 15 Dec 2023 09:47:03 -0500
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1rE9Sw-0004Ft-JV
 for bug-gnu-emacs@gnu.org; Fri, 15 Dec 2023 09:47:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Thierry Volpiatto <thievol@posteo.net>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Fri, 15 Dec 2023 14:47:02 +0000
Resent-Message-ID: <handler.66394.B66394.170265156716087@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 66394
X-GNU-PR-Package: emacs
Original-Received: via spool by 66394-submit@debbugs.gnu.org id=B66394.170265156716087
 (code B ref 66394); Fri, 15 Dec 2023 14:47:02 +0000
Original-Received: (at 66394) by debbugs.gnu.org; 15 Dec 2023 14:46:07 +0000
Original-Received: from localhost ([127.0.0.1]:51818 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1rE9S1-00049T-UH
 for submit@debbugs.gnu.org; Fri, 15 Dec 2023 09:46:07 -0500
Original-Received: from mout02.posteo.de ([185.67.36.66]:38183)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <thievol@posteo.net>) id 1rE9Rz-0003v2-A0
 for 66394@debbugs.gnu.org; Fri, 15 Dec 2023 09:46:05 -0500
Original-Received: from submission (posteo.de [185.67.36.169]) 
 by mout02.posteo.de (Postfix) with ESMTPS id 5DA27240105
 for <66394@debbugs.gnu.org>; Fri, 15 Dec 2023 15:45:57 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1702651557; bh=qfIZ/KMlt40K3I53G7Ecop+JXyMGt3q/HouwsIHgYIM=;
 h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Autocrypt:OpenPGP:
 From;
 b=UPQ+FQLoPwet4JOBdrsCwyNYNd84dkWN4sTGRGbFEZOHKQ8pUMFWQZosdN1nVXVtY
 rTnL9EmccdP9WPYCScbHh44XvzpKM8oKdU488/Syg2b2Qeb6zzbmhfhiOJMa+jjOeB
 yr/OtZ1N73lNYbvLsfywt53Un2eO88PbpQak628q6IzBQVfXdZvS53TmBkJF3QpZ8h
 9cozi/Ap1afTCyAvpNnGLQOb7y1bedwS9B/HQciHgU4rKaSPHjCS9zc0PoBbdns7xW
 q7p6DQOBznEI4UzUDINuTOSGHcmUWJK183b1dcvcXd8K+KkPVJpW0cE628HAddWD+f
 uDyrgCze+yhUA==
Original-Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4SsBq50DXHz6v1H;
 Fri, 15 Dec 2023 15:45:52 +0100 (CET)
In-Reply-To: <CADwFkmm3H9+-nrYi0JQM9YT0_ZYU3SYvcqfmEnEpJWWaZzHTGQ@mail.gmail.com>
 (Stefan Kangas's message of "Thu, 14 Dec 2023 12:29:04 -0800 (18
 hours, 6 minutes, 4 seconds ago)")
Autocrypt: addr=thievol@posteo.net; prefer-encrypt=mutual;
 keydata=xsDNBF8ylcIBDADG+hy+zR6L4/vbdDDZuSaMmSrU3A5QZJpeBCvxTr7MpzzruZbhLPW1K3R6N2MA
 edi8Y+C8o27FVRIjpdbaKMGu9je7JV/TbUQYo3SOwCK1vM4LUn4V6ZLzSYkuiEt4eyMoiDdyvN0p
 kcK6P9x9DCetcEVszXzQg+yzCVrQ2hXWDXWT4M18EC3wtO7RHPouMqGiwBFhBAYErCqFWFxQHkfb
 tG/4yGyJ58rglb65O3qijjMWvYwcWZun9/7qm8Z4/4mHopmo2zgU+OrptnLSZfkZGz3Y7Uf452xQ
 GVq0Fv75NPvQru7y+DYVhuVXXyAmGxt+vf4rIiixMBbhKEPjcxEPAa2LTzex2IsTZR+QVG9uDnqC
 WcgaOEQ58fzXNvNhtwwF/Rgio2XWAJVdmFWS59/k9W58CIUSNKBMZh2XeGdEmtHvDtCxW3z6FJha
 36RzOM3fMNNiAGdFZJA84gcdloJR+sHCDTTPT3784fjr+V8An7sI581NGFzkRQqPvEQCZbUAEQEA
 Ac0SdGhpZXZvbEBwb3N0ZW8ubmV0wsEOBBMBCgA4AhsDBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheA
 FiEEI9twfRN7r3nig/xwDsVtFB0W75MFAmL3HCoACgkQDsVtFB0W75OVEAv/f6XxmtIFz08fUb8h
 Bp/zJP6IC4/rhhh+0GMRIRzLN8DK0jV8JCzYdFHiRJOy2lNIOpmrrCmjRRxferc2G42+ePFIsslx
 hU46VSz1Z83NwIG3mpdYNV5WUTUdgzxExHTNTFCd7NKv0nlHKQaA 
OpenPGP: url=https://posteo.de/keys/thievol@posteo.net.asc; preference=encrypt
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.bugs:276271
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/276271>

--==-=-=
Content-Type: multipart/mixed; boundary="=-=-="

--=-=-=
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Stefan Kangas <stefankangas@gmail.com> writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>>> What do others think about making this the default?
>>
>> My understanding is that usage style of registers varies a lot, where
>> some people use them extensively, so any change that makes them
>> heavier/slower (such a requiring a confirmation) will alienate them.
>> For that reason I'd opt to keep the defaults as close to the previous
>> behavior, focusing on making the new features discoverable rather than
>> enabled by default.
>
> +1

I just fixed a bug with register-use-preview =3D nil about its usage
with kmacros.
So I guess it is now possible to make it the default.
In these patches (attached) I also fixed the problem of Dmitri with windows
configuration (let me know if it works), BTW I guess this bug was
already here before these changes.

Thanks all for your feedback.

PS: I didn't have the time to look in delayed preview request, will do
as soon as possible.

=2D-=20
Thierry

--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0001-Don-t-confirm-with-RET-even-when-overwriting-in-regi.patch
Content-Transfer-Encoding: quoted-printable

From=20c83e6132f33c1ab7f6baf63f85aed32f32e8177c Mon Sep 17 00:00:00 2001
From: Thierry Volpiatto <thievol@posteo.net>
Date: Mon, 11 Dec 2023 07:02:40 +0100
Subject: [PATCH 1/4] Don't confirm with RET even when overwriting in regist=
er
 commands

This happen when register-use-preview is nil or never.
This reproduce what we had previously in 29.1 but with filtering in
the preview and default registers are provided for the commands of
type 'set'.

This is implemented with cl-defmethod to keep the code as much as
possible configurable.

* lisp/register.el (register-preview-info): New slot.
(register-command-info): Add new methods for copy-to-register,
point-to-register, number-to-register,
window-configuration-to-register, frameset-to-register and
copy-rectangle-to-register.
(register-read-with-preview): Bind noconfirm.
=2D--
 lisp/register.el | 67 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 56 insertions(+), 11 deletions(-)

diff --git a/lisp/register.el b/lisp/register.el
index fa4bbcf483f..cc4770579ee 100644
=2D-- a/lisp/register.el
+++ b/lisp/register.el
@@ -156,7 +156,7 @@ TYPES are the types of register supported.
 MSG is the minibuffer message to send when a register is selected.
 ACT is the type of action the command is doing on register.
 SMATCH accept a boolean value to say if command accept non matching regist=
er."
=2D  types msg act smatch)
+  types msg act smatch noconfirm)
=20
 (cl-defgeneric register-command-info (command)
   "Returns a `register-preview-info' object storing data for COMMAND."
@@ -179,24 +179,66 @@ SMATCH accept a boolean value to say if command accep=
t non matching register."
    :types '(all)
    :msg "View register `%s'"
    :act 'view
+   :noconfirm (memq register-use-preview '(nil never))
    :smatch t))
 (cl-defmethod register-command-info ((_command (eql append-to-register)))
   (make-register-preview-info
    :types '(string number)
    :msg "Append to register `%s'"
    :act 'modify
+   :noconfirm (memq register-use-preview '(nil never))
    :smatch t))
 (cl-defmethod register-command-info ((_command (eql prepend-to-register)))
   (make-register-preview-info
    :types '(string number)
    :msg "Prepend to register `%s'"
    :act 'modify
+   :noconfirm (memq register-use-preview '(nil never))
    :smatch t))
 (cl-defmethod register-command-info ((_command (eql increment-register)))
   (make-register-preview-info
    :types '(string number)
    :msg "Increment register `%s'"
    :act 'modify
+   :noconfirm (memq register-use-preview '(nil never))
+   :smatch t))
+(cl-defmethod register-command-info ((_command (eql copy-to-register)))
+  (make-register-preview-info
+   :types '(all)
+   :msg "Copy to register `%s'"
+   :act 'set
+   :noconfirm (memq register-use-preview '(nil never))))
+(cl-defmethod register-command-info ((_command (eql point-to-register)))
+  (make-register-preview-info
+   :types '(all)
+   :msg "Point to register `%s'"
+   :act 'set
+   :noconfirm (memq register-use-preview '(nil never))))
+(cl-defmethod register-command-info ((_command (eql number-to-register)))
+  (make-register-preview-info
+   :types '(all)
+   :msg "Number to register `%s'"
+   :act 'set
+   :noconfirm (memq register-use-preview '(nil never))))
+(cl-defmethod register-command-info
+    ((_command (eql window-configuration-to-register)))
+  (make-register-preview-info
+   :types '(all)
+   :msg "Window configuration to register `%s'"
+   :act 'set
+   :noconfirm (memq register-use-preview '(nil never))))
+(cl-defmethod register-command-info ((_command (eql frameset-to-register)))
+  (make-register-preview-info
+   :types '(all)
+   :msg "Frameset to register `%s'"
+   :act 'set
+   :noconfirm (memq register-use-preview '(nil never))))
+(cl-defmethod register-command-info ((_command (eql copy-rectangle-to-regi=
ster)))
+  (make-register-preview-info
+   :types '(all)
+   :msg "Copy rectangle to register `%s'"
+   :act 'set
+   :noconfirm (memq register-use-preview '(nil never))
    :smatch t))
=20
 (defun register-preview-forward-line (arg)
@@ -328,12 +370,13 @@ display such a window regardless."
                 m))
          (data (register-command-info this-command))
          (enable-recursive-minibuffers t)
=2D         types msg result timer act win strs smatch)
+         types msg result timer act win strs smatch noconfirm)
     (if data
=2D        (setq types  (register-preview-info-types data)
=2D              msg    (register-preview-info-msg   data)
=2D              act    (register-preview-info-act   data)
=2D              smatch (register-preview-info-smatch data))
+        (setq types     (register-preview-info-types data)
+              msg       (register-preview-info-msg   data)
+              act       (register-preview-info-act   data)
+              smatch    (register-preview-info-smatch data)
+              noconfirm (register-preview-info-noconfirm data))
       (setq types '(all)
             msg   "Overwrite register `%s'"
             act   'set))
@@ -400,13 +443,15 @@ display such a window regardless."
                                          "Register `%s' is empty" pat))))))
                             (unless (string=3D pat "")
                               (with-selected-window (minibuffer-window)
=2D                                (if (and (member pat strs) (memq act '(s=
et modify)))
+                                (if (and (member pat strs)
+                                         (memq act '(set modify))
+                                         (null noconfirm))
                                     (with-selected-window (minibuffer-wind=
ow)
                                       (minibuffer-message msg pat))
=2D                                  ;; An empty register or an existing
=2D                                  ;; one but the action is insert or
=2D                                  ;; jump, don't ask for confirmation
=2D                                  ;; and exit immediately (bug#66394).
+                                  ;; The action is insert or
+                                  ;; jump or noconfirm is specifed
+                                  ;; explicitely, don't ask for
+                                  ;; confirmation and exit immediately (bu=
g#66394).
                                   (setq result pat)
                                   (exit-minibuffer)))))))))
              (setq result (read-from-minibuffer
=2D-=20
2.34.1


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0002-Provide-emacs-29-behavior-for-register-preview.patch
Content-Transfer-Encoding: quoted-printable

From=2031effd1956d78810bd197abd746b84a48474911d Mon Sep 17 00:00:00 2001
From: Thierry Volpiatto <thievol@posteo.net>
Date: Tue, 12 Dec 2023 07:24:32 +0100
Subject: [PATCH 2/4] Provide emacs-29 behavior for register-preview

It is now the default with a value of register-use-preview eq to
basic.
To change this one have now to customize register-use-preview to
another value.

* lisp/register.el (register-preview-delay): Remove obsolescence.
(register--read-with-preview-function): New.
(register-use-preview): New option basic, it is now the default.
(register-preview-default-1): New the register-preview-default used by
`register-read-with-preview-fancy`.
(register-preview-default): Restored (same as Emacs-29).
(register--preview-function): Generic fn that return the right
function for register--preview-function.
(register-preview): Restored (same behavior as Emacs-29).
(register-preview-1): Used by `register-read-with-preview-fancy'.
(register-read-with-preview-basic): The old
register-read-with-preview.
(register-read-with-preview-fancy): The new
register-read-with-preview.
=2D--
 lisp/register.el | 156 +++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 132 insertions(+), 24 deletions(-)

diff --git a/lisp/register.el b/lisp/register.el
index cc4770579ee..1ef6189682e 100644
=2D-- a/lisp/register.el
+++ b/lisp/register.el
@@ -100,25 +100,55 @@ If nil, do not show register previews, unless `help-c=
har' (or a member of
   :version "24.4"
   :type '(choice number (const :tag "No preview unless requested" nil))
   :group 'register)
=2D(make-obsolete-variable 'register-preview-delay "No longer used." "30.1")
=20
 (defcustom register-preview-default-keys (mapcar #'string (number-sequence=
 ?a ?z))
   "Default keys for setting a new register."
=2D  :type '(repeat string))
=2D
=2D(defcustom register-use-preview t
=2D  "Whether to show preview of registers.
=2D
=2DIf the value is t, show a preview buffer with navigation and highlightin=
g.
=2DIf the value is nil, show a basic preview buffer and exit minibuffer
=2Dimmediately after the register name is inserted into minibuffer.
=2DIf the value is \\=3D'never, behave as for nil, but with no preview buff=
er
=2Dat all."
+  :type '(repeat string)
+  :version 30.1)
+
+(defvar register--read-with-preview-function nil
+  "The register read preview function to use.
+Two functions are provided, one that provide navigation and
+highlighting of the register selected, filtering of register
+according to command in use, defaults register to use when
+setting a new register, confirmation and notification when you
+are about to overwrite a register and generic functions to
+configure how each existing commands behave.  The other function
+provided is the same as what was used in Emacs-29, no filtering,
+no navigation, no defaults.")
+
+(defvar register-preview-function nil
+  "Function to format a register for previewing.
+Called with one argument, a cons (NAME . CONTENTS) as found in `register-a=
list'.
+The function should return a string, the description of the argument.
+It is set according to the value of `register--read-with-preview-function'=
.")
+
+(defcustom register-use-preview 'basic
+  "Maybe show register preview.
+
+This has no effect when `register--read-with-preview-function' value
+is `register-read-with-preview-basic'.
+
+When set to `t' show a preview buffer with navigation and highlighting.
+When nil show a basic preview buffer and exit minibuffer
+immediately after insertion in minibuffer.
+When set to \\=3D'never behave as above but with no preview buffer at
+all.
+When set to \\=3D'basic provide a much more basic preview according to
+`register-preview-delay', it has the exact same behavior as in Emacs-29."
   :type '(choice
           (const :tag "Use preview" t)
           (const :tag "Use quick preview" nil)
=2D          (const :tag "Never use preview" never))
=2D  :version "30.1")
+          (const :tag "Never use preview" never)
+          (const :tag "Basic preview like Emacs-29" basic))
+  :version 30.1
+  :set (lambda (var val)
+         (set var val)
+         (setq register--read-with-preview-function
+               (if (eq val 'basic)
+                   #'register-read-with-preview-basic
+                 #'register-read-with-preview-fancy))
+         (setq register-preview-function nil)))
=20
 (defun get-register (register)
   "Return contents of Emacs register named REGISTER, or nil if none."
@@ -138,17 +168,28 @@ See the documentation of the variable `register-alist=
' for possible VALUEs."
         (substring d (match-end 0))
       d)))
=20
=2D(defun register-preview-default (r)
+(defun register-preview-default-1 (r)
   "Function that is the default value of the variable `register-preview-fu=
nction'."
   (format "%s: %s\n"
 	  (propertize (string (car r))
                       'display (single-key-description (car r)))
 	  (register-describe-oneline (car r))))
=20
=2D(defvar register-preview-function #'register-preview-default
=2D  "Function to format a register for previewing.
=2DCalled with one argument, a cons (NAME . CONTENTS) as found in `register=
-alist'.
=2DThe function should return a string, the description of the argument.")
+(defun register-preview-default (r)
+  "Function that is the default value of the variable `register-preview-fu=
nction'."
+  (format "%s: %s\n"
+	  (single-key-description (car r))
+	  (register-describe-oneline (car r))))
+
+(cl-defgeneric register--preview-function (read-preview-function)
+  "Returns a function to format a register for previewing.
+This according to the value of READ-PREVIEW-FUNCTION.")
+(cl-defmethod register--preview-function ((_read-preview-function
+                                           (eql register-read-with-preview=
-basic)))
+  #'register-preview-default)
+(cl-defmethod register--preview-function ((_read-preview-function
+                                           (eql register-read-with-preview=
-fancy)))
+  #'register-preview-default-1)
=20
 (cl-defstruct register-preview-info
   "Store data for a specific register command.
@@ -310,9 +351,9 @@ satisfy `cl-typep' otherwise the new type should be def=
ined with
 (cl-defmethod register--type ((_regval string)) 'string)
 (cl-defmethod register--type ((_regval number)) 'number)
 (cl-defmethod register--type ((_regval marker)) 'marker)
=2D(cl-defmethod register--type ((_regval (eql 'buffer))) 'buffer)
=2D(cl-defmethod register--type ((_regval (eql 'file))) 'file)
=2D(cl-defmethod register--type ((_regval (eql 'file-query))) 'file-query)
+(cl-defmethod register--type ((_regval (eql buffer))) 'buffer)
+(cl-defmethod register--type ((_regval (eql file))) 'file)
+(cl-defmethod register--type ((_regval (eql file-query))) 'file-query)
 (cl-defmethod register--type ((_regval window-configuration)) 'window)
 (cl-deftype frame-register () '(satisfies frameset-register-p))
 (cl-defmethod register--type :extra "frame-register" (_regval) 'frame)
@@ -327,12 +368,39 @@ satisfy `cl-typep' otherwise the new type should be d=
efined with
              when (memq (register-type register) types)
              collect register)))
=20
=2D(defun register-preview (buffer &optional show-empty types)
+(defun register-preview (buffer &optional show-empty)
   "Pop up a window showing the registers preview in BUFFER.
 If SHOW-EMPTY is non-nil, show the window even if no registers.
+Format of each entry is controlled by the variable `register-preview-funct=
ion'."
+  (unless register-preview-function
+    (setq register-preview-function (register--preview-function
+                                     register--read-with-preview-function)=
))
+  (when (or show-empty (consp register-alist))
+    (with-current-buffer-window
+     buffer
+     (cons 'display-buffer-below-selected
+	   '((window-height . fit-window-to-buffer)
+	     (preserve-size . (nil . t))))
+     nil
+     (with-current-buffer standard-output
+       (setq cursor-in-non-selected-windows nil)
+       (mapc (lambda (elem)
+               (when (get-register (car elem))
+                 (insert (funcall register-preview-function elem))))
+             register-alist)))))
+
+(defun register-preview-1 (buffer &optional show-empty types)
+  "Pop up a window showing the registers preview in BUFFER.
+
+This is the preview function use with
+`register-read-with-preview-fancy' function.
+If SHOW-EMPTY is non-nil, show the window even if no registers.
 Argument TYPES (a list) specify the types of register to show, when nil sh=
ow all
 registers, see `register-type' for suitable types.
 Format of each entry is controlled by the variable `register-preview-funct=
ion'."
+  (unless register-preview-function
+    (setq register-preview-function (register--preview-function
+                                     register--read-with-preview-function)=
))
   (let ((registers (register-of-type-alist (or types '(all)))))
     (when (or show-empty (consp registers))
       (with-current-buffer-window
@@ -360,6 +428,46 @@ Format of each entry is controlled by the variable `re=
gister-preview-function'."
   "Read and return a register name, possibly showing existing registers.
 Prompt with the string PROMPT.
 If `help-char' (or a member of `help-event-list') is pressed,
+display such a window regardless."
+  (funcall register--read-with-preview-function prompt))
+
+(defun register-read-with-preview-basic (prompt)
+  "Read and return a register name, possibly showing existing registers.
+Prompt with the string PROMPT.  If `register-alist' and
+`register-preview-delay' are both non-nil, display a window
+listing existing registers after `register-preview-delay' seconds.
+If `help-char' (or a member of `help-event-list') is pressed,
+display such a window regardless."
+  (let* ((buffer "*Register Preview*")
+	 (timer (when (numberp register-preview-delay)
+		  (run-with-timer register-preview-delay nil
+				  (lambda ()
+				    (unless (get-buffer-window buffer)
+				      (register-preview buffer))))))
+	 (help-chars (cl-loop for c in (cons help-char help-event-list)
+			      when (not (get-register c))
+			      collect c)))
+    (unwind-protect
+	(progn
+	  (while (memq (read-key (propertize prompt 'face 'minibuffer-prompt))
+		       help-chars)
+	    (unless (get-buffer-window buffer)
+	      (register-preview buffer 'show-empty)))
+          (when (or (eq ?\C-g last-input-event)
+                    (eq 'escape last-input-event)
+                    (eq ?\C-\[ last-input-event))
+            (keyboard-quit))
+	  (if (characterp last-input-event) last-input-event
+	    (error "Non-character input-event")))
+      (and (timerp timer) (cancel-timer timer))
+      (let ((w (get-buffer-window buffer)))
+        (and (window-live-p w) (delete-window w)))
+      (and (get-buffer buffer) (kill-buffer buffer)))))
+
+(defun register-read-with-preview-fancy (prompt)
+  "Read and return a register name, possibly showing existing registers.
+Prompt with the string PROMPT.
+If `help-char' (or a member of `help-event-list') is pressed,
 display such a window regardless."
   (let* ((buffer "*Register Preview*")
          (buffer1 "*Register quick preview*")
@@ -392,13 +500,13 @@ display such a window regardless."
                        ;; Do nothing when buffer1 is in use.
                        (unless (get-buffer-window buf)
                          (with-selected-window (minibuffer-selected-window)
=2D                           (register-preview buffer 'show-empty types)))=
)))
+                           (register-preview-1 buffer 'show-empty types)))=
)))
     (define-key map (kbd "<down>") 'register-preview-next)
     (define-key map (kbd "<up>")   'register-preview-previous)
     (define-key map (kbd "C-n")    'register-preview-next)
     (define-key map (kbd "C-p")    'register-preview-previous)
     (unless (or executing-kbd-macro (eq register-use-preview 'never))
=2D      (register-preview buf nil types))
+      (register-preview-1 buf nil types))
     (unwind-protect
          (progn
            (minibuffer-with-setup-hook
=2D-=20
2.34.1


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0003-Save-and-restore-win-confs-after-register-commands.patch
Content-Transfer-Encoding: quoted-printable

From=208d81687b7e58ae9e36a2a405f98976b05aaffe28 Mon Sep 17 00:00:00 2001
From: Thierry Volpiatto <thievol@posteo.net>
Date: Thu, 14 Dec 2023 16:23:26 +0100
Subject: [PATCH 3/4] Save and restore win confs after register commands

When several windows are open, the register preview may eat other
windows and break the current window configuration.

* lisp/register.el (register-read-with-preview-fancy): Do it.
=2D--
 lisp/register.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/register.el b/lisp/register.el
index 1ef6189682e..43dad90778c 100644
=2D-- a/lisp/register.el
+++ b/lisp/register.el
@@ -473,6 +473,7 @@ display such a window regardless."
          (buffer1 "*Register quick preview*")
          (buf (if register-use-preview buffer buffer1))
          (pat "")
+         (winconf (current-window-configuration))
          (map (let ((m (make-sparse-keymap)))
                 (set-keymap-parent m minibuffer-local-map)
                 m))
@@ -568,6 +569,7 @@ display such a window regardless."
                       nil "No register specified")
            (string-to-char result))
       (when timer (cancel-timer timer))
+      (set-window-configuration winconf)
       (let ((w (get-buffer-window buf)))
         (and (window-live-p w) (delete-window w)))
       (and (get-buffer buf) (kill-buffer buf)))))
=2D-=20
2.34.1


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0004-Fix-register-commands-in-kmacros.patch
Content-Transfer-Encoding: quoted-printable

From=20382feaaa808946cde7fc3aa4fa20520e009fcaf3 Mon Sep 17 00:00:00 2001
From: Thierry Volpiatto <thievol@posteo.net>
Date: Fri, 15 Dec 2023 06:41:46 +0100
Subject: [PATCH 4/4] Fix register commands in kmacros

When register-use-preview is nil we are exiting minibuffer with no
confirmation after an idle delay.  This cause a problem when executing
kmacros because the commands in macro that should run outside the
minibuffer run inside the minibuffer and BTW have no effect in current
buffer.

By using a preview fn that is not delayed we exit immediately with no
delay and the commands are executed in the good order and in the main
buffer.

* lisp/register.el (register-read-with-preview): Use basic fn while
executing kmacros.
=2D--
 lisp/register.el | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/register.el b/lisp/register.el
index 43dad90778c..15ed5c0a53b 100644
=2D-- a/lisp/register.el
+++ b/lisp/register.el
@@ -429,7 +429,12 @@ Format of each entry is controlled by the variable `re=
gister-preview-function'."
 Prompt with the string PROMPT.
 If `help-char' (or a member of `help-event-list') is pressed,
 display such a window regardless."
=2D  (funcall register--read-with-preview-function prompt))
+  (let ((register--read-with-preview-function
+         (if (and executing-kbd-macro
+                  (memq register-use-preview '(nil never)))
+             #'register-read-with-preview-basic
+           (default-value 'register--read-with-preview-function))))
+    (funcall register--read-with-preview-function prompt)))
=20
 (defun register-read-with-preview-basic (prompt)
   "Read and return a register name, possibly showing existing registers.
=2D-=20
2.34.1


--=-=-=--

--==-=-=
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQHHBAEBCgAxFiEEI9twfRN7r3nig/xwDsVtFB0W75MFAmV8Zp0THHRoaWV2b2xA
cG9zdGVvLm5ldAAKCRAOxW0UHRbvk7URC/4+9yx9HpjB7zqRyr39NdWaebzQmF0z
Mrf4Shly6VFy3SwCW2/8rBtZM7ji1wkWXpb2Hi/8CZTO/Sb1l2b12bp3zOxMkKOk
eNAgDHH59TtC+TFhFHfk2DhH5Cq7U7btAk8UstvbmZOKJmafDLVkBeAVXUuBcFZ2
jTs1BfrZNt1OAFEv3PMOGjzjJ6mcofHQoimMYT0XhVqeieBNgRSrN0jlHG8eo8/C
f/L8Qsx8OT6PqZQlzix1SUU7iaoKWW2Vm579wIKKFhyHMPCh/HD8gdVW+JRkBjCI
TFqWgw05K0NziFWveOIArfAeR50EUqIrb0dOgFRN5y7PqOM7kaiSyogtivEgFZFW
0wgLRJyBSzaBt1qMSp526NfXPw5X8xKe12HSTXNWlNZ2BlCJQbDLSzn/GN0ZrEen
JRLMteaQh+Aekv9G81RIJw/jXwtiP2JG2rnb3DAnkU5QqfhZ2PuZM1HjT94h+fe+
QZ0gSCHDRWh5TrFAMsVOoCz/FiGFZIhFQuk=
=e6FL
-----END PGP SIGNATURE-----
--==-=-=--