From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#71429: Inconsistent y-or-n-p prompt behavior in Emacs Lisp Date: Sat, 08 Jun 2024 15:59:11 +0200 Message-ID: <87h6e3lemo.fsf@gmx.net> References: <0a72f9c4-3f1c-4fc8-a412-169dca892b57@medialab.sissa.it> <86bk4bet9p.fsf@gnu.org> <87cyoreqpd.fsf@gmx.net> Reply-To: Stephen Berman Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1106"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Gabriele Nicolardi , 71429@debbugs.gnu.org, Stefan Kangas To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 08 16:00:05 2024 Return-path: 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 ) id 1sFwc1-000AYC-JH for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 08 Jun 2024 16:00:05 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFwbn-0005JI-3V; Sat, 08 Jun 2024 09:59:51 -0400 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 ) id 1sFwbi-0005Ie-Lw for bug-gnu-emacs@gnu.org; Sat, 08 Jun 2024 09:59:47 -0400 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 ) id 1sFwbi-0003hl-7f for bug-gnu-emacs@gnu.org; Sat, 08 Jun 2024 09:59:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sFwbx-0006kn-QG for bug-gnu-emacs@gnu.org; Sat, 08 Jun 2024 10:00:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 08 Jun 2024 14:00:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71429 X-GNU-PR-Package: emacs Original-Received: via spool by 71429-submit@debbugs.gnu.org id=B71429.171785518425909 (code B ref 71429); Sat, 08 Jun 2024 14:00:01 +0000 Original-Received: (at 71429) by debbugs.gnu.org; 8 Jun 2024 13:59:44 +0000 Original-Received: from localhost ([127.0.0.1]:39171 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sFwbf-0006jp-Im for submit@debbugs.gnu.org; Sat, 08 Jun 2024 09:59:44 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]:48671) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sFwbb-0006jY-Ri for 71429@debbugs.gnu.org; Sat, 08 Jun 2024 09:59:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1717855154; x=1718459954; i=stephen.berman@gmx.net; bh=jwa4Ca7Q3X18TPpgG2yzsO+XVolnVPZcwv3R41qpcDA=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=C5R9el5dyE5Mqak1OOp/mf5aPUeUt8hide1XRbMXjwrI0KlIS7/Syy0OFWQwsR04 9DUT2S86TDs/45mZZpLUVjD/S0KxX3I0UC3fL6DUt0HMyfuv1oA0oJ4pkaVMJHAl5 YozcicXW9BcZ7gFQr9d/ZwCJCNP4v3Uj6jlkoHKSRqLghniqmuAtxeO1piPNPlDmi 6JDQo59i3OqDU6K0P7iUgD661mZoY0zER/5K/enqqrpB+RT0JTF5M1xqisF7/noJ0 a54yg8NpaZ64HdY+yx73eurQuQMP1bqNMvjlWdS2mfaKZ98klRIWKwUgcEB0vstAY duVMmPmrc58nuAZ5Zg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([94.134.94.137]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MQ5rO-1s2h4E0QrI-00NncL; Sat, 08 Jun 2024 15:59:14 +0200 In-Reply-To: <87cyoreqpd.fsf@gmx.net> (Stephen Berman's message of "Sat, 08 Jun 2024 11:20:14 +0200") X-Provags-ID: V03:K1:o6r7vWTiSLPy+7O0erydNpVmapqngC70/8dcCHabLyIQtT/a4G0 hWQOio+ZbnbBTpEI2Q73W6v0uDI8hETPgV3TiD6J7Nww36bCPT3icl4yVDqzd+06Ji69hP+ 6PunTw+k/gGULJoOyuWoEVx0TpGbH2wrGh2rzh3SzdNumXjXJQ8p2a2J+jo+wwimf3zVDlt 0iFriKJDPMeToLcMYnSZQ== UI-OutboundReport: notjunk:1;M01:P0:d/5RhjO0spA=;dh3tir8u0K215M9fAAxvybeI7/V wSnE/rjzaJoo/Tr1CVDJRqk5tY+UGGq007ejlAnDLqIGePDkNhgk5Q/rUAQlfprygqEf657oF j1CjQRxCKZ2gUNWUIG3ciK74Mnz44dDyR+BBKJ66N6WVOQRrTCU17IIg6LpKSuQkdl2IxFbiz jWn6UemLzj9lNWgf8jUDR1NNmk19JYHVxHRzCxmwrAC6xU88f96CkPgHg9V3yxPSNXAJUIfny sbwPGUb1cGoXceGE1ugIqxYtUMNnq+3OvdJXwiXFr0SWftYd/6ZZyQHvt6+3/70X/XSdBPTft GTt8SlcMdoeE4tuTF+hz9kipsZgIxn5XKJkJpI86u1yKEgcWvZTfrdqyzOOTxy2EfERhb6Xjw 8oiko3GiCD3+KAvnsxBjgkmMWhqZJ1nMb0VeAigNPyYW5MCffmHuVWbzmOHmeBvnzfUr8NwL3 IfH8dcELk0MsBG7SdBQ9jqCRT6DJALGSFCmoV5+9sKl34nidCGbonOfPxryFXDiEWA4urovcA nrNZUhMrX31mYjjad5lWS9WwY9lkuvcFlkPvAFS+FxVrex/SiXYXP6W+IYybLpKWTbHhW9QMP 1I20fabGVni0KT52lZ5NXMSZi4j1g0JzBmMJf6q64prctpGqQ/RoA5tiOAUKh8KUkpp/scFvh 5eq5R15eqH2uQzMGITryUqvNk/D2ziLV9aVi9CbWDKJGyRWqNsywjLcS3DHzHZ5zaANMjNjfB 3ErIuP5YJivhBCL4KMaJcdMiN9XlZHYH/eDtpQkFg5mJD2RBHNbLVkLy38h4yAEwPb3Hr2T3 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" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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:286857 Archived-At: On Sat, 08 Jun 2024 11:20:14 +0200 Stephen Berman = wrote: > On Sat, 08 Jun 2024 11:24:50 +0300 Eli Zaretskii wrote: > >>> Date: Sat, 8 Jun 2024 09:03:37 +0200 >>> From: Gabriele Nicolardi >>>=20 >>> I have the following Emacs Lisp code: >>>=20 >>> (progn >>> (y-or-n-p "Test: ") >>> (let ((search-spaces-regexp "\\(?:\\n?[\s\t]+\\|\n\\)?")) >>> (y-or-n-p "Test: "))) >>>=20 >>> The first prompt from the y-or-n-p function appears as expected: >>>=20 >>> Test: (y or n) >>>=20 >>> However, the second prompt appears differently: >>>=20 >>> Test: (=E2=80=98y=E2=80=99 or =E2=80=98n=E2=80=99) >>>=20 >>> I=E2=80=99m trying to understand why the second prompt format changes. = What causes this inconsistency in the >>> y-or-n-p prompt? >>>=20 >>> I suspect it might be related to the search-spaces-regexp variable or h= ow Emacs handles interactive >>> prompts, but I=E2=80=99m not sure. Any insights or explanations would b= e greatly appreciated! >> >> Stefan, can you please look into this? It sounds like some issue with >> substitute-command-keys: >> >> (substitute-command-keys "(\\`y' or \\`n') ") >> =3D> #("(y or n) " 1 2 (font-lock-face help-key-binding face help-key= -binding) 6 7 (font-lock-face help-key-binding face help-key-binding)) >> >> But >> >> (let ((search-spaces-regexp "\\(?:\\n?[\s\t]+\\|\n\\)?")) >> (substitute-command-keys "(\\`y' or \\`n') ")) >> =3D> "(\\=E2=80=98y=E2=80=99 or \\=E2=80=98n=E2=80=99) " >> >> I actually don't understand why we use \\`y' and \\`n' in y-or-n-p. >> Why those backslashes, and not just `y' and `n'? That's your change >> in commit a36ecc408a. If I remove the backslashes, the results are >> identical whether or not search-spaces-regexp is let-bound. Without the backslashes the cond-clause in substitute-command-keys handling sequences starting with "\" is skipped, so "y" and "n" do not get the help-key-binding face property. > Removing the final '?' in the regexp, i.e. > > (let ((search-spaces-regexp "\\(?:\\n?[\s\t]+\\|\n\\)")) > (y-or-n-p "Test: ")) > > results in the second prompt appearing like the first one. Likewise > with '*', but not with '+': > > (let ((search-spaces-regexp " ?")) > (y-or-n-p "Test: ")) > =3D> Test: (\=E2=80=98y=E2=80=99 or \=E2=80=98n=E2=80=99) > > (let ((search-spaces-regexp " *")) > (y-or-n-p "Test: ")) > =3D> Test: (\=E2=80=98y=E2=80=99 or \=E2=80=98n=E2=80=99) > > (let ((search-spaces-regexp " +")) > (y-or-n-p "Test: ")) > =3D> Test: (y or n) > > (let ((search-spaces-regexp " ")) > (y-or-n-p "Test: ")) > =3D> Test: (y or n) Stepping through substitute-command-keys in Edebug, I see that when the regexp ends in '?' or '*' the sexp (key-valid-p k) in substitute-command-keys returns nil for k set to "y" and then to "n", so these strings do not get the help-key-binding face property and "(\\`y' or \\`n') " is returned to y-or-n-p unaltered. When the regexp does not end in '?' or '*', (key-valid-p k) returns t for "y" and "n" and these strings get propertized. Stepping through key-valid-p, I see that when the regexp ends in '?' or '*' the sexp (split-string keys " ") returns (#1=3D"" "y" #1#) for keys set to "y", and key-valid-p loops over this lists, and the first element "" is an invalid key. When the regexp does not end in '?' or '*' the split-string sexp in key-valid-p returns ("y"), and "y" is valid. And stepping through split-string, I see that when the regexp ends in '?' or '*', the invocation of string-match in the while-loop with args REGEXP set to " ", STRING set to "y" and START set to 0 returns 0, which results in "" being pushed onto the list both before and after "y", hence returning (#1=3D"" "y" #1#). When the regexp does not end in '?' or '*', the string-match invocation returns nil and only "y" is pushed onto the list. Steve Berman