all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
@ 2023-05-09 20:35 Tim Landscheidt
  2023-05-10 10:08 ` Michael Albinus
  2023-05-10 13:48 ` Eli Zaretskii
  0 siblings, 2 replies; 14+ messages in thread
From: Tim Landscheidt @ 2023-05-09 20:35 UTC (permalink / raw)
  To: 63399

The documentation for yes-or-no-p in Emacs 28.2 reads:

| yes-or-no-p is a built-in function in ‘C source code’.

| (yes-or-no-p PROMPT)

| Ask user a yes-or-no question.
| Return t if answer is yes, and nil if the answer is no.

| PROMPT is the string to display to ask the question; ‘yes-or-no-p’
| adds "(yes or no) " to it.  It does not need to end in space, but if
| it does up to one space will be removed.

| […]

This is wrong: (yes-or-no-p "Prompt? ") gives the prompt
"Prompt? (yes or no) ", but according to the docstring it
should be "Prompt?(yes or no) ".

With the big caveat that I have never looked deeper at
Emacs's C code, the source in src/fns.c does not appear to
change the prompt given as an argument in any way, but just
append yes-or-no-prompt to it.

Also, (elisp) Yes-or-No Queries reads (since 7f53446a10ea;
doc/lispref/minibuf.texi):

| […]

|      Here is an example:

|           (yes-or-no-p "Do you really want to remove everything?")

|           ;; After evaluation of the preceding expression,
|           ;;   the following prompt appears,
|           ;;   with an empty minibuffer:

|           ---------- Buffer: minibuffer ----------
|           Do you really want to remove everything? (yes or no)
|           ---------- Buffer: minibuffer ----------

| […]

This is not the actual result: (yes-or-no-p "Do you really
want to remove everything?") gives the prompt "Do you really
want to remove everything?(yes or no) ", i. e., the space
before the parenthesis is missing.

Finally, the behaviour is different when using
use-short-answers:

| (yes-or-no-p "Prompt?")

gives "Prompt?(yes or no) ", while:

| (let ((use-short-answers t)) (yes-or-no-p "Prompt?"))

gives "Prompt? (y or n) ".





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-09 20:35 bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref Tim Landscheidt
@ 2023-05-10 10:08 ` Michael Albinus
  2023-05-10 14:05   ` Eli Zaretskii
  2023-05-10 13:48 ` Eli Zaretskii
  1 sibling, 1 reply; 14+ messages in thread
From: Michael Albinus @ 2023-05-10 10:08 UTC (permalink / raw)
  To: Tim Landscheidt; +Cc: 63399

[-- Attachment #1: Type: text/plain, Size: 1304 bytes --]

Tim Landscheidt <tim@tim-landscheidt.de> writes:

Hi,

> With the big caveat that I have never looked deeper at
> Emacs's C code, the source in src/fns.c does not appear to
> change the prompt given as an argument in any way, but just
> append yes-or-no-prompt to it.
>
> Also, (elisp) Yes-or-No Queries reads (since 7f53446a10ea;
> doc/lispref/minibuf.texi):
>
> | […]
>
> |      Here is an example:
>
> |           (yes-or-no-p "Do you really want to remove everything?")
>
> |           ;; After evaluation of the preceding expression,
> |           ;;   the following prompt appears,
> |           ;;   with an empty minibuffer:
>
> |           ---------- Buffer: minibuffer ----------
> |           Do you really want to remove everything? (yes or no)
> |           ---------- Buffer: minibuffer ----------
>
> | […]
>
> This is not the actual result: (yes-or-no-p "Do you really
> want to remove everything?") gives the prompt "Do you really
> want to remove everything?(yes or no) ", i. e., the space
> before the parenthesis is missing.

I guess we should pad the prompt with a trailing space, if there isn't
any already. As we do in `y-or-no-p'. What about the appended patch?
Documentation must be updated as well, of course.

Best regards, Michael.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 768 bytes --]

diff --git a/src/fns.c b/src/fns.c
index bb6efdda655..b081cb225e1 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -26,6 +26,7 @@ Copyright (C) 1985-2023 Free Software Foundation, Inc.
 #include <intprops.h>
 #include <vla.h>
 #include <errno.h>
+#include <ctype.h>

 #include "lisp.h"
 #include "bignum.h"
@@ -3234,6 +3235,12 @@ DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0,
   if (use_short_answers)
     return call1 (intern ("y-or-n-p"), prompt);

