annotate doc/lispref/minibuf.texi @ 84230:c6c2d1e7f3e4

Move here from ../../man
author Glenn Morris <rgm@gnu.org>
date Thu, 06 Sep 2007 04:44:54 +0000
parents 0ba80d073e27
children 25264f468203
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84087
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1 @c -*-texinfo-*-
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2 @c This is part of the GNU Emacs Lisp Reference Manual.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001, 2002,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
4 @c 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5 @c See the file elisp.texi for copying conditions.
84116
0ba80d073e27 (setfilename): Go up one more level to ../../info.
Glenn Morris <rgm@gnu.org>
parents: 84087
diff changeset
6 @setfilename ../../info/minibuf
84087
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7 @node Minibuffers, Command Loop, Read and Print, Top
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8 @chapter Minibuffers
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9 @cindex arguments, reading
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10 @cindex complex arguments
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
11 @cindex minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
13 A @dfn{minibuffer} is a special buffer that Emacs commands use to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
14 read arguments more complicated than the single numeric prefix
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15 argument. These arguments include file names, buffer names, and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16 command names (as in @kbd{M-x}). The minibuffer is displayed on the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 bottom line of the frame, in the same place as the echo area
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 (@pxref{The Echo Area}), but only while it is in use for reading an
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19 argument.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21 @menu
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22 * Intro to Minibuffers:: Basic information about minibuffers.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 * Text from Minibuffer:: How to read a straight text string.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24 * Object from Minibuffer:: How to read a Lisp object or expression.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25 * Minibuffer History:: Recording previous minibuffer inputs
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26 so the user can reuse them.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 * Initial Input:: Specifying initial contents for the minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 * Completion:: How to invoke and customize completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 * Yes-or-No Queries:: Asking a question with a simple answer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 * Multiple Queries:: Asking a series of similar questions.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 * Reading a Password:: Reading a password from the terminal.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 * Minibuffer Commands:: Commands used as key bindings in minibuffers.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 * Minibuffer Contents:: How such commands access the minibuffer text.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34 * Minibuffer Windows:: Operating on the special minibuffer windows.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 * Recursive Mini:: Whether recursive entry to minibuffer is allowed.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36 * Minibuffer Misc:: Various customization hooks and variables.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 @end menu
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 @node Intro to Minibuffers
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 @section Introduction to Minibuffers
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 In most ways, a minibuffer is a normal Emacs buffer. Most operations
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 @emph{within} a buffer, such as editing commands, work normally in a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 minibuffer. However, many operations for managing buffers do not apply
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 to minibuffers. The name of a minibuffer always has the form @w{@samp{
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 *Minibuf-@var{number}*}}, and it cannot be changed. Minibuffers are
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 displayed only in special windows used only for minibuffers; these
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 windows always appear at the bottom of a frame. (Sometimes frames have
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 no minibuffer window, and sometimes a special kind of frame contains
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 nothing but a minibuffer window; see @ref{Minibuffers and Frames}.)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 The text in the minibuffer always starts with the @dfn{prompt string},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 the text that was specified by the program that is using the minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 to tell the user what sort of input to type. This text is marked
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 read-only so you won't accidentally delete or change it. It is also
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 marked as a field (@pxref{Fields}), so that certain motion functions,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 including @code{beginning-of-line}, @code{forward-word},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 @code{forward-sentence}, and @code{forward-paragraph}, stop at the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 boundary between the prompt and the actual text. (In older Emacs
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 versions, the prompt was displayed using a special mechanism and was not
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 part of the buffer contents.)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 The minibuffer's window is normally a single line; it grows
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 automatically if necessary if the contents require more space. You can
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 explicitly resize it temporarily with the window sizing commands; it
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 reverts to its normal size when the minibuffer is exited. You can
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 resize it permanently by using the window sizing commands in the frame's
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 other window, when the minibuffer is not active. If the frame contains
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 just a minibuffer, you can change the minibuffer's size by changing the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 frame's size.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 Use of the minibuffer reads input events, and that alters the values
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 of variables such as @code{this-command} and @code{last-command}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 (@pxref{Command Loop Info}). Your program should bind them around the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 code that uses the minibuffer, if you do not want that to change them.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 If a command uses a minibuffer while there is an active minibuffer,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 this is called a @dfn{recursive minibuffer}. The first minibuffer is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 named @w{@samp{ *Minibuf-0*}}. Recursive minibuffers are named by
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 incrementing the number at the end of the name. (The names begin with a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 space so that they won't show up in normal buffer lists.) Of several
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 recursive minibuffers, the innermost (or most recently entered) is the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 active minibuffer. We usually call this ``the'' minibuffer. You can
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 permit or forbid recursive minibuffers by setting the variable
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 @code{enable-recursive-minibuffers} or by putting properties of that
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 name on command symbols (@pxref{Recursive Mini}).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88 Like other buffers, a minibuffer uses a local keymap
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
89 (@pxref{Keymaps}) to specify special key bindings. The function that
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90 invokes the minibuffer also sets up its local map according to the job
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91 to be done. @xref{Text from Minibuffer}, for the non-completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 minibuffer local maps. @xref{Completion Commands}, for the minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 local maps for completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95 When Emacs is running in batch mode, any request to read from the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96 minibuffer actually reads a line from the standard input descriptor that
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97 was supplied when Emacs was started.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99 @node Text from Minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100 @section Reading Text Strings with the Minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 Most often, the minibuffer is used to read text as a string. It can
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103 also be used to read a Lisp object in textual form. The most basic
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104 primitive for minibuffer input is @code{read-from-minibuffer}; it can do
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 either one. There are also specialized commands for reading
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
106 commands, variables, file names, etc. (@pxref{Completion}).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108 In most cases, you should not call minibuffer input functions in the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 middle of a Lisp function. Instead, do all minibuffer input as part of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 reading the arguments for a command, in the @code{interactive}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 specification. @xref{Defining Commands}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 @defun read-from-minibuffer prompt-string &optional initial-contents keymap read hist default inherit-input-method
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114 This function is the most general way to get input through the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 minibuffer. By default, it accepts arbitrary text and returns it as a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116 string; however, if @var{read} is non-@code{nil}, then it uses
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 @code{read} to convert the text into a Lisp object (@pxref{Input
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 Functions}).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120 The first thing this function does is to activate a minibuffer and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 display it with @var{prompt-string} as the prompt. This value must be a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122 string. Then the user can edit text in the minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 When the user types a command to exit the minibuffer,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 @code{read-from-minibuffer} constructs the return value from the text in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 the minibuffer. Normally it returns a string containing that text.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 However, if @var{read} is non-@code{nil}, @code{read-from-minibuffer}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 reads the text and returns the resulting Lisp object, unevaluated.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129 (@xref{Input Functions}, for information about reading.)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 The argument @var{default} specifies a default value to make available
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 through the history commands. It should be a string, or @code{nil}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133 If non-@code{nil}, the user can access it using
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 @code{next-history-element}, usually bound in the minibuffer to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 @kbd{M-n}. If @var{read} is non-@code{nil}, then @var{default} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 also used as the input to @code{read}, if the user enters empty input.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137 (If @var{read} is non-@code{nil} and @var{default} is @code{nil}, empty
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
138 input results in an @code{end-of-file} error.) However, in the usual
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 case (where @var{read} is @code{nil}), @code{read-from-minibuffer}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 ignores @var{default} when the user enters empty input and returns an
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 empty string, @code{""}. In this respect, it is different from all
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 the other minibuffer input functions in this chapter.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 If @var{keymap} is non-@code{nil}, that keymap is the local keymap to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145 use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146 value of @code{minibuffer-local-map} is used as the keymap. Specifying
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147 a keymap is the most important way to customize the minibuffer for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 various applications such as completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 The argument @var{hist} specifies which history list variable to use
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 for saving the input and for history commands used in the minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 It defaults to @code{minibuffer-history}. @xref{Minibuffer History}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 If the variable @code{minibuffer-allow-text-properties} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 non-@code{nil}, then the string which is returned includes whatever text
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 properties were present in the minibuffer. Otherwise all the text
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157 properties are stripped when the value is returned.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 If the argument @var{inherit-input-method} is non-@code{nil}, then the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 minibuffer inherits the current input method (@pxref{Input Methods}) and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161 the setting of @code{enable-multibyte-characters} (@pxref{Text
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
162 Representations}) from whichever buffer was current before entering the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163 minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165 Use of @var{initial-contents} is mostly deprecated; we recommend using
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166 a non-@code{nil} value only in conjunction with specifying a cons cell
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 for @var{hist}. @xref{Initial Input}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
169
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
170 @defun read-string prompt &optional initial history default inherit-input-method
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
171 This function reads a string from the minibuffer and returns it. The
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
172 arguments @var{prompt}, @var{initial}, @var{history} and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
173 @var{inherit-input-method} are used as in @code{read-from-minibuffer}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
174 The keymap used is @code{minibuffer-local-map}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
175
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
176 The optional argument @var{default} is used as in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
177 @code{read-from-minibuffer}, except that, if non-@code{nil}, it also
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178 specifies a default value to return if the user enters null input. As
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179 in @code{read-from-minibuffer} it should be a string, or @code{nil},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
180 which is equivalent to an empty string.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
181
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
182 This function is a simplified interface to the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
183 @code{read-from-minibuffer} function:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
187 (read-string @var{prompt} @var{initial} @var{history} @var{default} @var{inherit})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188 @equiv{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
189 (let ((value
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
190 (read-from-minibuffer @var{prompt} @var{initial} nil nil
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 @var{history} @var{default} @var{inherit})))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192 (if (and (equal value "") @var{default})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193 @var{default}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194 value))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
197 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199 @defvar minibuffer-allow-text-properties
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200 If this variable is @code{nil}, then @code{read-from-minibuffer} strips
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 all text properties from the minibuffer input before returning it.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202 This variable also affects @code{read-string}. However,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203 @code{read-no-blanks-input} (see below), as well as
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
204 @code{read-minibuffer} and related functions (@pxref{Object from
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 Minibuffer,, Reading Lisp Objects With the Minibuffer}), and all
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206 functions that do minibuffer input with completion, discard text
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
207 properties unconditionally, regardless of the value of this variable.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210 @defvar minibuffer-local-map
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211 This
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212 @anchor{Definition of minibuffer-local-map}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
213 @c avoid page break at anchor; work around Texinfo deficiency
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214 is the default local keymap for reading from the minibuffer. By
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215 default, it makes the following bindings:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 @table @asis
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 @item @kbd{C-j}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 @code{exit-minibuffer}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
220
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 @item @key{RET}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
222 @code{exit-minibuffer}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224 @item @kbd{C-g}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
225 @code{abort-recursive-edit}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
226
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
227 @item @kbd{M-n}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
228 @itemx @key{DOWN}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
229 @code{next-history-element}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
230
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
231 @item @kbd{M-p}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
232 @itemx @key{UP}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
233 @code{previous-history-element}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
234
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
235 @item @kbd{M-s}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
236 @code{next-matching-history-element}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
237
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
238 @item @kbd{M-r}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
239 @code{previous-matching-history-element}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
240 @end table
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
241 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
242
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
243 @c In version 18, initial is required
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
244 @c Emacs 19 feature
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
245 @defun read-no-blanks-input prompt &optional initial inherit-input-method
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
246 This function reads a string from the minibuffer, but does not allow
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
247 whitespace characters as part of the input: instead, those characters
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
248 terminate the input. The arguments @var{prompt}, @var{initial}, and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
249 @var{inherit-input-method} are used as in @code{read-from-minibuffer}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
250
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
251 This is a simplified interface to the @code{read-from-minibuffer}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
252 function, and passes the value of the @code{minibuffer-local-ns-map}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
253 keymap as the @var{keymap} argument for that function. Since the keymap
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
254 @code{minibuffer-local-ns-map} does not rebind @kbd{C-q}, it @emph{is}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
255 possible to put a space into the string, by quoting it.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
256
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
257 This function discards text properties, regardless of the value of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
258 @code{minibuffer-allow-text-properties}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
259
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
260 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
261 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
262 (read-no-blanks-input @var{prompt} @var{initial})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
263 @equiv{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
264 (let (minibuffer-allow-text-properties)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
265 (read-from-minibuffer @var{prompt} @var{initial} minibuffer-local-ns-map))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
266 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
267 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
268 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
269
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
270 @defvar minibuffer-local-ns-map
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
271 This built-in variable is the keymap used as the minibuffer local keymap
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
272 in the function @code{read-no-blanks-input}. By default, it makes the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
273 following bindings, in addition to those of @code{minibuffer-local-map}:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
274
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
275 @table @asis
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
276 @item @key{SPC}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
277 @cindex @key{SPC} in minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
278 @code{exit-minibuffer}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
279
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
280 @item @key{TAB}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
281 @cindex @key{TAB} in minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
282 @code{exit-minibuffer}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
283
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
284 @item @kbd{?}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
285 @cindex @kbd{?} in minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
286 @code{self-insert-and-exit}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
287 @end table
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
288 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
289
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
290 @node Object from Minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
291 @section Reading Lisp Objects with the Minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
292
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
293 This section describes functions for reading Lisp objects with the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
294 minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
295
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
296 @defun read-minibuffer prompt &optional initial
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
297 This function reads a Lisp object using the minibuffer, and returns it
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
298 without evaluating it. The arguments @var{prompt} and @var{initial} are
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
299 used as in @code{read-from-minibuffer}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
300
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
301 This is a simplified interface to the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
302 @code{read-from-minibuffer} function:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
303
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
304 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
305 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
306 (read-minibuffer @var{prompt} @var{initial})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
307 @equiv{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
308 (let (minibuffer-allow-text-properties)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
309 (read-from-minibuffer @var{prompt} @var{initial} nil t))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
310 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
311 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
312
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
313 Here is an example in which we supply the string @code{"(testing)"} as
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
314 initial input:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
315
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
316 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
317 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
318 (read-minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
319 "Enter an expression: " (format "%s" '(testing)))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
320
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
321 ;; @r{Here is how the minibuffer is displayed:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
322 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
323
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
324 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
325 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
326 Enter an expression: (testing)@point{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
327 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
328 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
329 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
330
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
331 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
332 The user can type @key{RET} immediately to use the initial input as a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
333 default, or can edit the input.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
334 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
335
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
336 @defun eval-minibuffer prompt &optional initial
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
337 This function reads a Lisp expression using the minibuffer, evaluates
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
338 it, then returns the result. The arguments @var{prompt} and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
339 @var{initial} are used as in @code{read-from-minibuffer}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
340
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
341 This function simply evaluates the result of a call to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
342 @code{read-minibuffer}:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
343
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
344 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
345 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
346 (eval-minibuffer @var{prompt} @var{initial})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
347 @equiv{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
348 (eval (read-minibuffer @var{prompt} @var{initial}))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
349 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
350 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
351 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
352
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
353 @defun edit-and-eval-command prompt form
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
354 This function reads a Lisp expression in the minibuffer, and then
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
355 evaluates it. The difference between this command and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
356 @code{eval-minibuffer} is that here the initial @var{form} is not
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
357 optional and it is treated as a Lisp object to be converted to printed
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
358 representation rather than as a string of text. It is printed with
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
359 @code{prin1}, so if it is a string, double-quote characters (@samp{"})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
360 appear in the initial text. @xref{Output Functions}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
361
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
362 The first thing @code{edit-and-eval-command} does is to activate the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
363 minibuffer with @var{prompt} as the prompt. Then it inserts the printed
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
364 representation of @var{form} in the minibuffer, and lets the user edit it.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
365 When the user exits the minibuffer, the edited text is read with
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
366 @code{read} and then evaluated. The resulting value becomes the value
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
367 of @code{edit-and-eval-command}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
368
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
369 In the following example, we offer the user an expression with initial
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
370 text which is a valid form already:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
371
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
372 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
373 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
374 (edit-and-eval-command "Please edit: " '(forward-word 1))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
375
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
376 ;; @r{After evaluation of the preceding expression,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
377 ;; @r{the following appears in the minibuffer:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
378 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
379
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
380 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
381 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
382 Please edit: (forward-word 1)@point{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
383 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
384 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
385 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
386
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
387 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
388 Typing @key{RET} right away would exit the minibuffer and evaluate the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
389 expression, thus moving point forward one word.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
390 @code{edit-and-eval-command} returns @code{nil} in this example.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
391 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
392
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
393 @node Minibuffer History
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
394 @section Minibuffer History
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
395 @cindex minibuffer history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
396 @cindex history list
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
397
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
398 A @dfn{minibuffer history list} records previous minibuffer inputs so
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
399 the user can reuse them conveniently. A history list is actually a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
400 symbol, not a list; it is a variable whose value is a list of strings
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
401 (previous inputs), most recent first.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
402
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
403 There are many separate history lists, used for different kinds of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
404 inputs. It's the Lisp programmer's job to specify the right history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
405 list for each use of the minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
406
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
407 You specify the history list with the optional @var{hist} argument
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
408 to either @code{read-from-minibuffer} or @code{completing-read}. Here
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
409 are the possible values for it:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
410
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
411 @table @asis
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
412 @item @var{variable}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
413 Use @var{variable} (a symbol) as the history list.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
414
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
415 @item (@var{variable} . @var{startpos})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
416 Use @var{variable} (a symbol) as the history list, and assume that the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
417 initial history position is @var{startpos} (a nonnegative integer).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
418
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
419 Specifying 0 for @var{startpos} is equivalent to just specifying the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
420 symbol @var{variable}. @code{previous-history-element} will display
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
421 the most recent element of the history list in the minibuffer. If you
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
422 specify a positive @var{startpos}, the minibuffer history functions
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
423 behave as if @code{(elt @var{variable} (1- @var{STARTPOS}))} were the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
424 history element currently shown in the minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
425
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
426 For consistency, you should also specify that element of the history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
427 as the initial minibuffer contents, using the @var{initial} argument
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
428 to the minibuffer input function (@pxref{Initial Input}).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
429 @end table
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
430
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
431 If you don't specify @var{hist}, then the default history list
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
432 @code{minibuffer-history} is used. For other standard history lists,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
433 see below. You can also create your own history list variable; just
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
434 initialize it to @code{nil} before the first use.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
435
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
436 Both @code{read-from-minibuffer} and @code{completing-read} add new
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
437 elements to the history list automatically, and provide commands to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
438 allow the user to reuse items on the list. The only thing your program
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
439 needs to do to use a history list is to initialize it and to pass its
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
440 name to the input functions when you wish. But it is safe to modify the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
441 list by hand when the minibuffer input functions are not using it.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
442
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
443 Emacs functions that add a new element to a history list can also
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
444 delete old elements if the list gets too long. The variable
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
445 @code{history-length} specifies the maximum length for most history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
446 lists. To specify a different maximum length for a particular history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
447 list, put the length in the @code{history-length} property of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
448 history list symbol. The variable @code{history-delete-duplicates}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
449 specifies whether to delete duplicates in history.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
450
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
451 @defun add-to-history history-var newelt &optional maxelt keep-all
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
452 This function adds a new element @var{newelt}, if it isn't the empty
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
453 string, to the history list stored in the variable @var{history-var},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
454 and returns the updated history list. It limits the list length to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
455 the value of @var{maxelt} (if non-@code{nil}) or @code{history-length}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
456 (described below). The possible values of @var{maxelt} have the same
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
457 meaning as the values of @code{history-length}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
458
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
459 Normally, @code{add-to-history} removes duplicate members from the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
460 history list if @code{history-delete-duplicates} is non-@code{nil}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
461 However, if @var{keep-all} is non-@code{nil}, that says not to remove
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
462 duplicates, and to add @var{newelt} to the list even if it is empty.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
463 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
464
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
465 @defvar history-add-new-input
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
466 If the value of this variable is @code{nil}, standard functions that
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
467 read from the minibuffer don't add new elements to the history list.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
468 This lets Lisp programs explicitly manage input history by using
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
469 @code{add-to-history}. By default, @code{history-add-new-input} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
470 set to a non-@code{nil} value.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
471 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
472
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
473 @defvar history-length
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
474 The value of this variable specifies the maximum length for all
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
475 history lists that don't specify their own maximum lengths. If the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
476 value is @code{t}, that means there no maximum (don't delete old
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
477 elements). The value of @code{history-length} property of the history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
478 list variable's symbol, if set, overrides this variable for that
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
479 particular history list.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
480 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
481
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
482 @defvar history-delete-duplicates
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
483 If the value of this variable is @code{t}, that means when adding a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
484 new history element, all previous identical elements are deleted.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
485 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
486
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
487 Here are some of the standard minibuffer history list variables:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
488
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
489 @defvar minibuffer-history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
490 The default history list for minibuffer history input.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
491 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
492
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
493 @defvar query-replace-history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
494 A history list for arguments to @code{query-replace} (and similar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
495 arguments to other commands).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
496 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
497
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
498 @defvar file-name-history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
499 A history list for file-name arguments.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
500 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
501
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
502 @defvar buffer-name-history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
503 A history list for buffer-name arguments.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
504 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
505
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
506 @defvar regexp-history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
507 A history list for regular expression arguments.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
508 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
509
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
510 @defvar extended-command-history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
511 A history list for arguments that are names of extended commands.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
512 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
513
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
514 @defvar shell-command-history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
515 A history list for arguments that are shell commands.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
516 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
517
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
518 @defvar read-expression-history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
519 A history list for arguments that are Lisp expressions to evaluate.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
520 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
521
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
522 @node Initial Input
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
523 @section Initial Input
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
524
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
525 Several of the functions for minibuffer input have an argument called
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
526 @var{initial} or @var{initial-contents}. This is a mostly-deprecated
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
527 feature for specifying that the minibuffer should start out with
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
528 certain text, instead of empty as usual.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
529
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
530 If @var{initial} is a string, the minibuffer starts out containing the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
531 text of the string, with point at the end, when the user starts to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
532 edit the text. If the user simply types @key{RET} to exit the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
533 minibuffer, it will use the initial input string to determine the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
534 value to return.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
535
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
536 @strong{We discourage use of a non-@code{nil} value for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
537 @var{initial}}, because initial input is an intrusive interface.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
538 History lists and default values provide a much more convenient method
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
539 to offer useful default inputs to the user.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
540
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
541 There is just one situation where you should specify a string for an
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
542 @var{initial} argument. This is when you specify a cons cell for the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
543 @var{hist} or @var{history} argument. @xref{Minibuffer History}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
544
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
545 @var{initial} can also be a cons cell of the form @code{(@var{string}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
546 . @var{position})}. This means to insert @var{string} in the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
547 minibuffer but put point at @var{position} within the string's text.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
548
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
549 As a historical accident, @var{position} was implemented
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
550 inconsistently in different functions. In @code{completing-read},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
551 @var{position}'s value is interpreted as origin-zero; that is, a value
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
552 of 0 means the beginning of the string, 1 means after the first
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
553 character, etc. In @code{read-minibuffer}, and the other
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
554 non-completion minibuffer input functions that support this argument,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
555 1 means the beginning of the string 2 means after the first character,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
556 etc.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
557
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
558 Use of a cons cell as the value for @var{initial} arguments is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
559 deprecated in user code.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
560
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
561 @node Completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
562 @section Completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
563 @cindex completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
564
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
565 @dfn{Completion} is a feature that fills in the rest of a name
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
566 starting from an abbreviation for it. Completion works by comparing the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
567 user's input against a list of valid names and determining how much of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
568 the name is determined uniquely by what the user has typed. For
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
569 example, when you type @kbd{C-x b} (@code{switch-to-buffer}) and then
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
570 type the first few letters of the name of the buffer to which you wish
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
571 to switch, and then type @key{TAB} (@code{minibuffer-complete}), Emacs
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
572 extends the name as far as it can.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
573
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
574 Standard Emacs commands offer completion for names of symbols, files,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
575 buffers, and processes; with the functions in this section, you can
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
576 implement completion for other kinds of names.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
577
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
578 The @code{try-completion} function is the basic primitive for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
579 completion: it returns the longest determined completion of a given
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
580 initial string, with a given set of strings to match against.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
581
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
582 The function @code{completing-read} provides a higher-level interface
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
583 for completion. A call to @code{completing-read} specifies how to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
584 determine the list of valid names. The function then activates the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
585 minibuffer with a local keymap that binds a few keys to commands useful
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
586 for completion. Other functions provide convenient simple interfaces
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
587 for reading certain kinds of names with completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
588
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
589 @menu
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
590 * Basic Completion:: Low-level functions for completing strings.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
591 (These are too low level to use the minibuffer.)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
592 * Minibuffer Completion:: Invoking the minibuffer with completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
593 * Completion Commands:: Minibuffer commands that do completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
594 * High-Level Completion:: Convenient special cases of completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
595 (reading buffer name, file name, etc.)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
596 * Reading File Names:: Using completion to read file names.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
597 * Programmed Completion:: Writing your own completion-function.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
598 @end menu
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
599
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
600 @node Basic Completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
601 @subsection Basic Completion Functions
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
602
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
603 The completion functions @code{try-completion},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
604 @code{all-completions} and @code{test-completion} have nothing in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
605 themselves to do with minibuffers. We describe them in this chapter
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
606 so as to keep them near the higher-level completion features that do
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
607 use the minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
608
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
609 If you store a completion alist in a variable, you should mark the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
610 variable as ``risky'' with a non-@code{nil}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
611 @code{risky-local-variable} property.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
612
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
613 @defun try-completion string collection &optional predicate
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
614 This function returns the longest common substring of all possible
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
615 completions of @var{string} in @var{collection}. The value of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
616 @var{collection} must be a list of strings or symbols, an alist, an
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
617 obarray, a hash table, or a function that implements a virtual set of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
618 strings (see below).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
619
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
620 Completion compares @var{string} against each of the permissible
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
621 completions specified by @var{collection}; if the beginning of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
622 permissible completion equals @var{string}, it matches. If no permissible
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
623 completions match, @code{try-completion} returns @code{nil}. If only
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
624 one permissible completion matches, and the match is exact, then
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
625 @code{try-completion} returns @code{t}. Otherwise, the value is the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
626 longest initial sequence common to all the permissible completions that
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
627 match.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
628
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
629 If @var{collection} is an alist (@pxref{Association Lists}), the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
630 permissible completions are the elements of the alist that are either
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
631 strings, symbols, or conses whose @sc{car} is a string or symbol.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
632 Symbols are converted to strings using @code{symbol-name}. Other
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
633 elements of the alist are ignored. (Remember that in Emacs Lisp, the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
634 elements of alists do not @emph{have} to be conses.) In particular, a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
635 list of strings or symbols is allowed, even though we usually do not
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
636 think of such lists as alists.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
637
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
638 @cindex obarray in completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
639 If @var{collection} is an obarray (@pxref{Creating Symbols}), the names
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
640 of all symbols in the obarray form the set of permissible completions. The
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
641 global variable @code{obarray} holds an obarray containing the names of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
642 all interned Lisp symbols.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
643
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
644 Note that the only valid way to make a new obarray is to create it
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
645 empty and then add symbols to it one by one using @code{intern}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
646 Also, you cannot intern a given symbol in more than one obarray.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
647
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
648 If @var{collection} is a hash table, then the keys that are strings
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
649 are the possible completions. Other keys are ignored.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
650
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
651 You can also use a symbol that is a function as @var{collection}. Then
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
652 the function is solely responsible for performing completion;
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
653 @code{try-completion} returns whatever this function returns. The
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
654 function is called with three arguments: @var{string}, @var{predicate}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
655 and @code{nil}. (The reason for the third argument is so that the same
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
656 function can be used in @code{all-completions} and do the appropriate
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
657 thing in either case.) @xref{Programmed Completion}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
658
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
659 If the argument @var{predicate} is non-@code{nil}, then it must be a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
660 function of one argument, unless @var{collection} is a hash table, in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
661 which case it should be a function of two arguments. It is used to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
662 test each possible match, and the match is accepted only if
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
663 @var{predicate} returns non-@code{nil}. The argument given to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
664 @var{predicate} is either a string or a cons cell (the @sc{car} of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
665 which is a string) from the alist, or a symbol (@emph{not} a symbol
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
666 name) from the obarray. If @var{collection} is a hash table,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
667 @var{predicate} is called with two arguments, the string key and the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
668 associated value.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
669
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
670 In addition, to be acceptable, a completion must also match all the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
671 regular expressions in @code{completion-regexp-list}. (Unless
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
672 @var{collection} is a function, in which case that function has to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
673 handle @code{completion-regexp-list} itself.)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
674
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
675 In the first of the following examples, the string @samp{foo} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
676 matched by three of the alist @sc{car}s. All of the matches begin with
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
677 the characters @samp{fooba}, so that is the result. In the second
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
678 example, there is only one possible match, and it is exact, so the value
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
679 is @code{t}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
680
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
681 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
682 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
683 (try-completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
684 "foo"
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
685 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
686 @result{} "fooba"
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
687 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
688
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
689 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
690 (try-completion "foo" '(("barfoo" 2) ("foo" 3)))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
691 @result{} t
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
692 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
693 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
694
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
695 In the following example, numerous symbols begin with the characters
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
696 @samp{forw}, and all of them begin with the word @samp{forward}. In
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
697 most of the symbols, this is followed with a @samp{-}, but not in all,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
698 so no more than @samp{forward} can be completed.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
699
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
700 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
701 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
702 (try-completion "forw" obarray)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
703 @result{} "forward"
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
704 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
705 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
706
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
707 Finally, in the following example, only two of the three possible
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
708 matches pass the predicate @code{test} (the string @samp{foobaz} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
709 too short). Both of those begin with the string @samp{foobar}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
710
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
711 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
712 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
713 (defun test (s)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
714 (> (length (car s)) 6))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
715 @result{} test
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
716 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
717 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
718 (try-completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
719 "foo"
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
720 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
721 'test)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
722 @result{} "foobar"
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
723 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
724 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
725 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
726
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
727 @defun all-completions string collection &optional predicate nospace
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
728 This function returns a list of all possible completions of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
729 @var{string}. The arguments to this function (aside from
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
730 @var{nospace}) are the same as those of @code{try-completion}. Also,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
731 this function uses @code{completion-regexp-list} in the same way that
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
732 @code{try-completion} does. The optional argument @var{nospace} only
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
733 matters if @var{string} is the empty string. In that case, if
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
734 @var{nospace} is non-@code{nil}, completions that start with a space
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
735 are ignored.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
736
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
737 If @var{collection} is a function, it is called with three arguments:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
738 @var{string}, @var{predicate} and @code{t}; then @code{all-completions}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
739 returns whatever the function returns. @xref{Programmed Completion}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
740
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
741 Here is an example, using the function @code{test} shown in the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
742 example for @code{try-completion}:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
743
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
744 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
745 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
746 (defun test (s)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
747 (> (length (car s)) 6))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
748 @result{} test
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
749 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
750
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
751 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
752 (all-completions
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
753 "foo"
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
754 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
755 'test)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
756 @result{} ("foobar1" "foobar2")
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
757 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
758 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
759 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
760
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
761 @defun test-completion string collection &optional predicate
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
762 @anchor{Definition of test-completion}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
763 This function returns non-@code{nil} if @var{string} is a valid
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
764 completion possibility specified by @var{collection} and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
765 @var{predicate}. The arguments are the same as in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
766 @code{try-completion}. For instance, if @var{collection} is a list of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
767 strings, this is true if @var{string} appears in the list and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
768 @var{predicate} is satisfied.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
769
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
770 This function uses @code{completion-regexp-list} in the same
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
771 way that @code{try-completion} does.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
772
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
773 If @var{predicate} is non-@code{nil} and if @var{collection} contains
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
774 several strings that are equal to each other, as determined by
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
775 @code{compare-strings} according to @code{completion-ignore-case},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
776 then @var{predicate} should accept either all or none of them.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
777 Otherwise, the return value of @code{test-completion} is essentially
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
778 unpredictable.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
779
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
780 If @var{collection} is a function, it is called with three arguments,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
781 the values @var{string}, @var{predicate} and @code{lambda}; whatever
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
782 it returns, @code{test-completion} returns in turn.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
783 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
784
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
785 @defvar completion-ignore-case
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
786 If the value of this variable is non-@code{nil}, Emacs does not
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
787 consider case significant in completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
788 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
789
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
790 @defvar completion-regexp-list
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
791 This is a list of regular expressions. The completion functions only
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
792 consider a completion acceptable if it matches all regular expressions
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
793 in this list, with @code{case-fold-search} (@pxref{Searching and Case})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
794 bound to the value of @code{completion-ignore-case}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
795 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
796
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
797 @defmac lazy-completion-table var fun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
798 This macro provides a way to initialize the variable @var{var} as a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
799 collection for completion in a lazy way, not computing its actual
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
800 contents until they are first needed. You use this macro to produce a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
801 value that you store in @var{var}. The actual computation of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
802 proper value is done the first time you do completion using @var{var}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
803 It is done by calling @var{fun} with no arguments. The
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
804 value @var{fun} returns becomes the permanent value of @var{var}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
805
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
806 Here is an example of use:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
807
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
808 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
809 (defvar foo (lazy-completion-table foo make-my-alist))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
810 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
811 @end defmac
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
812
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
813 @node Minibuffer Completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
814 @subsection Completion and the Minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
815 @cindex minibuffer completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
816 @cindex reading from minibuffer with completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
817
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
818 This section describes the basic interface for reading from the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
819 minibuffer with completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
820
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
821 @defun completing-read prompt collection &optional predicate require-match initial hist default inherit-input-method
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
822 This function reads a string in the minibuffer, assisting the user by
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
823 providing completion. It activates the minibuffer with prompt
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
824 @var{prompt}, which must be a string.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
825
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
826 The actual completion is done by passing @var{collection} and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
827 @var{predicate} to the function @code{try-completion}. This happens
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
828 in certain commands bound in the local keymaps used for completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
829 Some of these commands also call @code{test-completion}. Thus, if
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
830 @var{predicate} is non-@code{nil}, it should be compatible with
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
831 @var{collection} and @code{completion-ignore-case}. @xref{Definition
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
832 of test-completion}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
833
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
834 If @var{require-match} is @code{nil}, the exit commands work regardless
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
835 of the input in the minibuffer. If @var{require-match} is @code{t}, the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
836 usual minibuffer exit commands won't exit unless the input completes to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
837 an element of @var{collection}. If @var{require-match} is neither
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
838 @code{nil} nor @code{t}, then the exit commands won't exit unless the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
839 input already in the buffer matches an element of @var{collection}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
840
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
841 However, empty input is always permitted, regardless of the value of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
842 @var{require-match}; in that case, @code{completing-read} returns
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
843 @var{default}, or @code{""}, if @var{default} is @code{nil}. The
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
844 value of @var{default} (if non-@code{nil}) is also available to the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
845 user through the history commands.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
846
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
847 The function @code{completing-read} uses
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
848 @code{minibuffer-local-completion-map} as the keymap if
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
849 @var{require-match} is @code{nil}, and uses
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
850 @code{minibuffer-local-must-match-map} if @var{require-match} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
851 non-@code{nil}. @xref{Completion Commands}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
852
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
853 The argument @var{hist} specifies which history list variable to use for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
854 saving the input and for minibuffer history commands. It defaults to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
855 @code{minibuffer-history}. @xref{Minibuffer History}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
856
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
857 The argument @var{initial} is mostly deprecated; we recommend using a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
858 non-@code{nil} value only in conjunction with specifying a cons cell
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
859 for @var{hist}. @xref{Initial Input}. For default input, use
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
860 @var{default} instead.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
861
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
862 If the argument @var{inherit-input-method} is non-@code{nil}, then the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
863 minibuffer inherits the current input method (@pxref{Input
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
864 Methods}) and the setting of @code{enable-multibyte-characters}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
865 (@pxref{Text Representations}) from whichever buffer was current before
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
866 entering the minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
867
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
868 If the built-in variable @code{completion-ignore-case} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
869 non-@code{nil}, completion ignores case when comparing the input
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
870 against the possible matches. @xref{Basic Completion}. In this mode
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
871 of operation, @var{predicate} must also ignore case, or you will get
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
872 surprising results.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
873
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
874 Here's an example of using @code{completing-read}:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
875
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
876 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
877 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
878 (completing-read
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
879 "Complete a foo: "
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
880 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
881 nil t "fo")
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
882 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
883
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
884 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
885 ;; @r{After evaluation of the preceding expression,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
886 ;; @r{the following appears in the minibuffer:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
887
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
888 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
889 Complete a foo: fo@point{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
890 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
891 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
892 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
893
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
894 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
895 If the user then types @kbd{@key{DEL} @key{DEL} b @key{RET}},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
896 @code{completing-read} returns @code{barfoo}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
897
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
898 The @code{completing-read} function binds variables to pass
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
899 information to the commands that actually do completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
900 They are described in the following section.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
901 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
902
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
903 @node Completion Commands
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
904 @subsection Minibuffer Commands that Do Completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
905
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
906 This section describes the keymaps, commands and user options used
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
907 in the minibuffer to do completion. The description refers to the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
908 situation when Partial Completion mode is disabled (as it is by
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
909 default). When enabled, this minor mode uses its own alternatives to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
910 some of the commands described below. @xref{Completion Options,,,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
911 emacs, The GNU Emacs Manual}, for a short description of Partial
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
912 Completion mode.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
913
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
914 @defvar minibuffer-completion-table
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
915 The value of this variable is the collection used for completion in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
916 the minibuffer. This is the global variable that contains what
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
917 @code{completing-read} passes to @code{try-completion}. It is used by
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
918 minibuffer completion commands such as @code{minibuffer-complete-word}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
919 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
920
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
921 @defvar minibuffer-completion-predicate
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
922 This variable's value is the predicate that @code{completing-read}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
923 passes to @code{try-completion}. The variable is also used by the other
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
924 minibuffer completion functions.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
925 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
926
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
927 @defvar minibuffer-completion-confirm
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
928 When the value of this variable is non-@code{nil}, Emacs asks for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
929 confirmation of a completion before exiting the minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
930 @code{completing-read} binds this variable, and the function
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
931 @code{minibuffer-complete-and-exit} checks the value before exiting.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
932 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
933
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
934 @deffn Command minibuffer-complete-word
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
935 This function completes the minibuffer contents by at most a single
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
936 word. Even if the minibuffer contents have only one completion,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
937 @code{minibuffer-complete-word} does not add any characters beyond the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
938 first character that is not a word constituent. @xref{Syntax Tables}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
939 @end deffn
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
940
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
941 @deffn Command minibuffer-complete
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
942 This function completes the minibuffer contents as far as possible.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
943 @end deffn
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
944
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
945 @deffn Command minibuffer-complete-and-exit
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
946 This function completes the minibuffer contents, and exits if
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
947 confirmation is not required, i.e., if
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
948 @code{minibuffer-completion-confirm} is @code{nil}. If confirmation
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
949 @emph{is} required, it is given by repeating this command
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
950 immediately---the command is programmed to work without confirmation
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
951 when run twice in succession.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
952 @end deffn
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
953
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
954 @deffn Command minibuffer-completion-help
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
955 This function creates a list of the possible completions of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
956 current minibuffer contents. It works by calling @code{all-completions}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
957 using the value of the variable @code{minibuffer-completion-table} as
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
958 the @var{collection} argument, and the value of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
959 @code{minibuffer-completion-predicate} as the @var{predicate} argument.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
960 The list of completions is displayed as text in a buffer named
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
961 @samp{*Completions*}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
962 @end deffn
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
963
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
964 @defun display-completion-list completions &optional common-substring
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
965 This function displays @var{completions} to the stream in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
966 @code{standard-output}, usually a buffer. (@xref{Read and Print}, for more
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
967 information about streams.) The argument @var{completions} is normally
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
968 a list of completions just returned by @code{all-completions}, but it
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
969 does not have to be. Each element may be a symbol or a string, either
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
970 of which is simply printed. It can also be a list of two strings,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
971 which is printed as if the strings were concatenated. The first of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
972 the two strings is the actual completion, the second string serves as
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
973 annotation.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
974
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
975 The argument @var{common-substring} is the prefix that is common to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
976 all the completions. With normal Emacs completion, it is usually the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
977 same as the string that was completed. @code{display-completion-list}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
978 uses this to highlight text in the completion list for better visual
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
979 feedback. This is not needed in the minibuffer; for minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
980 completion, you can pass @code{nil}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
981
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
982 This function is called by @code{minibuffer-completion-help}. The
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
983 most common way to use it is together with
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
984 @code{with-output-to-temp-buffer}, like this:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
985
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
986 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
987 (with-output-to-temp-buffer "*Completions*"
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
988 (display-completion-list
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
989 (all-completions (buffer-string) my-alist)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
990 (buffer-string)))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
991 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
992 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
993
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
994 @defopt completion-auto-help
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
995 If this variable is non-@code{nil}, the completion commands
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
996 automatically display a list of possible completions whenever nothing
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
997 can be completed because the next character is not uniquely determined.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
998 @end defopt
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
999
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1000 @defvar minibuffer-local-completion-map
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1001 @code{completing-read} uses this value as the local keymap when an
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1002 exact match of one of the completions is not required. By default, this
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1003 keymap makes the following bindings:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1004
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1005 @table @asis
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1006 @item @kbd{?}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1007 @code{minibuffer-completion-help}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1008
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1009 @item @key{SPC}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1010 @code{minibuffer-complete-word}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1011
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1012 @item @key{TAB}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1013 @code{minibuffer-complete}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1014 @end table
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1015
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1016 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1017 with other characters bound as in @code{minibuffer-local-map}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1018 (@pxref{Definition of minibuffer-local-map}).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1019 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1020
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1021 @defvar minibuffer-local-must-match-map
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1022 @code{completing-read} uses this value as the local keymap when an
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1023 exact match of one of the completions is required. Therefore, no keys
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1024 are bound to @code{exit-minibuffer}, the command that exits the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1025 minibuffer unconditionally. By default, this keymap makes the following
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1026 bindings:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1027
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1028 @table @asis
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1029 @item @kbd{?}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1030 @code{minibuffer-completion-help}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1031
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1032 @item @key{SPC}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1033 @code{minibuffer-complete-word}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1034
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1035 @item @key{TAB}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1036 @code{minibuffer-complete}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1037
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1038 @item @kbd{C-j}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1039 @code{minibuffer-complete-and-exit}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1040
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1041 @item @key{RET}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1042 @code{minibuffer-complete-and-exit}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1043 @end table
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1044
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1045 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1046 with other characters bound as in @code{minibuffer-local-map}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1047 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1048
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1049 @defvar minibuffer-local-filename-completion-map
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1050 This is like @code{minibuffer-local-completion-map}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1051 except that it does not bind @key{SPC}. This keymap is used by the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1052 function @code{read-file-name}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1053 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1054
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1055 @defvar minibuffer-local-must-match-filename-map
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1056 This is like @code{minibuffer-local-must-match-map}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1057 except that it does not bind @key{SPC}. This keymap is used by the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1058 function @code{read-file-name}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1059 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1060
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1061 @node High-Level Completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1062 @subsection High-Level Completion Functions
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1063
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1064 This section describes the higher-level convenient functions for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1065 reading certain sorts of names with completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1066
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1067 In most cases, you should not call these functions in the middle of a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1068 Lisp function. When possible, do all minibuffer input as part of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1069 reading the arguments for a command, in the @code{interactive}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1070 specification. @xref{Defining Commands}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1071
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1072 @defun read-buffer prompt &optional default existing
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1073 This function reads the name of a buffer and returns it as a string.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1074 The argument @var{default} is the default name to use, the value to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1075 return if the user exits with an empty minibuffer. If non-@code{nil},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1076 it should be a string or a buffer. It is mentioned in the prompt, but
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1077 is not inserted in the minibuffer as initial input.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1078
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1079 The argument @var{prompt} should be a string ending with a colon and a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1080 space. If @var{default} is non-@code{nil}, the function inserts it in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1081 @var{prompt} before the colon to follow the convention for reading from
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1082 the minibuffer with a default value (@pxref{Programming Tips}).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1083
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1084 If @var{existing} is non-@code{nil}, then the name specified must be
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1085 that of an existing buffer. The usual commands to exit the minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1086 do not exit if the text is not valid, and @key{RET} does completion to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1087 attempt to find a valid name. If @var{existing} is neither @code{nil}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1088 nor @code{t}, confirmation is required after completion. (However,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1089 @var{default} is not checked for validity; it is returned, whatever it
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1090 is, if the user exits with the minibuffer empty.)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1091
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1092 In the following example, the user enters @samp{minibuffer.t}, and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1093 then types @key{RET}. The argument @var{existing} is @code{t}, and the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1094 only buffer name starting with the given input is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1095 @samp{minibuffer.texi}, so that name is the value.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1096
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1097 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1098 (read-buffer "Buffer name: " "foo" t)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1099 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1100 ;; @r{After evaluation of the preceding expression,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1101 ;; @r{the following prompt appears,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1102 ;; @r{with an empty minibuffer:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1103 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1104
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1105 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1106 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1107 Buffer name (default foo): @point{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1108 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1109 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1110
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1111 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1112 ;; @r{The user types @kbd{minibuffer.t @key{RET}}.}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1113 @result{} "minibuffer.texi"
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1114 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1115 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1116 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1117
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1118 @defvar read-buffer-function
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1119 This variable specifies how to read buffer names. For example, if you
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1120 set this variable to @code{iswitchb-read-buffer}, all Emacs commands
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1121 that call @code{read-buffer} to read a buffer name will actually use the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1122 @code{iswitchb} package to read it.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1123 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1124
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1125 @defun read-command prompt &optional default
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1126 This function reads the name of a command and returns it as a Lisp
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1127 symbol. The argument @var{prompt} is used as in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1128 @code{read-from-minibuffer}. Recall that a command is anything for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1129 which @code{commandp} returns @code{t}, and a command name is a symbol
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1130 for which @code{commandp} returns @code{t}. @xref{Interactive Call}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1131
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1132 The argument @var{default} specifies what to return if the user enters
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1133 null input. It can be a symbol or a string; if it is a string,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1134 @code{read-command} interns it before returning it. If @var{default} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1135 @code{nil}, that means no default has been specified; then if the user
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1136 enters null input, the return value is @code{(intern "")}, that is, a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1137 symbol whose name is an empty string.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1138
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1139 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1140 (read-command "Command name? ")
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1141
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1142 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1143 ;; @r{After evaluation of the preceding expression,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1144 ;; @r{the following prompt appears with an empty minibuffer:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1145 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1146
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1147 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1148 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1149 Command name?
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1150 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1151 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1152 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1153
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1154 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1155 If the user types @kbd{forward-c @key{RET}}, then this function returns
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1156 @code{forward-char}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1157
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1158 The @code{read-command} function is a simplified interface to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1159 @code{completing-read}. It uses the variable @code{obarray} so as to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1160 complete in the set of extant Lisp symbols, and it uses the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1161 @code{commandp} predicate so as to accept only command names:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1162
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1163 @cindex @code{commandp} example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1164 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1165 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1166 (read-command @var{prompt})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1167 @equiv{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1168 (intern (completing-read @var{prompt} obarray
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1169 'commandp t nil))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1170 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1171 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1172 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1173
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1174 @defun read-variable prompt &optional default
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1175 @anchor{Definition of read-variable}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1176 This function reads the name of a user variable and returns it as a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1177 symbol.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1178
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1179 The argument @var{default} specifies what to return if the user enters
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1180 null input. It can be a symbol or a string; if it is a string,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1181 @code{read-variable} interns it before returning it. If @var{default}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1182 is @code{nil}, that means no default has been specified; then if the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1183 user enters null input, the return value is @code{(intern "")}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1184
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1185 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1186 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1187 (read-variable "Variable name? ")
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1188
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1189 ;; @r{After evaluation of the preceding expression,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1190 ;; @r{the following prompt appears,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1191 ;; @r{with an empty minibuffer:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1192 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1193
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1194 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1195 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1196 Variable name? @point{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1197 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1198 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1199 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1200
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1201 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1202 If the user then types @kbd{fill-p @key{RET}}, @code{read-variable}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1203 returns @code{fill-prefix}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1204
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1205 In general, @code{read-variable} is similar to @code{read-command},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1206 but uses the predicate @code{user-variable-p} instead of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1207 @code{commandp}:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1208
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1209 @cindex @code{user-variable-p} example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1210 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1211 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1212 (read-variable @var{prompt})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1213 @equiv{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1214 (intern
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1215 (completing-read @var{prompt} obarray
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1216 'user-variable-p t nil))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1217 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1218 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1219 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1220
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1221 See also the functions @code{read-coding-system} and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1222 @code{read-non-nil-coding-system}, in @ref{User-Chosen Coding Systems},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1223 and @code{read-input-method-name}, in @ref{Input Methods}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1224
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1225 @node Reading File Names
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1226 @subsection Reading File Names
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1227 @cindex read file names
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1228 @cindex prompt for file name
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1229
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1230 Here is another high-level completion function, designed for reading a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1231 file name. It provides special features including automatic insertion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1232 of the default directory.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1233
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1234 @defun read-file-name prompt &optional directory default existing initial predicate
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1235 This function reads a file name in the minibuffer, prompting with
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1236 @var{prompt} and providing completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1237
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1238 If @var{existing} is non-@code{nil}, then the user must specify the name
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1239 of an existing file; @key{RET} performs completion to make the name
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1240 valid if possible, and then refuses to exit if it is not valid. If the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1241 value of @var{existing} is neither @code{nil} nor @code{t}, then
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1242 @key{RET} also requires confirmation after completion. If
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1243 @var{existing} is @code{nil}, then the name of a nonexistent file is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1244 acceptable.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1245
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1246 @code{read-file-name} uses
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1247 @code{minibuffer-local-filename-completion-map} as the keymap if
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1248 @var{existing} is @code{nil}, and uses
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1249 @code{minibuffer-local-must-match-filename-map} if @var{existing} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1250 non-@code{nil}. @xref{Completion Commands}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1251
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1252 The argument @var{directory} specifies the directory to use for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1253 completion of relative file names. It should be an absolute directory
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1254 name. If @code{insert-default-directory} is non-@code{nil},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1255 @var{directory} is also inserted in the minibuffer as initial input.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1256 It defaults to the current buffer's value of @code{default-directory}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1257
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1258 @c Emacs 19 feature
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1259 If you specify @var{initial}, that is an initial file name to insert
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1260 in the buffer (after @var{directory}, if that is inserted). In this
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1261 case, point goes at the beginning of @var{initial}. The default for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1262 @var{initial} is @code{nil}---don't insert any file name. To see what
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1263 @var{initial} does, try the command @kbd{C-x C-v}. @strong{Please
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1264 note:} we recommend using @var{default} rather than @var{initial} in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1265 most cases.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1266
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1267 If @var{default} is non-@code{nil}, then the function returns
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1268 @var{default} if the user exits the minibuffer with the same non-empty
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1269 contents that @code{read-file-name} inserted initially. The initial
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1270 minibuffer contents are always non-empty if
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1271 @code{insert-default-directory} is non-@code{nil}, as it is by
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1272 default. @var{default} is not checked for validity, regardless of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1273 value of @var{existing}. However, if @var{existing} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1274 non-@code{nil}, the initial minibuffer contents should be a valid file
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1275 (or directory) name. Otherwise @code{read-file-name} attempts
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1276 completion if the user exits without any editing, and does not return
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1277 @var{default}. @var{default} is also available through the history
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1278 commands.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1279
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1280 If @var{default} is @code{nil}, @code{read-file-name} tries to find a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1281 substitute default to use in its place, which it treats in exactly the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1282 same way as if it had been specified explicitly. If @var{default} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1283 @code{nil}, but @var{initial} is non-@code{nil}, then the default is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1284 the absolute file name obtained from @var{directory} and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1285 @var{initial}. If both @var{default} and @var{initial} are @code{nil}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1286 and the buffer is visiting a file, @code{read-file-name} uses the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1287 absolute file name of that file as default. If the buffer is not
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1288 visiting a file, then there is no default. In that case, if the user
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1289 types @key{RET} without any editing, @code{read-file-name} simply
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1290 returns the pre-inserted contents of the minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1291
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1292 If the user types @key{RET} in an empty minibuffer, this function
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1293 returns an empty string, regardless of the value of @var{existing}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1294 This is, for instance, how the user can make the current buffer visit
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1295 no file using @code{M-x set-visited-file-name}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1296
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1297 If @var{predicate} is non-@code{nil}, it specifies a function of one
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1298 argument that decides which file names are acceptable completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1299 possibilities. A file name is an acceptable value if @var{predicate}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1300 returns non-@code{nil} for it.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1301
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1302 @code{read-file-name} does not automatically expand file names. You
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1303 must call @code{expand-file-name} yourself if an absolute file name is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1304 required.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1305
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1306 Here is an example:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1307
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1308 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1309 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1310 (read-file-name "The file is ")
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1311
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1312 ;; @r{After evaluation of the preceding expression,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1313 ;; @r{the following appears in the minibuffer:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1314 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1315
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1316 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1317 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1318 The file is /gp/gnu/elisp/@point{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1319 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1320 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1321 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1322
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1323 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1324 Typing @kbd{manual @key{TAB}} results in the following:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1325
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1326 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1327 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1328 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1329 The file is /gp/gnu/elisp/manual.texi@point{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1330 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1331 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1332 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1333
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1334 @c Wordy to avoid overfull hbox in smallbook mode.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1335 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1336 If the user types @key{RET}, @code{read-file-name} returns the file name
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1337 as the string @code{"/gp/gnu/elisp/manual.texi"}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1338 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1339
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1340 @defvar read-file-name-function
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1341 If non-@code{nil}, this should be a function that accepts the same
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1342 arguments as @code{read-file-name}. When @code{read-file-name} is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1343 called, it calls this function with the supplied arguments instead of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1344 doing its usual work.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1345 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1346
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1347 @defvar read-file-name-completion-ignore-case
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1348 If this variable is non-@code{nil}, @code{read-file-name} ignores case
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1349 when performing completion.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1350 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1351
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1352 @defun read-directory-name prompt &optional directory default existing initial
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1353 This function is like @code{read-file-name} but allows only directory
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1354 names as completion possibilities.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1355
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1356 If @var{default} is @code{nil} and @var{initial} is non-@code{nil},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1357 @code{read-directory-name} constructs a substitute default by
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1358 combining @var{directory} (or the current buffer's default directory
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1359 if @var{directory} is @code{nil}) and @var{initial}. If both
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1360 @var{default} and @var{initial} are @code{nil}, this function uses
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1361 @var{directory} as substitute default, or the current buffer's default
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1362 directory if @var{directory} is @code{nil}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1363 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1364
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1365 @defopt insert-default-directory
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1366 This variable is used by @code{read-file-name}, and thus, indirectly,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1367 by most commands reading file names. (This includes all commands that
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1368 use the code letters @samp{f} or @samp{F} in their interactive form.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1369 @xref{Interactive Codes,, Code Characters for interactive}.) Its
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1370 value controls whether @code{read-file-name} starts by placing the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1371 name of the default directory in the minibuffer, plus the initial file
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1372 name if any. If the value of this variable is @code{nil}, then
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1373 @code{read-file-name} does not place any initial input in the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1374 minibuffer (unless you specify initial input with the @var{initial}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1375 argument). In that case, the default directory is still used for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1376 completion of relative file names, but is not displayed.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1377
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1378 If this variable is @code{nil} and the initial minibuffer contents are
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1379 empty, the user may have to explicitly fetch the next history element
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1380 to access a default value. If the variable is non-@code{nil}, the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1381 initial minibuffer contents are always non-empty and the user can
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1382 always request a default value by immediately typing @key{RET} in an
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1383 unedited minibuffer. (See above.)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1384
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1385 For example:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1386
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1387 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1388 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1389 ;; @r{Here the minibuffer starts out with the default directory.}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1390 (let ((insert-default-directory t))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1391 (read-file-name "The file is "))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1392 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1393
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1394 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1395 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1396 The file is ~lewis/manual/@point{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1397 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1398 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1399
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1400 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1401 ;; @r{Here the minibuffer is empty and only the prompt}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1402 ;; @r{appears on its line.}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1403 (let ((insert-default-directory nil))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1404 (read-file-name "The file is "))
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1405 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1406
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1407 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1408 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1409 The file is @point{}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1410 ---------- Buffer: Minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1411 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1412 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1413 @end defopt
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1414
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1415 @node Programmed Completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1416 @subsection Programmed Completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1417 @cindex programmed completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1418
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1419 Sometimes it is not possible to create an alist or an obarray
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1420 containing all the intended possible completions. In such a case, you
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1421 can supply your own function to compute the completion of a given string.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1422 This is called @dfn{programmed completion}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1423
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1424 To use this feature, pass a symbol with a function definition as the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1425 @var{collection} argument to @code{completing-read}. The function
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1426 @code{completing-read} arranges to pass your completion function along
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1427 to @code{try-completion} and @code{all-completions}, which will then let
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1428 your function do all the work.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1429
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1430 The completion function should accept three arguments:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1431
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1432 @itemize @bullet
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1433 @item
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1434 The string to be completed.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1435
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1436 @item
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1437 The predicate function to filter possible matches, or @code{nil} if
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1438 none. Your function should call the predicate for each possible match,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1439 and ignore the possible match if the predicate returns @code{nil}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1440
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1441 @item
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1442 A flag specifying the type of operation.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1443 @end itemize
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1444
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1445 There are three flag values for three operations:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1446
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1447 @itemize @bullet
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1448 @item
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1449 @code{nil} specifies @code{try-completion}. The completion function
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1450 should return the completion of the specified string, or @code{t} if the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1451 string is a unique and exact match already, or @code{nil} if the string
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1452 matches no possibility.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1453
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1454 If the string is an exact match for one possibility, but also matches
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1455 other longer possibilities, the function should return the string, not
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1456 @code{t}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1457
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1458 @item
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1459 @code{t} specifies @code{all-completions}. The completion function
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1460 should return a list of all possible completions of the specified
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1461 string.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1462
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1463 @item
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1464 @code{lambda} specifies @code{test-completion}. The completion
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1465 function should return @code{t} if the specified string is an exact
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1466 match for some possibility; @code{nil} otherwise.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1467 @end itemize
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1468
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1469 It would be consistent and clean for completion functions to allow
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1470 lambda expressions (lists that are functions) as well as function
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1471 symbols as @var{collection}, but this is impossible. Lists as
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1472 completion tables already have other meanings, and it would be
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1473 unreliable to treat one differently just because it is also a possible
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1474 function. So you must arrange for any function you wish to use for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1475 completion to be encapsulated in a symbol.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1476
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1477 Emacs uses programmed completion when completing file names.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1478 @xref{File Name Completion}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1479
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1480 @defmac dynamic-completion-table function
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1481 This macro is a convenient way to write a function that can act as
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1482 programmed completion function. The argument @var{function} should be
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1483 a function that takes one argument, a string, and returns an alist of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1484 possible completions of it. You can think of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1485 @code{dynamic-completion-table} as a transducer between that interface
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1486 and the interface for programmed completion functions.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1487 @end defmac
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1488
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1489 @node Yes-or-No Queries
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1490 @section Yes-or-No Queries
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1491 @cindex asking the user questions
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1492 @cindex querying the user
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1493 @cindex yes-or-no questions
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1494
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1495 This section describes functions used to ask the user a yes-or-no
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1496 question. The function @code{y-or-n-p} can be answered with a single
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1497 character; it is useful for questions where an inadvertent wrong answer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1498 will not have serious consequences. @code{yes-or-no-p} is suitable for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1499 more momentous questions, since it requires three or four characters to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1500 answer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1501
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1502 If either of these functions is called in a command that was invoked
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1503 using the mouse---more precisely, if @code{last-nonmenu-event}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1504 (@pxref{Command Loop Info}) is either @code{nil} or a list---then it
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1505 uses a dialog box or pop-up menu to ask the question. Otherwise, it
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1506 uses keyboard input. You can force use of the mouse or use of keyboard
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1507 input by binding @code{last-nonmenu-event} to a suitable value around
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1508 the call.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1509
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1510 Strictly speaking, @code{yes-or-no-p} uses the minibuffer and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1511 @code{y-or-n-p} does not; but it seems best to describe them together.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1512
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1513 @defun y-or-n-p prompt
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1514 This function asks the user a question, expecting input in the echo
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1515 area. It returns @code{t} if the user types @kbd{y}, @code{nil} if the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1516 user types @kbd{n}. This function also accepts @key{SPC} to mean yes
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1517 and @key{DEL} to mean no. It accepts @kbd{C-]} to mean ``quit,'' like
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1518 @kbd{C-g}, because the question might look like a minibuffer and for
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1519 that reason the user might try to use @kbd{C-]} to get out. The answer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1520 is a single character, with no @key{RET} needed to terminate it. Upper
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1521 and lower case are equivalent.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1522
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1523 ``Asking the question'' means printing @var{prompt} in the echo area,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1524 followed by the string @w{@samp{(y or n) }}. If the input is not one of
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1525 the expected answers (@kbd{y}, @kbd{n}, @kbd{@key{SPC}},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1526 @kbd{@key{DEL}}, or something that quits), the function responds
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1527 @samp{Please answer y or n.}, and repeats the request.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1528
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1529 This function does not actually use the minibuffer, since it does not
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1530 allow editing of the answer. It actually uses the echo area (@pxref{The
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1531 Echo Area}), which uses the same screen space as the minibuffer. The
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1532 cursor moves to the echo area while the question is being asked.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1533
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1534 The answers and their meanings, even @samp{y} and @samp{n}, are not
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1535 hardwired. The keymap @code{query-replace-map} specifies them.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1536 @xref{Search and Replace}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1537
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1538 In the following example, the user first types @kbd{q}, which is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1539 invalid. At the next prompt the user types @kbd{y}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1540
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1541 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1542 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1543 (y-or-n-p "Do you need a lift? ")
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1544
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1545 ;; @r{After evaluation of the preceding expression,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1546 ;; @r{the following prompt appears in the echo area:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1547 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1548
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1549 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1550 ---------- Echo area ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1551 Do you need a lift? (y or n)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1552 ---------- Echo area ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1553 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1554
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1555 ;; @r{If the user then types @kbd{q}, the following appears:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1556
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1557 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1558 ---------- Echo area ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1559 Please answer y or n. Do you need a lift? (y or n)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1560 ---------- Echo area ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1561 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1562
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1563 ;; @r{When the user types a valid answer,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1564 ;; @r{it is displayed after the question:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1565
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1566 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1567 ---------- Echo area ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1568 Do you need a lift? (y or n) y
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1569 ---------- Echo area ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1570 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1571 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1572
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1573 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1574 We show successive lines of echo area messages, but only one actually
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1575 appears on the screen at a time.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1576 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1577
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1578 @defun y-or-n-p-with-timeout prompt seconds default-value
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1579 Like @code{y-or-n-p}, except that if the user fails to answer within
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1580 @var{seconds} seconds, this function stops waiting and returns
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1581 @var{default-value}. It works by setting up a timer; see @ref{Timers}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1582 The argument @var{seconds} may be an integer or a floating point number.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1583 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1584
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1585 @defun yes-or-no-p prompt
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1586 This function asks the user a question, expecting input in the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1587 minibuffer. It returns @code{t} if the user enters @samp{yes},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1588 @code{nil} if the user types @samp{no}. The user must type @key{RET} to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1589 finalize the response. Upper and lower case are equivalent.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1590
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1591 @code{yes-or-no-p} starts by displaying @var{prompt} in the echo area,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1592 followed by @w{@samp{(yes or no) }}. The user must type one of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1593 expected responses; otherwise, the function responds @samp{Please answer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1594 yes or no.}, waits about two seconds and repeats the request.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1595
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1596 @code{yes-or-no-p} requires more work from the user than
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1597 @code{y-or-n-p} and is appropriate for more crucial decisions.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1598
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1599 Here is an example:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1600
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1601 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1602 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1603 (yes-or-no-p "Do you really want to remove everything? ")
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1604
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1605 ;; @r{After evaluation of the preceding expression,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1606 ;; @r{the following prompt appears,}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1607 ;; @r{with an empty minibuffer:}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1608 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1609
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1610 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1611 ---------- Buffer: minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1612 Do you really want to remove everything? (yes or no)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1613 ---------- Buffer: minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1614 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1615 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1616
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1617 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1618 If the user first types @kbd{y @key{RET}}, which is invalid because this
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1619 function demands the entire word @samp{yes}, it responds by displaying
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1620 these prompts, with a brief pause between them:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1621
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1622 @smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1623 @group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1624 ---------- Buffer: minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1625 Please answer yes or no.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1626 Do you really want to remove everything? (yes or no)
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1627 ---------- Buffer: minibuffer ----------
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1628 @end group
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1629 @end smallexample
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1630 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1631
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1632 @node Multiple Queries
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1633 @section Asking Multiple Y-or-N Questions
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1634
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1635 When you have a series of similar questions to ask, such as ``Do you
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1636 want to save this buffer'' for each buffer in turn, you should use
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1637 @code{map-y-or-n-p} to ask the collection of questions, rather than
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1638 asking each question individually. This gives the user certain
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1639 convenient facilities such as the ability to answer the whole series at
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1640 once.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1641
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1642 @defun map-y-or-n-p prompter actor list &optional help action-alist no-cursor-in-echo-area
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1643 This function asks the user a series of questions, reading a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1644 single-character answer in the echo area for each one.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1645
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1646 The value of @var{list} specifies the objects to ask questions about.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1647 It should be either a list of objects or a generator function. If it is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1648 a function, it should expect no arguments, and should return either the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1649 next object to ask about, or @code{nil} meaning stop asking questions.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1650
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1651 The argument @var{prompter} specifies how to ask each question. If
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1652 @var{prompter} is a string, the question text is computed like this:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1653
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1654 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1655 (format @var{prompter} @var{object})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1656 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1657
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1658 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1659 where @var{object} is the next object to ask about (as obtained from
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1660 @var{list}).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1661
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1662 If not a string, @var{prompter} should be a function of one argument
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1663 (the next object to ask about) and should return the question text. If
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1664 the value is a string, that is the question to ask the user. The
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1665 function can also return @code{t} meaning do act on this object (and
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1666 don't ask the user), or @code{nil} meaning ignore this object (and don't
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1667 ask the user).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1668
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1669 The argument @var{actor} says how to act on the answers that the user
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1670 gives. It should be a function of one argument, and it is called with
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1671 each object that the user says yes for. Its argument is always an
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1672 object obtained from @var{list}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1673
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1674 If the argument @var{help} is given, it should be a list of this form:
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1675
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1676 @example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1677 (@var{singular} @var{plural} @var{action})
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1678 @end example
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1679
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1680 @noindent
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1681 where @var{singular} is a string containing a singular noun that
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1682 describes the objects conceptually being acted on, @var{plural} is the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1683 corresponding plural noun, and @var{action} is a transitive verb
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1684 describing what @var{actor} does.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1685
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1686 If you don't specify @var{help}, the default is @code{("object"
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1687 "objects" "act on")}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1688
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1689 Each time a question is asked, the user may enter @kbd{y}, @kbd{Y}, or
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1690 @key{SPC} to act on that object; @kbd{n}, @kbd{N}, or @key{DEL} to skip
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1691 that object; @kbd{!} to act on all following objects; @key{ESC} or
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1692 @kbd{q} to exit (skip all following objects); @kbd{.} (period) to act on
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1693 the current object and then exit; or @kbd{C-h} to get help. These are
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1694 the same answers that @code{query-replace} accepts. The keymap
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1695 @code{query-replace-map} defines their meaning for @code{map-y-or-n-p}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1696 as well as for @code{query-replace}; see @ref{Search and Replace}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1697
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1698 You can use @var{action-alist} to specify additional possible answers
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1699 and what they mean. It is an alist of elements of the form
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1700 @code{(@var{char} @var{function} @var{help})}, each of which defines one
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1701 additional answer. In this element, @var{char} is a character (the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1702 answer); @var{function} is a function of one argument (an object from
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1703 @var{list}); @var{help} is a string.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1704
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1705 When the user responds with @var{char}, @code{map-y-or-n-p} calls
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1706 @var{function}. If it returns non-@code{nil}, the object is considered
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1707 ``acted upon,'' and @code{map-y-or-n-p} advances to the next object in
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1708 @var{list}. If it returns @code{nil}, the prompt is repeated for the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1709 same object.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1710
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1711 Normally, @code{map-y-or-n-p} binds @code{cursor-in-echo-area} while
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1712 prompting. But if @var{no-cursor-in-echo-area} is non-@code{nil}, it
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1713 does not do that.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1714
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1715 If @code{map-y-or-n-p} is called in a command that was invoked using the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1716 mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1717 Loop Info}) is either @code{nil} or a list---then it uses a dialog box
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1718 or pop-up menu to ask the question. In this case, it does not use
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1719 keyboard input or the echo area. You can force use of the mouse or use
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1720 of keyboard input by binding @code{last-nonmenu-event} to a suitable
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1721 value around the call.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1722
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1723 The return value of @code{map-y-or-n-p} is the number of objects acted on.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1724 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1725
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1726 @node Reading a Password
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1727 @section Reading a Password
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1728 @cindex passwords, reading
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1729
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1730 To read a password to pass to another program, you can use the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1731 function @code{read-passwd}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1732
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1733 @defun read-passwd prompt &optional confirm default
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1734 This function reads a password, prompting with @var{prompt}. It does
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1735 not echo the password as the user types it; instead, it echoes @samp{.}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1736 for each character in the password.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1737
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1738 The optional argument @var{confirm}, if non-@code{nil}, says to read the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1739 password twice and insist it must be the same both times. If it isn't
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1740 the same, the user has to type it over and over until the last two
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1741 times match.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1742
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1743 The optional argument @var{default} specifies the default password to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1744 return if the user enters empty input. If @var{default} is @code{nil},
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1745 then @code{read-passwd} returns the null string in that case.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1746 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1747
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1748 @node Minibuffer Commands
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1749 @section Minibuffer Commands
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1750
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1751 This section describes some commands meant for use in the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1752 minibuffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1753
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1754 @deffn Command exit-minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1755 This command exits the active minibuffer. It is normally bound to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1756 keys in minibuffer local keymaps.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1757 @end deffn
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1758
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1759 @deffn Command self-insert-and-exit
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1760 This command exits the active minibuffer after inserting the last
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1761 character typed on the keyboard (found in @code{last-command-char};
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1762 @pxref{Command Loop Info}).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1763 @end deffn
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1764
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1765 @deffn Command previous-history-element n
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1766 This command replaces the minibuffer contents with the value of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1767 @var{n}th previous (older) history element.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1768 @end deffn
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1769
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1770 @deffn Command next-history-element n
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1771 This command replaces the minibuffer contents with the value of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1772 @var{n}th more recent history element.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1773 @end deffn
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1774
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1775 @deffn Command previous-matching-history-element pattern n
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1776 This command replaces the minibuffer contents with the value of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1777 @var{n}th previous (older) history element that matches @var{pattern} (a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1778 regular expression).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1779 @end deffn
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1780
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1781 @deffn Command next-matching-history-element pattern n
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1782 This command replaces the minibuffer contents with the value of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1783 @var{n}th next (newer) history element that matches @var{pattern} (a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1784 regular expression).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1785 @end deffn
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1786
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1787 @node Minibuffer Windows
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1788 @section Minibuffer Windows
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1789 @cindex minibuffer windows
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1790
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1791 These functions access and select minibuffer windows
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1792 and test whether they are active.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1793
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1794 @defun active-minibuffer-window
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1795 This function returns the currently active minibuffer window, or
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1796 @code{nil} if none is currently active.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1797 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1798
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1799 @defun minibuffer-window &optional frame
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1800 @anchor{Definition of minibuffer-window}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1801 This function returns the minibuffer window used for frame @var{frame}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1802 If @var{frame} is @code{nil}, that stands for the current frame. Note
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1803 that the minibuffer window used by a frame need not be part of that
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1804 frame---a frame that has no minibuffer of its own necessarily uses some
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1805 other frame's minibuffer window.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1806 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1807
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1808 @defun set-minibuffer-window window
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1809 This function specifies @var{window} as the minibuffer window to use.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1810 This affects where the minibuffer is displayed if you put text in it
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1811 without invoking the usual minibuffer commands. It has no effect on
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1812 the usual minibuffer input functions because they all start by
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1813 choosing the minibuffer window according to the current frame.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1814 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1815
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1816 @c Emacs 19 feature
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1817 @defun window-minibuffer-p &optional window
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1818 This function returns non-@code{nil} if @var{window} is a minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1819 window.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1820 @var{window} defaults to the selected window.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1821 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1822
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1823 It is not correct to determine whether a given window is a minibuffer by
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1824 comparing it with the result of @code{(minibuffer-window)}, because
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1825 there can be more than one minibuffer window if there is more than one
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1826 frame.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1827
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1828 @defun minibuffer-window-active-p window
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1829 This function returns non-@code{nil} if @var{window}, assumed to be
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1830 a minibuffer window, is currently active.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1831 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1832
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1833 @node Minibuffer Contents
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1834 @section Minibuffer Contents
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1835
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1836 These functions access the minibuffer prompt and contents.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1837
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1838 @defun minibuffer-prompt
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1839 This function returns the prompt string of the currently active
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1840 minibuffer. If no minibuffer is active, it returns @code{nil}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1841 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1842
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1843 @defun minibuffer-prompt-end
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1844 This function returns the current
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1845 position of the end of the minibuffer prompt, if a minibuffer is
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1846 current. Otherwise, it returns the minimum valid buffer position.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1847 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1848
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1849 @defun minibuffer-prompt-width
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1850 This function returns the current display-width of the minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1851 prompt, if a minibuffer is current. Otherwise, it returns zero.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1852 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1853
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1854 @defun minibuffer-contents
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1855 This function returns the editable
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1856 contents of the minibuffer (that is, everything except the prompt) as
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1857 a string, if a minibuffer is current. Otherwise, it returns the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1858 entire contents of the current buffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1859 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1860
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1861 @defun minibuffer-contents-no-properties
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1862 This is like @code{minibuffer-contents}, except that it does not copy text
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1863 properties, just the characters themselves. @xref{Text Properties}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1864 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1865
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1866 @defun minibuffer-completion-contents
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1867 This is like @code{minibuffer-contents}, except that it returns only
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1868 the contents before point. That is the part that completion commands
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1869 operate on. @xref{Minibuffer Completion}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1870 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1871
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1872 @defun delete-minibuffer-contents
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1873 This function erases the editable contents of the minibuffer (that is,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1874 everything except the prompt), if a minibuffer is current. Otherwise,
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1875 it erases the entire current buffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1876 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1877
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1878 @node Recursive Mini
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1879 @section Recursive Minibuffers
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1880 @cindex recursive minibuffers
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1881
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1882 These functions and variables deal with recursive minibuffers
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1883 (@pxref{Recursive Editing}):
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1884
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1885 @defun minibuffer-depth
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1886 This function returns the current depth of activations of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1887 minibuffer, a nonnegative integer. If no minibuffers are active, it
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1888 returns zero.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1889 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1890
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1891 @defopt enable-recursive-minibuffers
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1892 If this variable is non-@code{nil}, you can invoke commands (such as
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1893 @code{find-file}) that use minibuffers even while the minibuffer window
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1894 is active. Such invocation produces a recursive editing level for a new
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1895 minibuffer. The outer-level minibuffer is invisible while you are
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1896 editing the inner one.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1897
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1898 If this variable is @code{nil}, you cannot invoke minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1899 commands when the minibuffer window is active, not even if you switch to
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1900 another window to do it.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1901 @end defopt
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1902
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1903 @c Emacs 19 feature
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1904 If a command name has a property @code{enable-recursive-minibuffers}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1905 that is non-@code{nil}, then the command can use the minibuffer to read
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1906 arguments even if it is invoked from the minibuffer. A command can
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1907 also achieve this by binding @code{enable-recursive-minibuffers}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1908 to @code{t} in the interactive declaration (@pxref{Using Interactive}).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1909 The minibuffer command @code{next-matching-history-element} (normally
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1910 @kbd{M-s} in the minibuffer) does the latter.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1911
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1912 @node Minibuffer Misc
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1913 @section Minibuffer Miscellany
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1914
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1915 @defun minibufferp &optional buffer-or-name
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1916 This function returns non-@code{nil} if @var{buffer-or-name} is a
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1917 minibuffer. If @var{buffer-or-name} is omitted, it tests the current
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1918 buffer.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1919 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1920
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1921 @defvar minibuffer-setup-hook
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1922 This is a normal hook that is run whenever the minibuffer is entered.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1923 @xref{Hooks}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1924 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1925
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1926 @defvar minibuffer-exit-hook
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1927 This is a normal hook that is run whenever the minibuffer is exited.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1928 @xref{Hooks}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1929 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1930
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1931 @defvar minibuffer-help-form
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1932 @anchor{Definition of minibuffer-help-form}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1933 The current value of this variable is used to rebind @code{help-form}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1934 locally inside the minibuffer (@pxref{Help Functions}).
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1935 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1936
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1937 @defvar minibuffer-scroll-window
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1938 @anchor{Definition of minibuffer-scroll-window}
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1939 If the value of this variable is non-@code{nil}, it should be a window
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1940 object. When the function @code{scroll-other-window} is called in the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1941 minibuffer, it scrolls this window.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1942 @end defvar
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1943
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1944 @defun minibuffer-selected-window
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1945 This function returns the window which was selected when the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1946 minibuffer was entered. If selected window is not a minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1947 window, it returns @code{nil}.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1948 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1949
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1950 @defopt max-mini-window-height
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1951 This variable specifies the maximum height for resizing minibuffer
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1952 windows. If a float, it specifies a fraction of the height of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1953 frame. If an integer, it specifies a number of lines.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1954 @end defopt
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1955
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1956 @defun minibuffer-message string
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1957 This function displays @var{string} temporarily at the end of the
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1958 minibuffer text, for two seconds, or until the next input event
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1959 arrives, whichever comes first.
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1960 @end defun
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1961
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1962 @ignore
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1963 arch-tag: bba7f945-9078-477f-a2ce-18818a6e1218
aa6ce8057bdb Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1964 @end ignore