Go to the first, previous, next, last section, table of contents.


Prompting

The most common way to ask the user for a response is to encode the question in the command's interactive declaration (see section Interactive Declarations), sometimes this is inconvenient; functions are available which have the same effect as the code letters in an interactive declaration.

The following two functions don't have an equivalent code for the interactive declaration.

Function: y-or-n-p question
This function prompts the user for a single key response to the string question asking a question which can be answered yes or no.

Returns t when question is answered with a y and nil when n is typed.

Function: yes-or-no-p question
Similar to y-or-n-p but the answer must be either the word `yes' or the word no entered in full. This function should be used when a mistyped answer could be catastrophic (i.e. losing changes to a buffer).

Returns t for `yes', nil for anything else.

The following functions are the functions used by the call-command function to resolve interactive arguments.

Note that these function don't return the string entered (except for prompt-for-string) -- they return some Lisp object which the string entered represents somehow.

Function: prompt-for-file &optional prompt existing start
Prompts for the name of a file. prompt is the string to display at the head of the prompt, when existing is non-nil only files which actually exist are allowed to be entered. The start argument may be a string defining the starting contents of the prompt.

Function: prompt-for-directory &optional prompt existing start
Prompts for the name of a directory, all arguments are similar to in the prompt-for-file function.

Function: prompt-for-buffer &optional prompt existing default
This function prompts for a buffer object, if existing is non-nil the buffer selected must exist, otherwise the buffer will be created if it doesn't already exist. default is the value to return if the user enters the null string, if nil the current buffer is returned.

Note that this returns the actual buffer, not its name as a string.

Function: prompt-for-symbol &optional prompt predicate
Prompt for a symbol, prompt is displayed at the head of the prompt buffer. If the predicate argument is defined it is a predicate function; only symbols which when applied to the function predicate return non-nil will be allowed to be entered.

Function: prompt-for-lisp &optional prompt
Prompt for and return a Lisp object.

Function: prompt-for-function &optional prompt
Prompts for a function.

(prompt-for-function prompt)
==
(prompt-for-symbol prompt 'functionp)

Function: prompt-for-variable &optional prompt
Prompts for a variable (a symbol whose value is not void).

(prompt-for-variable prompt)
==
(prompt-for-symbol prompt 'boundp)

Function: prompt-for-command &optional prompt
Prompts for a command (a function which may be called interactively).

(prompt-for-command prompt)
==
(prompt-for-symbol prompt 'commandp)

Function: prompt-for-string &optional prompt
Prompt for a string, whatever string is entered is returned as-is.

Function: prompt-for-number &optional prompt
Prompts for a number which is then returned.

The following function is useful when a number of options have to be chosen between, for example the menu command in Info-mode uses this function.

Function: prompt-from-list option-list prompt &optional start
Returns a selected choice from the list of options (strings) option-list. prompt is the title displayed, start the optional starting choice.


Go to the first, previous, next, last section, table of contents.