+  {
+    char *s = SSDATA (prompt);
+    ptrdiff_t len = strlen (s);
+    if (!(len == 0) && !(isspace (s[len - 1])))
+      prompt = CALLN (Fconcat, prompt, make_string (" ", 1));
+  }
   prompt = CALLN (Fconcat, prompt, Vyes_or_no_prompt);

   specpdl_ref count = SPECPDL_INDEX ();

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-09 20:35 bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref Tim Landscheidt
  2023-05-10 10:08 ` Michael Albinus
@ 2023-05-10 13:48 ` Eli Zaretskii
  2023-05-10 14:05   ` Michael Albinus
  1 sibling, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-10 13:48 UTC (permalink / raw)
  To: Tim Landscheidt; +Cc: 63399

> From: Tim Landscheidt <tim@tim-landscheidt.de>
> Date: Tue, 09 May 2023 20:35:20 +0000
> 
> The documentation for yes-or-no-p in Emacs 28.2 reads:
> 
> | yes-or-no-p is a built-in function in ‘C source code’.
> 
> | (yes-or-no-p PROMPT)
> 
> | Ask user a yes-or-no question.
> | Return t if answer is yes, and nil if the answer is no.
> 
> | PROMPT is the string to display to ask the question; ‘yes-or-no-p’
> | adds "(yes or no) " to it.  It does not need to end in space, but if
> | it does up to one space will be removed.
> 
> | […]
> 
> This is wrong: (yes-or-no-p "Prompt? ") gives the prompt
> "Prompt? (yes or no) ", but according to the docstring it
> should be "Prompt?(yes or no) ".

The doc string in Emacs 29 no longer includes the above confusing and
inaccurate text about removing the space.  So I think this
documentation bug was already fixed.

> Also, (elisp) Yes-or-No Queries reads (since 7f53446a10ea;
> doc/lispref/minibuf.texi):
> 
> | […]
> 
> |      Here is an example:
> 
> |           (yes-or-no-p "Do you really want to remove everything?")
> 
> |           ;; After evaluation of the preceding expression,
> |           ;;   the following prompt appears,
> |           ;;   with an empty minibuffer:
> 
> |           ---------- Buffer: minibuffer ----------
> |           Do you really want to remove everything? (yes or no)
> |           ---------- Buffer: minibuffer ----------
> 
> | […]
> 
> This is not the actual result: (yes-or-no-p "Do you really
> want to remove everything?") gives the prompt "Do you really
> want to remove everything?(yes or no) ", i. e., the space
> before the parenthesis is missing.

I've now fixed the example to be consistent with the result.

> Finally, the behaviour is different when using
> use-short-answers:
> 
> | (yes-or-no-p "Prompt?")
> 
> gives "Prompt?(yes or no) ", while:
> 
> | (let ((use-short-answers t)) (yes-or-no-p "Prompt?"))
> 
> gives "Prompt? (y or n) ".

You are supposed to include the trailing blank if you want to ensure
there's a blank between the prompt and the "(y or n)" part.

I think we should close this bug now.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 10:08 ` Michael Albinus
@ 2023-05-10 14:05   ` Eli Zaretskii
  2023-05-10 14:07     ` Michael Albinus
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-10 14:05 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 63399, tim

> Cc: 63399@debbugs.gnu.org
> From: Michael Albinus <michael.albinus@gmx.de>
> Date: Wed, 10 May 2023 12:08:24 +0200
> 
> I guess we should pad the prompt with a trailing space, if there isn't
> any already.

No, I don't think we should.  The caller should take care of any
padding, if that is desired.  The function shouldn't second-guess
whether a space is needed or not.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 13:48 ` Eli Zaretskii
@ 2023-05-10 14:05   ` Michael Albinus
  0 siblings, 0 replies; 14+ messages in thread
From: Michael Albinus @ 2023-05-10 14:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 63399, Tim Landscheidt

Eli Zaretskii <eliz@gnu.org> writes:

Hi Eli,

> You are supposed to include the trailing blank if you want to ensure
> there's a blank between the prompt and the "(y or n)" part.

In y-or-n-p, we add a trailing space if it doesn't exist. So I assume we
could do it in yes-or-no-p as well. See my other message, where I have
proposed a patch.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 14:05   ` Eli Zaretskii
@ 2023-05-10 14:07     ` Michael Albinus
  2023-05-10 14:42       ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Michael Albinus @ 2023-05-10 14:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 63399, tim

Eli Zaretskii <eliz@gnu.org> writes:

>> I guess we should pad the prompt with a trailing space, if there isn't
>> any already.
>
> No, I don't think we should.  The caller should take care of any
> padding, if that is desired.  The function shouldn't second-guess
> whether a space is needed or not.

Why the difference to y-or-no-p?

