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 18:36:26 +0000
Message-ID: <87jzpf48k5.fsf@posteo.net>
References: <87il7ib6cu.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>
 <87r0jn4j8i.fsf@posteo.net> <jwv8r5vfqo6.fsf-monnier+emacs@gnu.org>
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="37835"; mail-complaints-to="usenet@ciao.gmane.io"
Cc: michael_heerdegen@web.de, dmitry@gutov.dev, Eli Zaretskii <eliz@gnu.org>,
 Stefan Kangas <stefankangas@gmail.com>, 66394@debbugs.gnu.org
To: Stefan Monnier <monnier@iro.umontreal.ca>
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 15 19:37:24 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 1rED3s-0009Wk-5o
	for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Dec 2023 19:37:24 +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 1rED3Z-00009P-5z; Fri, 15 Dec 2023 13:37:05 -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 1rED3W-00008x-Jv
 for bug-gnu-emacs@gnu.org; Fri, 15 Dec 2023 13:37: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 1rED3W-0007xm-C1
 for bug-gnu-emacs@gnu.org; Fri, 15 Dec 2023 13:37:02 -0500
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1rED3W-0006tw-CT
 for bug-gnu-emacs@gnu.org; Fri, 15 Dec 2023 13:37: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 18:37:02 +0000
Resent-Message-ID: <handler.66394.B66394.170266540326502@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.170266540326502
 (code B ref 66394); Fri, 15 Dec 2023 18:37:02 +0000
Original-Received: (at 66394) by debbugs.gnu.org; 15 Dec 2023 18:36:43 +0000
Original-Received: from localhost ([127.0.0.1]:53447 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1rED3D-0006tM-8Q
 for submit@debbugs.gnu.org; Fri, 15 Dec 2023 13:36:43 -0500
Original-Received: from mout02.posteo.de ([185.67.36.66]:56737)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <thievol@posteo.net>) id 1rED3A-0006t3-CP
 for 66394@debbugs.gnu.org; Fri, 15 Dec 2023 13:36:41 -0500
Original-Received: from submission (posteo.de [185.67.36.169]) 
 by mout02.posteo.de (Postfix) with ESMTPS id 52035240101
 for <66394@debbugs.gnu.org>; Fri, 15 Dec 2023 19:36:34 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1702665394; bh=ts4eFEXqVSHeqVe9s/DBynm1JQjpXhQchYXTXTsasns=;
 h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Autocrypt:OpenPGP:
 From;
 b=jHiA18iG29NvDhhbxDV5oBHiO10ZgFLtxeBXMgU5Wqw8evVn3DHWPQVc/RBB7Khhp
 hIEZn96qeTBPRvSwaU1v6W+JUiUEtUA1zdqUOPmJK5wAk6BSYzrwoinrSTDvbOsiK2
 5Ebkvk7hRlD98s0CsDrGVtBYKY+b7c4Ug5VDZDjgxQ5lralFGybl3xRd9xcNOYqf89
 DRcvbuIwlZwMtaRe7QfB+mHBmrkiwoZpSUTPaMUZGwhm+6kqdzP7MonHS8d3FfXzdh
 n++Kw3tfA5tubwiivfAK/ieo8bu2J+4xR+ukwlInZLpztYjE+UBYQ+3BEY/BTMp/wM
 pymhzA8YMOnbg==
Original-Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4SsHxB3cTfz6twR;
 Fri, 15 Dec 2023 19:36:30 +0100 (CET)
