(lispref.info)Yes-or-No Queries


Next: Multiple Queries Prev: Completion Up: Minibuffers

Yes-or-No Queries
=================

   This section describes functions used to ask the user a yes-or-no
question.  The function `y-or-n-p' can be answered with a single
character; it is useful for questions where an inadvertent wrong answer
will not have serious consequences.  `yes-or-no-p' is suitable for more
momentous questions, since it requires three or four characters to
answer.  Variations of these functions can be used to ask a yes-or-no
question using a dialog box, or optionally using one.

   Strictly speaking, not all of these functions use the minibuffer; but
it seems best to describe them together.

 - Function: y-or-n-p PROMPT
     This function asks the user a question, expecting input in the echo
     area.  It returns `t' if the user types `y', `nil' if the user
     types `n'.  This function also accepts SPC to mean yes and DEL to
     mean no.  It accepts `C-]' to mean "quit", like `C-g', because the
     question might look like a minibuffer and for that reason the user
     might try to use `C-]' to get out.  The answer is a single
     character, with no RET needed to terminate it.  Upper and lower
     case are equivalent.

     "Asking the question" means printing PROMPT in the echo area,
     followed by the string `(y or n) '.  If the input is not one of
     the expected answers (`y', `n', `SPC', `DEL', or something that
     quits), the function responds `Please answer y or n.', and repeats
     the request.

     This function does not actually use the minibuffer, since it does
     not allow editing of the answer.  It actually uses the echo area
     (Note: The Echo Area.), which uses the same screen space as the
     minibuffer.  The cursor moves to the echo area while the question
     is being asked.

     The meanings of answers, even `y' and `n', are not hardwired.
     They are controlled by the keymap `query-replace-map'.  *Note
     Replacement::.

     In the following example, the user first types `q', which is
     invalid.  At the next prompt the user types `n'.

          (y-or-n-p "Do you need a lift? ")
          
          ;; After evaluating the preceding expression,
          ;;   the following prompt appears in the echo area:

          ---------- Echo area ----------
          Do you need a lift? (y or n)
          ---------- Echo area ----------
          
          ;; If the user then types `q', the following appears:
          ---------- Echo area ----------
          Please answer y or n.  Do you need a lift? (y or n)
          ---------- Echo area ----------
          
          ;; When the user types a valid answer,
          ;;   it is displayed after the question:
          ---------- Echo area ----------
          Do you need a lift? (y or n) y
          ---------- Echo area ----------

     Note that we show successive lines of echo area messages here.
     Only one actually appears on the screen at a time.

 - Function: yes-or-no-p PROMPT
     This function asks the user a question, expecting input in
     minibuffer.  It returns `t' if the user enters `yes', `nil' if the
     user types `no'.  The user must type RET to finalize the response.
     Upper and lower case are equivalent.

     `yes-or-no-p' starts by displaying PROMPT in the echo area,
     followed by `(yes or no) '.  The user must type one of the
     expected responses; otherwise, the function responds `Please answer
     yes or no.', waits about two seconds and repeats the request.

     `yes-or-no-p' requires more work from the user than `y-or-n-p' and
     is appropriate for more crucial decisions.

     Here is an example:

          (yes-or-no-p "Do you really want to remove everything? ")
          
          ;; After evaluating 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 ----------

     If the user first types `y RET', which is invalid because this
     function demands the entire word `yes', it responds by displaying
     these prompts, with a brief pause between them:

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

 - Function: yes-or-no-p-dialog-box PROMPT
     This function asks the user a "y or n" question with a popup dialog
     box.  It returns `t' if the answer is "yes".  PROMPT is the string
     to display to ask the question.

   The following functions ask a question either in the minibuffer or a
dialog box, depending on whether the last user event (which presumably
invoked this command) was a keyboard or mouse event.  When Emacs is
running on a window system, the functions `y-or-n-p' and `yes-or-no-p'
are replaced with the following functions, so that menu items bring up
dialog boxes instead of minibuffer questions.

 - Function: y-or-n-p-maybe-dialog-box PROMPT
     This function asks user a "y or n" question, using either a dialog
     box or the minibuffer, as appropriate.

 - Function: yes-or-no-p-maybe-dialog-box PROMPT
     This function asks user a "yes or no" question, using either a
     dialog box or the minibuffer, as appropriate.


automatically generated by info2www