Add trailing space to PROMPT in yes-or-no-p

* doc/lispref/minibuf.texi (Yes-or-No Queries): Describe PROMPT
massage for y-or-n-p and yes-or-no-p.

* lisp/subr.el (y-or-n-p): Adapt docstring.

* src/fns.c (Fyes_or_no_p): Add trailing space to PROMPT if
needed.  (Bug#63399)
This commit is contained in:
Michael Albinus 2023-05-12 12:45:32 +02:00
parent c9cf673d50
commit cbb59267c7
3 changed files with 19 additions and 2 deletions

View file

@ -2200,6 +2200,9 @@ the expected answers (@kbd{y}, @kbd{n}, @kbd{@key{SPC}},
@kbd{@key{DEL}}, or something that quits), the function responds
@samp{Please answer y or n.}, and repeats the request.
If @var{prompt} is a non-empty string, and it ends with a non-space
character, a @samp{SPC} character will be appended to it.
This function actually uses the minibuffer, but does not allow editing
of the answer. The cursor moves to the minibuffer while the question
is being asked.
@ -2240,6 +2243,9 @@ minibuffer, followed by the value of @code{yes-or-no-prompt} @w{(default
responses; otherwise, the function responds @w{@samp{Please answer yes or
no.}}, waits about two seconds and repeats the request.
If @var{prompt} is a non-empty string, and it ends with a non-space
character, a @samp{SPC} character will be appended to it.
@code{yes-or-no-p} requires more work from the user than
@code{y-or-n-p} and is appropriate for more crucial decisions.

View file

@ -3590,7 +3590,9 @@ confusing to some users.")
Return t if answer is \"y\" and nil if it is \"n\".
PROMPT is the string to display to ask the question; `y-or-n-p'
adds \"(y or n) \" to it.
adds \"(y or n) \" to it. If PROMPT is a non-empty string, and
it ends with a non-space character, a space character will be
appended to it.
If you bind the variable `help-form' to a non-nil value
while calling this function, then pressing `help-char'

View file

@ -26,6 +26,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include <intprops.h>
#include <vla.h>
#include <errno.h>
#include <ctype.h>
#include "lisp.h"
#include "bignum.h"
@ -3202,7 +3203,9 @@ DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0,
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'
appends `yes-or-no-prompt' (default \"(yes or no) \") to it.
appends `yes-or-no-prompt' (default \"(yes or no) \") to it. If
PROMPT is a non-empty string, and it ends with a non-space character,
a space character will be appended to it.
The user must confirm the answer with RET, and can edit it until it
has been confirmed.
@ -3234,6 +3237,12 @@ if `last-nonmenu-event' is nil, and `use-dialog-box' is non-nil. */)
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, build_string (" "));
}
prompt = CALLN (Fconcat, prompt, Vyes_or_no_prompt);
specpdl_ref count = SPECPDL_INDEX ();