Best regards, Michael.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 14:07     ` Michael Albinus
@ 2023-05-10 14:42       ` Eli Zaretskii
  2023-05-10 14:57         ` Michael Albinus
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-10 14:42 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 63399, tim

> From: Michael Albinus <michael.albinus@gmx.de>
> Cc: tim@tim-landscheidt.de,  63399@debbugs.gnu.org
> Date: Wed, 10 May 2023 16:07:45 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> I guess we should pad the prompt with a trailing space, if there isn't
> >> any already.
> >
> > No, I don't think we should.  The caller should take care of any
> > padding, if that is desired.  The function shouldn't second-guess
> > whether a space is needed or not.
> 
> Why the difference to y-or-no-p?

I don't know.

But there's no difference if the prompt ends in a space.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 14:42       ` Eli Zaretskii
@ 2023-05-10 14:57         ` Michael Albinus
  2023-05-10 15:44           ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Michael Albinus @ 2023-05-10 14:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 63399, tim

Eli Zaretskii <eliz@gnu.org> writes:

>> >> I guess we should pad the prompt with a trailing space, if there isn't
>> >> any already.
>> >
>> > No, I don't think we should.  The caller should take care of any
>> > padding, if that is desired.  The function shouldn't second-guess
>> > whether a space is needed or not.
>>
>> Why the difference to y-or-no-p?
>
> I don't know.
>
> But there's no difference if the prompt ends in a space.

Yes. It is just a convenience change, and there's code in the wild which
doesn't use a trailing space in the propmpt, when calling
yes-or-no-p. What would be wrong with my patch? I don't see that it
hurts.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 14:57         ` Michael Albinus
@ 2023-05-10 15:44           ` Eli Zaretskii
  2023-05-10 16:04             ` Tim Landscheidt
                               ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-10 15:44 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 63399, tim

> From: Michael Albinus <michael.albinus@gmx.de>
> Cc: tim@tim-landscheidt.de,  63399@debbugs.gnu.org
> Date: Wed, 10 May 2023 16:57:17 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > But there's no difference if the prompt ends in a space.
> 
> Yes. It is just a convenience change, and there's code in the wild which
> doesn't use a trailing space in the propmpt, when calling
> yes-or-no-p. What would be wrong with my patch? I don't see that it
> hurts.

I'm sure something will come up.  It isn't an accident that we have
danced around this more than once in the past.

But if you insist, please install on master, and let's see whose gray
hair is more right...





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 15:44           ` Eli Zaretskii
@ 2023-05-10 16:04             ` Tim Landscheidt
  2023-05-10 16:44               ` Eli Zaretskii
  2023-05-10 16:55             ` Michael Albinus
  2023-05-12 10:49             ` Michael Albinus
  2 siblings, 1 reply; 14+ messages in thread
From: Tim Landscheidt @ 2023-05-10 16:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Michael Albinus, 63399

Eli Zaretskii <eliz@gnu.org> wrote:

>> > But there's no difference if the prompt ends in a space.

>> Yes. It is just a convenience change, and there's code in the wild which
>> doesn't use a trailing space in the propmpt, when calling
>> yes-or-no-p. What would be wrong with my patch? I don't see that it
>> hurts.

> I'm sure something will come up.  It isn't an accident that we have
> danced around this more than once in the past.

> But if you insist, please install on master, and let's see whose gray
> hair is more right...

I support Michael's idea here.  I do not remember any case
where a prompt "Prompt?(yes or no) " was an intentional
choice by the author.  It looks "wrong".  (The GNU Coding
Standards recommend spaces before open-parentheses in C
code, but strictly speaking this does not relate to the UI.)





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 16:04             ` Tim Landscheidt
@ 2023-05-10 16:44               ` Eli Zaretskii
  2023-05-10 16:57                 ` Michael Albinus
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-05-10 16:44 UTC (permalink / raw)
  To: Tim Landscheidt; +Cc: michael.albinus, 63399

> From: Tim Landscheidt <tim@tim-landscheidt.de>
> Cc: Michael Albinus <michael.albinus@gmx.de>,  63399@debbugs.gnu.org
> Date: Wed, 10 May 2023 16:04:47 +0000
> 
> Eli Zaretskii <eliz@gnu.org> wrote:
> 
> >> > But there's no difference if the prompt ends in a space.
> 
> >> Yes. It is just a convenience change, and there's code in the wild which
> >> doesn't use a trailing space in the propmpt, when calling
> >> yes-or-no-p. What would be wrong with my patch? I don't see that it
> >> hurts.
> 
> > I'm sure something will come up.  It isn't an accident that we have
> > danced around this more than once in the past.
> 
> > But if you insist, please install on master, and let's see whose gray
> > hair is more right...
> 
> I support Michael's idea here.

