Subject: Re: bug#66394: 29.1; Make register-read-with-preview more useful

From: Stefan Monnier <[email-masked]>
Date: Sat, 16 Dec 2023 10:31:50 -0500

> It should be possible to use post-command-hook, I didn't use it because
> it makes harder the communication between the minibuffer and the preview
> buffer.

The patch below seems to work for my extremely limited testing.

        Stefan

diff --git a/lisp/register.el b/lisp/register.el
index fa4bbcf483f..31466a42b0a 100644
--- a/lisp/register.el
+++ b/lisp/register.el
@@ -328,7 +328,7 @@ register-read-with-preview
                 m))
          (data (register-command-info this-command))
          (enable-recursive-minibuffers t)
-         types msg result timer act win strs smatch)
+         types msg result act win strs smatch)
     (if data
         (setq types  (register-preview-info-types data)
               msg    (register-preview-info-msg   data)
@@ -360,9 +360,7 @@ register-read-with-preview
          (progn
            (minibuffer-with-setup-hook
                (lambda ()
-                 (setq timer
-                       (run-with-idle-timer
-                        0.01 'repeat
+                 (add-hook 'post-command-hook
                         (lambda ()
                           (with-selected-window (minibuffer-window)
                             (let ((input (minibuffer-contents)))
@@ -408,13 +406,13 @@ register-read-with-preview
                                   ;; jump, don't ask for confirmation
                                   ;; and exit immediately (bug#66394).
                                   (setq result pat)
-                                  (exit-minibuffer)))))))))
+                                  (exit-minibuffer))))))
+                        nil 'local))
              (setq result (read-from-minibuffer
                            prompt nil map nil nil (register-preview-get-defaults act))))
            (cl-assert (and result (not (string= result "")))
                       nil "No register specified")
            (string-to-char result))
-      (when timer (cancel-timer timer))
       (let ((w (get-buffer-window buf)))
         (and (window-live-p w) (delete-window w)))
       (and (get-buffer buf) (kill-buffer buf)))))