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.
The user must confirm the answer with RET, and can edit it until it has been confirmed.
If the use-short-answers variable is non-nil, instead of asking for
"yes" or "no", this function will ask for "y" or "n".
If dialog boxes are supported, this function will use a dialog box
if use-dialog-box is non-nil and the last input event was produced
by a mouse, or by some window-system gesture, or via a menu.
Probably introduced at or before Emacs version 19.23.
Source Code
// Defined in /usr/src/emacs/src/fns.c
{
Lisp_Object ans, val;
CHECK_STRING (prompt);
if (!NILP (last_input_event)
&& (CONSP (last_nonmenu_event)
|| (NILP (last_nonmenu_event) && CONSP (last_input_event))
|| (val = find_symbol_value (Qfrom__tty_menu_p),
(!NILP (val) && !EQ (val, Qunbound))))
&& use_dialog_box)
{
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);
specpdl_ref count = SPECPDL_INDEX ();
specbind (Qenable_recursive_minibuffers, Qt);
/* Preserve the actual command that eventually called `yes-or-no-p'
(otherwise `repeat' will be repeating `exit-minibuffer'). */
specbind (Qreal_this_command, Vreal_this_command);
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);
}
}