Function: yes-or-no-p
yes-or-no-p is a function defined in fns.c.
Signature
(yes-or-no-p PROMPT)
Documentation
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.
The user must confirm the answer with RET, and can edit it until it has been confirmed.
If dialog boxes are supported, a dialog box will be used
if last-nonmenu-event is nil, and use-dialog-box is non-nil.
Probably introduced at or before Emacs version 19.23.
Source Code
// Defined in /usr/src/emacs/src/fns.c
{
Lisp_Object ans;
CHECK_STRING (prompt);
if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
&& use_dialog_box && ! NILP (last_input_event))
{
Lisp_Object pane, menu, obj;
redisplay_preserve_echo_area (4);
pane = list2 (Fcons (build_string ("Yes"), Qt),
Fcons (build_string ("No"), Qnil));
menu = Fcons (prompt, pane);
obj = Fx_popup_dialog (Qt, menu, Qnil);
return obj;
}
if (use_short_answers)
return call1 (intern ("y-or-n-p"), prompt);
AUTO_STRING (yes_or_no, "(yes or no) ");
prompt = CALLN (Fconcat, prompt, yes_or_no);
ptrdiff_t count = SPECPDL_INDEX ();
specbind (Qenable_recursive_minibuffers, Qt);
while (1)
{
ans = Fdowncase (Fread_from_minibuffer (prompt, Qnil, Qnil, Qnil,
Qyes_or_no_p_history, Qnil,
Qnil));
if (SCHARS (ans) == 3 && !strcmp (SSDATA (ans), "yes"))
return unbind_to (count, Qt);
if (SCHARS (ans) == 2 && !strcmp (SSDATA (ans), "no"))
return unbind_to (count, Qnil);
Fding (Qnil);
Fdiscard_input ();
message1 ("Please answer yes or no.");
Fsleep_for (make_fixnum (2), Qnil);
}
}