From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Stefan Monnier via "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
Newsgroups: gmane.emacs.bugs
Subject: bug#66394: 29.1; Make register-read-with-preview more useful
Date: Sat, 16 Dec 2023 10:31:50 -0500
Message-ID: <jwvzfya2mk9.fsf-monnier+emacs@gnu.org>
References: <87il7ib6cu.fsf@posteo.net> <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>
 <87r0jn4j8i.fsf@posteo.net> <jwv8r5vfqo6.fsf-monnier+emacs@gnu.org>
 <87jzpf48k5.fsf@posteo.net> <jwvplz73vpg.fsf-monnier+emacs@gnu.org>
 <87plz6xp3m.fsf@posteo.net>
Reply-To: Stefan Monnier <monnier@iro.umontreal.ca>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="32698"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cc: michael_heerdegen@web.de, dmitry@gutov.dev, Eli Zaretskii <eliz@gnu.org>,
 Stefan Kangas <stefankangas@gmail.com>, 66394@debbugs.gnu.org
To: Thierry Volpiatto <thievol@posteo.net>
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 16 16:33:21 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 1rEWfJ-0008Fo-6p
	for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Dec 2023 16:33:21 +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 1rEWf1-00053T-Id; Sat, 16 Dec 2023 10:33:03 -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 1rEWf0-00052W-7u
 for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 10:33:02 -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 1rEWez-00034G-V5
 for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 10:33:01 -0500
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1rEWf0-0006g1-8I
 for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 10:33:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Stefan Monnier <monnier@iro.umontreal.ca>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Sat, 16 Dec 2023 15:33:02 +0000
Resent-Message-ID: <handler.66394.B66394.170274072225576@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.170274072225576
 (code B ref 66394); Sat, 16 Dec 2023 15:33:02 +0000
Original-Received: (at 66394) by debbugs.gnu.org; 16 Dec 2023 15:32:02 +0000
Original-Received: from localhost ([127.0.0.1]:55768 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1rEWe1-0006eK-Gr
 for submit@debbugs.gnu.org; Sat, 16 Dec 2023 10:32:01 -0500
Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:50317)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@iro.umontreal.ca>) id 1rEWdz-0006e0-DB
 for 66394@debbugs.gnu.org; Sat, 16 Dec 2023 10:31:59 -0500
Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 5BA7D100068;
 Sat, 16 Dec 2023 10:31:53 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1702740712;
 bh=QIo3v3xmquZK4tkni4Ajh/xZYdE7Pje2yIftY27lhIg=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=XeeR1j2s//SMxGZDr76MZyMbX1u9G2CEZWj5jXxIHoZZucNt+lySWFSi4AuWdMgr6
 X9jQ9a4LKinilHntQiZwo72WvIhTtgweER8fGtI/rgiaINwicP1Ec76vpLLyLbAyjQ
 fyXBWEIVX+/b1fIn9aq7umGAuA040MvRoBli788TZElrEkq9dAsj+mF2vJyVAGgPWr
 fgjC/1DZzkKgVbv/4AFUiL/hz87KkBnSC/u/c9qkSSqce4dRCpbDiTlZLgR22OhkET
 zX/y0EfhC1kPyJUZLD0HnnpuNhuZQpiTul9t7UWRbevDabvmWo4OcLOZ6I73/11CQu
 g/dUfG07it/Cg==
Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 637E6100033;
 Sat, 16 Dec 2023 10:31:52 -0500 (EST)
Original-Received: from pastel (65-110-221-238.cpe.pppoe.ca [65.110.221.238])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 277EB120E7F;
 Sat, 16 Dec 2023 10:31:52 -0500 (EST)
In-Reply-To: <87plz6xp3m.fsf@posteo.net> (Thierry Volpiatto's message of "Sat, 
 16 Dec 2023 13:18:37 +0000")
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:276358
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/276358>

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