Of course you do.  And I won't argue, I will just say that you don't
have enough gray hair in Emacs development.  Time and again I see us
willing to fix some minuscule issue, and as result introduce subtle
problems and regressions which are frequently worse than the original
issue.  I suspect this is one of those cases.  But I'm willing to
consider the possibility that perhaps this time I will be wrong (yeah,
right).





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 15:44           ` Eli Zaretskii
  2023-05-10 16:04             ` Tim Landscheidt
@ 2023-05-10 16:55             ` Michael Albinus
  2023-05-12 10:49             ` Michael Albinus
  2 siblings, 0 replies; 14+ messages in thread
From: Michael Albinus @ 2023-05-10 16:55 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 63399, tim

Eli Zaretskii <eliz@gnu.org> writes:

Hi Eli,

>> Yes. It is just a convenience change, and there's code in the wild which
>> doesn't use a trailing space in the propmpt, when calling
>> yes-or-no-p. What would be wrong with my patch? I don't see that it
>> hurts.
>
> I'm sure something will come up.  It isn't an accident that we have
> danced around this more than once in the past.
>
> But if you insist, please install on master,

Will do. It might take one day or two. Tomorrow, I have a
Grand-daughter-care day. Perhaps also on Friday. Obviously, with changed
preferences :-)

> and let's see whose gray hair is more right...

Usually your hair, I know. Let's see.

OTOH, don't trust my Gravatar image. It is 15+ years old. If you want to
check my gray hair in reality, you might join the next Berlin Emacs
meetup :-)

<https://emacs-berlin.org/>

Best regards, Michael.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 16:44               ` Eli Zaretskii
@ 2023-05-10 16:57                 ` Michael Albinus
  0 siblings, 0 replies; 14+ messages in thread
From: Michael Albinus @ 2023-05-10 16:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 63399, Tim Landscheidt

Eli Zaretskii <eliz@gnu.org> writes:

Hi Eli,

> Of course you do.  And I won't argue, I will just say that you don't
> have enough gray hair in Emacs development.  Time and again I see us
> willing to fix some minuscule issue, and as result introduce subtle
> problems and regressions which are frequently worse than the original
> issue.  I suspect this is one of those cases.  But I'm willing to
> consider the possibility that perhaps this time I will be wrong (yeah,
> right).

Obviously, you should forward all reports about this change to me. I'm
prepared ...

Best regards, Michael.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref
  2023-05-10 15:44           ` Eli Zaretskii
  2023-05-10 16:04             ` Tim Landscheidt
  2023-05-10 16:55             ` Michael Albinus
@ 2023-05-12 10:49             ` Michael Albinus
  2 siblings, 0 replies; 14+ messages in thread
From: Michael Albinus @ 2023-05-12 10:49 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 63399-done, tim

Version: 30.1

Eli Zaretskii <eliz@gnu.org> writes:

Hi Eli,

>> > But there's no difference if the prompt ends in a space.
>>
>> Yes. It is just a convenience change, and there's code in the wild which
>> doesn't use a trailing space in the propmpt, when calling
>> yes-or-no-p. What would be wrong with my patch? I don't see that it
>> hurts.
>
> I'm sure something will come up.  It isn't an accident that we have
> danced around this more than once in the past.
>
> But if you insist, please install on master, and let's see whose gray
> hair is more right...

I've pushed this to master. In NEWS.28, we have

--8<---------------cut here---------------start------------->8---
** 'yes-or-no-p' and 'y-or-n-p' PROMPT parameter no longer needs trailing space.
In other words, the prompt can now end with "?" instead of "? ".  This
has been the case since Emacs 24.4 but was not announced or documented
until now.  (Checkdoc has also been updated to accept this convention.)
--8<---------------cut here---------------end--------------->8---

So this is the intended bahavior, and the patch is just a bug fix.

Closing this report.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-05-12 10:49 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-09 20:35 bug#63399: 28.2; Documentation for yes-or-no-p wrong/different between docstring and lispref Tim Landscheidt
2023-05-10 10:08 ` Michael Albinus
2023-05-10 14:05   ` Eli Zaretskii
2023-05-10 14:07     ` Michael Albinus
2023-05-10 14:42       ` Eli Zaretskii
2023-05-10 14:57         ` Michael Albinus
2023-05-10 15:44           ` Eli Zaretskii
2023-05-10 16:04             ` Tim Landscheidt
2023-05-10 16:44               ` Eli Zaretskii
2023-05-10 16:57                 ` Michael Albinus
2023-05-10 16:55             ` Michael Albinus
2023-05-12 10:49             ` Michael Albinus
2023-05-10 13:48 ` Eli Zaretskii
2023-05-10 14:05   ` Michael Albinus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.