Subject: Re: bug#67702: 30.0.50; insert-register can no longer be used in minibuffer

From: Thierry Volpiatto <[email-masked]>
Date: Fri, 08 Dec 2023 12:40:18 +0000

Here the patches, sorry.

-- 
Thierry
From ff8f43a39e2cee1f71629194d44c7459f2b90d79 Mon Sep 17 00:00:00 2001
From: Thierry Volpiatto <[email-masked]>
Date: Sun, 3 Dec 2023 15:21:50 +0100
Subject: [PATCH 1/3] Exit with no confirmation (RET) when register-use-preview

is non nil and .

This is done by exiting minibuffer when selected register is empty or
when just jumping or inserting.

* lisp/register.el (register-read-with-preview): Do it.
---
 lisp/register.el | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lisp/register.el b/lisp/register.el
index 46ec38821e5..a38b531dfc9 100644
--- a/lisp/register.el
+++ b/lisp/register.el
@@ -385,12 +385,16 @@ display such a window regardless."
                                         (minibuffer-message
                                          "Register `%s' is empty" pat))))))
                             (unless (string= pat "")
-                              (if (member pat strs)
-                                  (with-selected-window (minibuffer-window)
-                                    (minibuffer-message msg pat))
-                                (with-selected-window (minibuffer-window)
-                                  (minibuffer-message
-                                   "Register `%s' is empty" pat)))))))))
+                              (with-selected-window (minibuffer-window)
+                                (if (and (member pat strs) (memq act '(set modify)))
+                                    (with-selected-window (minibuffer-window)
+                                      (minibuffer-message msg pat))
+                                  ;; An empty register or an existing
+                                  ;; one but the action is insert or
+                                  ;; jump, don't ask for confirmation
+                                  ;; and exit immediately (bug#66394).
+                                  (setq result pat)
+                                  (exit-minibuffer)))))))))
              (setq result (read-from-minibuffer
                            prompt nil map nil nil (register-preview-get-defaults act))))
            (cl-assert (and result (not (string= result "")))
-- 
2.34.1

From 09c00dd82d377972bb9cc8b789156993f27c1026 Mon Sep 17 00:00:00 2001
From: Thierry Volpiatto <[email-masked]>
Date: Fri, 8 Dec 2023 08:09:38 +0100
Subject: [PATCH 2/3] Allow inserting registers in minibuffer (bug#67702)

* lisp/register.el (register-read-with-preview): Bind
`enable-recursive-minibuffers`.
---
 lisp/register.el | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lisp/register.el b/lisp/register.el
index a38b531dfc9..ba00f296af9 100644
--- a/lisp/register.el
+++ b/lisp/register.el
@@ -315,6 +315,7 @@ display such a window regardless."
                 (set-keymap-parent m minibuffer-local-map)
                 m))
          (data (register-command-info this-command))
+         (enable-recursive-minibuffers t)
          types msg result timer act win strs smatch)
     (if data
         (setq types  (register-preview-info-types data)
-- 
2.34.1

From 633fa5245072a746d122eb6eba11751033749afc Mon Sep 17 00:00:00 2001
From: Thierry Volpiatto <[email-masked]>
Date: Fri, 8 Dec 2023 11:34:08 +0100
Subject: [PATCH 3/3] Add more options to register-use-preview

This allow showing a basic preview buffer or no preview buffer at all.

* lisp/register.el (register-use-preview): Use choice with three
  options.
(register-read-with-preview): Use a basic buffer without navigation,
  highlighting etc... when register-use-preview is nil, and no buffer
  at all when set to 'never.
---
 lisp/register.el | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/lisp/register.el b/lisp/register.el
index ba00f296af9..ade65b5bdc2 100644
--- a/lisp/register.el
+++ b/lisp/register.el
@@ -107,8 +107,17 @@ If nil, do not show register previews, unless `help-char' (or a member of
   :type '(repeat string))
 
 (defcustom register-use-preview t
-  "Always show register preview when non nil."
-  :type 'boolean)
+  "Maybe show register preview.
+
+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 \\='never behave as above but with no preview buffer at
+all."
+  :type '(choice
+          (const :tag "Use preview" t)
+          (const :tag "Use quick preview" nil)
+          (const :tag "Never use preview" never)))
 
 (defun get-register (register)
   "Return contents of Emacs register named REGISTER, or nil if none."
@@ -310,6 +319,8 @@ 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*")
+         (buf (if register-use-preview buffer buffer1))
          (pat "")
          (map (let ((m (make-sparse-keymap)))
                 (set-keymap-parent m minibuffer-local-map)
@@ -334,15 +345,16 @@ display such a window regardless."
       (define-key map
           (vector k) (lambda ()
                        (interactive)
-                       (unless (get-buffer-window buffer)
+                       ;; Do nothing when buffer1 is in use.
+                       (unless (get-buffer-window buf)
                          (with-selected-window (minibuffer-selected-window)
                            (register-preview 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 (null register-use-preview))
-      (register-preview buffer nil types))
+    (unless (or executing-kbd-macro (eq register-use-preview 'never))
+      (register-preview buf nil types))
     (unwind-protect
          (progn
            (minibuffer-with-setup-hook
@@ -402,9 +414,9 @@ display such a window regardless."
                       nil "No register specified")
            (string-to-char result))
       (when timer (cancel-timer timer))
-      (let ((w (get-buffer-window buffer)))
+      (let ((w (get-buffer-window buf)))
         (and (window-live-p w) (delete-window w)))
-      (and (get-buffer buffer) (kill-buffer buffer)))))
+      (and (get-buffer buf) (kill-buffer buf)))))
 
 (defun point-to-register (register &optional arg)
   "Store current location of point in REGISTER.
-- 
2.34.1