In-Reply-To: <jwv8r5vfqo6.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message
 of "Fri, 15 Dec 2023 10:18:05 -0500 (2 hours, 59 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:276280
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/276280>

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

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> @@ -429,7 +429,12 @@ Format of each entry is controlled by the variable =
`register-preview-function'."
>>  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))
>> +  (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)))
>
> Questions/comments:
>
> - Why did you change from using
>   `register--read-with-preview-function` to using
>   (default-value 'register--read-with-preview-function) ?
>   [ The answer should presumably be in the commit message but
>     I couldn't find it there.  ]
>
> - Why let-bind `register--read-with-preview-function`
>   rather than using a local lexical var?
>   [ The answer should probably be in a comment in the code.  ]

To answer to your 1) and 2) questions, I guess what you
suggest is something like this (indeed better):

    diff --git a/lisp/register.el b/lisp/register.el
    index 15ed5c0a53b..2444f88794e 100644
    --- a/lisp/register.el
    +++ b/lisp/register.el
    @@ -429,12 +429,11 @@ Format of each entry is controlled by the variabl=
e `register-preview-function'."
     Prompt with the string PROMPT.
     If `help-char' (or a member of `help-event-list') is pressed,
     display such a window regardless."
    -  (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)))
    +  (let ((fn (if (and executing-kbd-macro
    +                     (memq register-use-preview '(nil never)))
    +                #'register-read-with-preview-basic
    +              register--read-with-preview-function)))
    +    (funcall fn prompt)))
=20=20=20=20=20
     (defun register-read-with-preview-basic (prompt)
       "Read and return a register name, possibly showing existing register=
s.

> - Making the behavior dependent on `executing-kbd-macro` is generally
>   undesirable, so it should be accompanied with a comment in the code
>   explaining why we need it (with enough detail that someone
>   sufficiently motivated could potentially "fix" the code to remove this
>   dependency, or alternatively to convince that someone else that this
>   dependency is actually desirable here).

The explanation is in the commit message. To resume, when we are not
using RET to exit minibuffer, we use `exit-minibuffer` from the timer
function in minibuffer-setup-hook, BTW when you have a macro using
e.g. "C-x r i, C-n, C-a, C-x r +", "C-n and C-a" are running
immediately BEFORE the minibuffer is exited so they run in minibuffer
and have no effect in your macro that run in current-buffer.
Is such a comment sufficiently explicit? (will add in next patch if so).

If you have a better fix for this I take ;-).

The problem with such a fix (as I did) is that we can't have an hybrid
version of preview i.e. one that use RET to confirm overwrite and no RET
for other things.
For example if one add a configuration like below to modify behavior
with *-use-preview =3D=3D nil the macro will fail to execute properly.=20

(cl-defmethod register-command-info ((_command (eql increment-register)))
  (make-register-preview-info
   :types '(all)
   :msg "Increment to register `%s'"
   :act 'set
   :noconfirm nil))


Thanks Stefan for reviewing this.

=2D-=20
Thierry

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

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

iQHHBAEBCgAxFiEEI9twfRN7r3nig/xwDsVtFB0W75MFAmV8nKsTHHRoaWV2b2xA
cG9zdGVvLm5ldAAKCRAOxW0UHRbvk2x7DACgtpj7xvjf0erQY4WC8pkFutcy1rts
PVSaWs8n81pqlMWU3NP/LocjGdzt5/Iu2/l8s5KHmHZC/CCRv7/RIGZikCHWDIyR
ohdV4vk1eBfVqdnnS1HuwkCi3CJPhHo+xwG7GqXwJxmKzC2b010JhSpP53hoVxcS
WqMQxJcTETdd/pUGziuvPGj8BhZcNI94oX3mpjphjk4YcBQHCzCkaVVJsxkn3QZ5
KVQfgNHXwWZPS26BGCaAwY51RATqinhDKFTej1dwpsg31kaocqK6jgW0QCvfIC7U
byBucn3yhmlsBbWCsKtN5Ke0OliPUphGarClubH6XKJst9YxXzMllS9EkEmQfIcE
tvlRl2NCojr7y+a17Q3hFeS1A4w1HtFPt5SJF77R3bwT1QnkxoJ7QCKjtd3twmt5
QDSbQA+L4DutBg2rJ8TIq07B34k42ct+5OSlutbxT+UEN7ACGzBD53sPDQM67T/d
ZzxleVPtSTwS3oZwA3Fu5EGhFjcQz29K7Kc=
=Q3Gq
-----END PGP SIGNATURE-----
--=-=-=--