Mercurial > emacs
annotate lispref/minibuf.texi @ 27055:f43dabd831f2
Support :data for JPEG.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Fri, 31 Dec 1999 15:04:57 +0000 |
parents | ef5e7bbe6f19 |
children | 4b1a67a46d8c |
rev | line source |
---|---|
6555 | 1 @c -*-texinfo-*- |
2 @c This is part of the GNU Emacs Lisp Reference Manual. | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. |
6555 | 4 @c See the file elisp.texi for copying conditions. |
5 @setfilename ../info/minibuf | |
7337
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
6 @node Minibuffers, Command Loop, Read and Print, Top |
6555 | 7 @chapter Minibuffers |
8 @cindex arguments, reading | |
9 @cindex complex arguments | |
10 @cindex minibuffer | |
11 | |
12 A @dfn{minibuffer} is a special buffer that Emacs commands use to read | |
13 arguments more complicated than the single numeric prefix argument. | |
14 These arguments include file names, buffer names, and command names (as | |
15 in @kbd{M-x}). The minibuffer is displayed on the bottom line of the | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
16 frame, in the same place as the echo area, but only while it is in use |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
17 for reading an argument. |
6555 | 18 |
19 @menu | |
20 * Intro to Minibuffers:: Basic information about minibuffers. | |
21 * Text from Minibuffer:: How to read a straight text string. | |
22 * Object from Minibuffer:: How to read a Lisp object or expression. | |
23 * Minibuffer History:: Recording previous minibuffer inputs | |
24 so the user can reuse them. | |
25 * Completion:: How to invoke and customize completion. | |
26 * Yes-or-No Queries:: Asking a question with a simple answer. | |
27 * Multiple Queries:: Asking a series of similar questions. | |
23147 | 28 * Reading a Password:: Reading a password from the terminal. |
6555 | 29 * Minibuffer Misc:: Various customization hooks and variables. |
30 @end menu | |
31 | |
32 @node Intro to Minibuffers | |
33 @section Introduction to Minibuffers | |
34 | |
35 In most ways, a minibuffer is a normal Emacs buffer. Most operations | |
36 @emph{within} a buffer, such as editing commands, work normally in a | |
37 minibuffer. However, many operations for managing buffers do not apply | |
38 to minibuffers. The name of a minibuffer always has the form @w{@samp{ | |
39 *Minibuf-@var{number}}}, and it cannot be changed. Minibuffers are | |
40 displayed only in special windows used only for minibuffers; these | |
22252
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
41 windows always appear at the bottom of a frame. (Sometimes frames have |
6555 | 42 no minibuffer window, and sometimes a special kind of frame contains |
43 nothing but a minibuffer window; see @ref{Minibuffers and Frames}.) | |
44 | |
25751
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
45 The text in the minibuffer always starts with the @dfn{prompt string}, |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
46 the text that was specified by the program that is using the minibuffer |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
47 to tell the user what sort of input to type. This text is marked |
26696
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
48 read-only so you won't accidentally delete or change it. It is also |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
49 marked as a field (@pxref{Fields}), so that certain motion functions, |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
50 including @code{beginning-of-line}, @code{forward-word}, |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
51 @code{forward-sentence}, and @code{forward-paragraph}, stop at the |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
52 boundary between the prompt and the actual text. (In older Emacs |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
53 versions, the prompt was displayed using a special mechanism and was not |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
54 part of the buffer contents.) |
25751
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
55 |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
56 The minibuffer's window is normally a single line; it grows |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
57 automatically if necessary if the contents require more space. You can |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
58 explicitly resize it temporarily with the window sizing commands; it |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
59 reverts to its normal size when the minibuffer is exited. You can |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
60 resize it permanently by using the window sizing commands in the frame's |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
61 other window, when the minibuffer is not active. If the frame contains |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
62 just a minibuffer, you can change the minibuffer's size by changing the |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
63 frame's size. |
6555 | 64 |
65 If a command uses a minibuffer while there is an active minibuffer, | |
66 this is called a @dfn{recursive minibuffer}. The first minibuffer is | |
67 named @w{@samp{ *Minibuf-0*}}. Recursive minibuffers are named by | |
68 incrementing the number at the end of the name. (The names begin with a | |
69 space so that they won't show up in normal buffer lists.) Of several | |
70 recursive minibuffers, the innermost (or most recently entered) is the | |
71 active minibuffer. We usually call this ``the'' minibuffer. You can | |
72 permit or forbid recursive minibuffers by setting the variable | |
73 @code{enable-recursive-minibuffers} or by putting properties of that | |
74 name on command symbols (@pxref{Minibuffer Misc}). | |
75 | |
76 Like other buffers, a minibuffer may use any of several local keymaps | |
77 (@pxref{Keymaps}); these contain various exit commands and in some cases | |
12098 | 78 completion commands (@pxref{Completion}). |
6555 | 79 |
80 @itemize @bullet | |
81 @item | |
82 @code{minibuffer-local-map} is for ordinary input (no completion). | |
83 | |
84 @item | |
85 @code{minibuffer-local-ns-map} is similar, except that @key{SPC} exits | |
86 just like @key{RET}. This is used mainly for Mocklisp compatibility. | |
87 | |
88 @item | |
89 @code{minibuffer-local-completion-map} is for permissive completion. | |
90 | |
91 @item | |
92 @code{minibuffer-local-must-match-map} is for strict completion and | |
93 for cautious completion. | |
94 @end itemize | |
95 | |
26696
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
96 When Emacs is running in batch mode, any request to read from the |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
97 minibuffer actually reads a line from the standard input descriptor that |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
98 was supplied when Emacs was started. |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
99 |
6555 | 100 @node Text from Minibuffer |
101 @section Reading Text Strings with the Minibuffer | |
102 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
103 Most often, the minibuffer is used to read text as a string. It can |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
104 also be used to read a Lisp object in textual form. The most basic |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
105 primitive for minibuffer input is @code{read-from-minibuffer}; it can do |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
106 either one. |
6555 | 107 |
12098 | 108 In most cases, you should not call minibuffer input functions in the |
109 middle of a Lisp function. Instead, do all minibuffer input as part of | |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
110 reading the arguments for a command, in the @code{interactive} |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
111 specification. @xref{Defining Commands}. |
12098 | 112 |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
113 @defun read-from-minibuffer prompt-string &optional initial-contents keymap read hist default inherit-input-method |
6555 | 114 This function is the most general way to get input through the |
115 minibuffer. By default, it accepts arbitrary text and returns it as a | |
116 string; however, if @var{read} is non-@code{nil}, then it uses | |
117 @code{read} to convert the text into a Lisp object (@pxref{Input | |
118 Functions}). | |
119 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
120 The first thing this function does is to activate a minibuffer and |
6555 | 121 display it with @var{prompt-string} as the prompt. This value must be a |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
122 string. Then the user can edit text in the minibuffer. |
6555 | 123 |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
124 When the user types a command to exit the minibuffer, |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
125 @code{read-from-minibuffer} constructs the return value from the text in |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
126 the minibuffer. Normally it returns a string containing that text. |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
127 However, if @var{read} is non-@code{nil}, @code{read-from-minibuffer} |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
128 reads the text and returns the resulting Lisp object, unevaluated. |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
129 (@xref{Input Functions}, for information about reading.) |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
130 |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
131 The argument @var{default} specifies a default value to make available |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
132 through the history commands. It should be a string, or @code{nil}. If |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
133 @var{read} is non-@code{nil}, then @var{default} is also used as the |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
134 input to @code{read}, if the user enters empty input. However, in the |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
135 usual case (where @var{read} is @code{nil}), @code{read-from-minibuffer} |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
136 does not return @var{default} when the user enters empty input; it |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
137 returns an empty string, @code{""}. In this respect, it is different |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
138 from all the other minibuffer input functions in this chapter. |
6555 | 139 |
140 If @var{keymap} is non-@code{nil}, that keymap is the local keymap to | |
141 use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the | |
142 value of @code{minibuffer-local-map} is used as the keymap. Specifying | |
143 a keymap is the most important way to customize the minibuffer for | |
144 various applications such as completion. | |
145 | |
146 The argument @var{hist} specifies which history list variable to use | |
147 for saving the input and for history commands used in the minibuffer. | |
148 It defaults to @code{minibuffer-history}. @xref{Minibuffer History}. | |
149 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
150 If the variable @code{minibuffer-allow-text-properties} is |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
151 non-@code{nil}, then the string which is returned includes whatever text |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
152 properties were present in the minibuffer. Otherwise all the text |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
153 properties are stripped when the value is returned. |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
154 |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
155 If the argument @var{inherit-input-method} is non-@code{nil}, then the |
22252
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
156 minibuffer inherits the current input method (@pxref{Input Methods}) and |
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
157 the setting of @code{enable-multibyte-characters} (@pxref{Text |
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
158 Representations}) from whichever buffer was current before entering the |
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
159 minibuffer. |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
160 |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
161 If @var{initial-contents} is a string, @code{read-from-minibuffer} |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
162 inserts it into the minibuffer, leaving point at the end, before the |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
163 user starts to edit the text. The minibuffer appears with this text as |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
164 its initial contents. |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
165 |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
166 Alternatively, @var{initial-contents} can be a cons cell of the form |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
167 @code{(@var{string} . @var{position})}. This means to insert |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
168 @var{string} in the minibuffer but put point @var{position} characters |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
169 from the beginning, rather than at the end. |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
170 |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
171 @strong{Usage note:} The @var{initial-contents} argument and the |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
172 @var{default} argument are two alternative features for more or less the |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
173 same job. It does not make sense to use both features in a single call |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
174 to @code{read-from-minibuffer}. In general, we recommend using |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
175 @var{default}, since this permits the user to insert the default value |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
176 when it is wanted, but does not burden the user with deleting it from |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
177 the minibuffer on other occasions. |
6555 | 178 @end defun |
179 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
180 @defun read-string prompt &optional initial history default inherit-input-method |
6555 | 181 This function reads a string from the minibuffer and returns it. The |
182 arguments @var{prompt} and @var{initial} are used as in | |
183 @code{read-from-minibuffer}. The keymap used is | |
184 @code{minibuffer-local-map}. | |
185 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
186 The optional argument @var{history}, if non-nil, specifies a history |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
187 list and optionally the initial position in the list. The optional |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
188 argument @var{default} specifies a default value to return if the user |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
189 enters null input; it should be a string. The optional argument |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
190 @var{inherit-input-method} specifies whether to inherit the current |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
191 buffer's input method. |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
192 |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
193 This function is a simplified interface to the |
6555 | 194 @code{read-from-minibuffer} function: |
195 | |
196 @smallexample | |
197 @group | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
198 (read-string @var{prompt} @var{initial} @var{history} @var{default} @var{inherit}) |
6555 | 199 @equiv{} |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
200 (let ((value |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
201 (read-from-minibuffer @var{prompt} @var{initial} nil nil |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
202 @var{history} @var{default} @var{inherit}))) |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
203 (if (equal value "") |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
204 @var{default} |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
205 value)) |
6555 | 206 @end group |
207 @end smallexample | |
208 @end defun | |
209 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
210 @defvar minibuffer-allow-text-properties |
22252
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
211 If this variable is @code{nil}, then @code{read-from-minibuffer} strips |
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
212 all text properties from the minibuffer input before returning it. |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
213 Since all minibuffer input uses @code{read-from-minibuffer}, this |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
214 variable applies to all minibuffer input. |
22252
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
215 |
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
216 Note that the completion functions discard text properties unconditionally, |
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
217 regardless of the value of this variable. |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
218 @end defvar |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
219 |
6555 | 220 @defvar minibuffer-local-map |
221 This is the default local keymap for reading from the minibuffer. By | |
222 default, it makes the following bindings: | |
223 | |
224 @table @asis | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
225 @item @kbd{C-j} |
6555 | 226 @code{exit-minibuffer} |
227 | |
228 @item @key{RET} | |
229 @code{exit-minibuffer} | |
230 | |
231 @item @kbd{C-g} | |
232 @code{abort-recursive-edit} | |
233 | |
234 @item @kbd{M-n} | |
235 @code{next-history-element} | |
236 | |
237 @item @kbd{M-p} | |
238 @code{previous-history-element} | |
239 | |
240 @item @kbd{M-r} | |
241 @code{next-matching-history-element} | |
242 | |
243 @item @kbd{M-s} | |
244 @code{previous-matching-history-element} | |
245 @end table | |
246 @end defvar | |
247 | |
248 @c In version 18, initial is required | |
249 @c Emacs 19 feature | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
250 @defun read-no-blanks-input prompt &optional initial inherit-input-method |
6555 | 251 This function reads a string from the minibuffer, but does not allow |
252 whitespace characters as part of the input: instead, those characters | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
253 terminate the input. The arguments @var{prompt}, @var{initial}, and |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
254 @var{inherit-input-method} are used as in @code{read-from-minibuffer}. |
6555 | 255 |
256 This is a simplified interface to the @code{read-from-minibuffer} | |
257 function, and passes the value of the @code{minibuffer-local-ns-map} | |
258 keymap as the @var{keymap} argument for that function. Since the keymap | |
259 @code{minibuffer-local-ns-map} does not rebind @kbd{C-q}, it @emph{is} | |
260 possible to put a space into the string, by quoting it. | |
261 | |
262 @smallexample | |
263 @group | |
264 (read-no-blanks-input @var{prompt} @var{initial}) | |
265 @equiv{} | |
266 (read-from-minibuffer @var{prompt} @var{initial} minibuffer-local-ns-map) | |
267 @end group | |
268 @end smallexample | |
269 @end defun | |
270 | |
271 @defvar minibuffer-local-ns-map | |
272 This built-in variable is the keymap used as the minibuffer local keymap | |
273 in the function @code{read-no-blanks-input}. By default, it makes the | |
12098 | 274 following bindings, in addition to those of @code{minibuffer-local-map}: |
6555 | 275 |
276 @table @asis | |
277 @item @key{SPC} | |
278 @cindex @key{SPC} in minibuffer | |
279 @code{exit-minibuffer} | |
280 | |
281 @item @key{TAB} | |
282 @cindex @key{TAB} in minibuffer | |
283 @code{exit-minibuffer} | |
284 | |
285 @item @kbd{?} | |
286 @cindex @kbd{?} in minibuffer | |
287 @code{self-insert-and-exit} | |
288 @end table | |
289 @end defvar | |
290 | |
291 @node Object from Minibuffer | |
292 @section Reading Lisp Objects with the Minibuffer | |
293 | |
294 This section describes functions for reading Lisp objects with the | |
295 minibuffer. | |
296 | |
297 @defun read-minibuffer prompt &optional initial | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
298 This function reads a Lisp object using the minibuffer, and returns it |
6555 | 299 without evaluating it. The arguments @var{prompt} and @var{initial} are |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
300 used as in @code{read-from-minibuffer}. |
6555 | 301 |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
302 This is a simplified interface to the |
6555 | 303 @code{read-from-minibuffer} function: |
304 | |
305 @smallexample | |
306 @group | |
307 (read-minibuffer @var{prompt} @var{initial}) | |
308 @equiv{} | |
309 (read-from-minibuffer @var{prompt} @var{initial} nil t) | |
310 @end group | |
311 @end smallexample | |
312 | |
313 Here is an example in which we supply the string @code{"(testing)"} as | |
314 initial input: | |
315 | |
316 @smallexample | |
317 @group | |
318 (read-minibuffer | |
319 "Enter an expression: " (format "%s" '(testing))) | |
320 | |
321 ;; @r{Here is how the minibuffer is displayed:} | |
322 @end group | |
323 | |
324 @group | |
325 ---------- Buffer: Minibuffer ---------- | |
326 Enter an expression: (testing)@point{} | |
327 ---------- Buffer: Minibuffer ---------- | |
328 @end group | |
329 @end smallexample | |
330 | |
331 @noindent | |
332 The user can type @key{RET} immediately to use the initial input as a | |
333 default, or can edit the input. | |
334 @end defun | |
335 | |
336 @defun eval-minibuffer prompt &optional initial | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
337 This function reads a Lisp expression using the minibuffer, evaluates |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
338 it, then returns the result. The arguments @var{prompt} and |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
339 @var{initial} are used as in @code{read-from-minibuffer}. |
6555 | 340 |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
341 This function simply evaluates the result of a call to |
6555 | 342 @code{read-minibuffer}: |
343 | |
344 @smallexample | |
345 @group | |
346 (eval-minibuffer @var{prompt} @var{initial}) | |
347 @equiv{} | |
348 (eval (read-minibuffer @var{prompt} @var{initial})) | |
349 @end group | |
350 @end smallexample | |
351 @end defun | |
352 | |
353 @defun edit-and-eval-command prompt form | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
354 This function reads a Lisp expression in the minibuffer, and then |
6555 | 355 evaluates it. The difference between this command and |
356 @code{eval-minibuffer} is that here the initial @var{form} is not | |
357 optional and it is treated as a Lisp object to be converted to printed | |
358 representation rather than as a string of text. It is printed with | |
359 @code{prin1}, so if it is a string, double-quote characters (@samp{"}) | |
360 appear in the initial text. @xref{Output Functions}. | |
361 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
362 The first thing @code{edit-and-eval-command} does is to activate the |
6555 | 363 minibuffer with @var{prompt} as the prompt. Then it inserts the printed |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
364 representation of @var{form} in the minibuffer, and lets the user edit it. |
6555 | 365 When the user exits the minibuffer, the edited text is read with |
366 @code{read} and then evaluated. The resulting value becomes the value | |
367 of @code{edit-and-eval-command}. | |
368 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
369 In the following example, we offer the user an expression with initial |
6555 | 370 text which is a valid form already: |
371 | |
372 @smallexample | |
373 @group | |
374 (edit-and-eval-command "Please edit: " '(forward-word 1)) | |
375 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
376 ;; @r{After evaluation of the preceding expression,} |
6555 | 377 ;; @r{the following appears in the minibuffer:} |
378 @end group | |
379 | |
380 @group | |
381 ---------- Buffer: Minibuffer ---------- | |
382 Please edit: (forward-word 1)@point{} | |
383 ---------- Buffer: Minibuffer ---------- | |
384 @end group | |
385 @end smallexample | |
386 | |
387 @noindent | |
388 Typing @key{RET} right away would exit the minibuffer and evaluate the | |
389 expression, thus moving point forward one word. | |
390 @code{edit-and-eval-command} returns @code{nil} in this example. | |
391 @end defun | |
392 | |
393 @node Minibuffer History | |
394 @section Minibuffer History | |
395 @cindex minibuffer history | |
396 @cindex history list | |
397 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
398 A @dfn{minibuffer history list} records previous minibuffer inputs so |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
399 the user can reuse them conveniently. A history list is actually a |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
400 symbol, not a list; it is a variable whose value is a list of strings |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
401 (previous inputs), most recent first. |
6555 | 402 |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
403 There are many separate history lists, used for different kinds of |
6555 | 404 inputs. It's the Lisp programmer's job to specify the right history |
405 list for each use of the minibuffer. | |
406 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
407 The basic minibuffer input functions @code{read-from-minibuffer} and |
6555 | 408 @code{completing-read} both accept an optional argument named @var{hist} |
409 which is how you specify the history list. Here are the possible | |
410 values: | |
411 | |
412 @table @asis | |
413 @item @var{variable} | |
414 Use @var{variable} (a symbol) as the history list. | |
415 | |
416 @item (@var{variable} . @var{startpos}) | |
417 Use @var{variable} (a symbol) as the history list, and assume that the | |
418 initial history position is @var{startpos} (an integer, counting from | |
419 zero which specifies the most recent element of the history). | |
420 | |
421 If you specify @var{startpos}, then you should also specify that element | |
422 of the history as the initial minibuffer contents, for consistency. | |
423 @end table | |
424 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
425 If you don't specify @var{hist}, then the default history list |
6555 | 426 @code{minibuffer-history} is used. For other standard history lists, |
427 see below. You can also create your own history list variable; just | |
428 initialize it to @code{nil} before the first use. | |
429 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
430 Both @code{read-from-minibuffer} and @code{completing-read} add new |
6555 | 431 elements to the history list automatically, and provide commands to |
432 allow the user to reuse items on the list. The only thing your program | |
433 needs to do to use a history list is to initialize it and to pass its | |
434 name to the input functions when you wish. But it is safe to modify the | |
435 list by hand when the minibuffer input functions are not using it. | |
436 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
437 Here are some of the standard minibuffer history list variables: |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
438 |
6555 | 439 @defvar minibuffer-history |
440 The default history list for minibuffer history input. | |
441 @end defvar | |
442 | |
443 @defvar query-replace-history | |
444 A history list for arguments to @code{query-replace} (and similar | |
445 arguments to other commands). | |
446 @end defvar | |
447 | |
448 @defvar file-name-history | |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
449 A history list for file-name arguments. |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
450 @end defvar |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
451 |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
452 @defvar buffer-name-history |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
453 @tindex buffer-name-history |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
454 A history list for buffer-name arguments. |
6555 | 455 @end defvar |
456 | |
457 @defvar regexp-history | |
458 A history list for regular expression arguments. | |
459 @end defvar | |
460 | |
461 @defvar extended-command-history | |
462 A history list for arguments that are names of extended commands. | |
463 @end defvar | |
464 | |
465 @defvar shell-command-history | |
466 A history list for arguments that are shell commands. | |
467 @end defvar | |
468 | |
469 @defvar read-expression-history | |
470 A history list for arguments that are Lisp expressions to evaluate. | |
471 @end defvar | |
472 | |
473 @node Completion | |
474 @section Completion | |
475 @cindex completion | |
476 | |
477 @dfn{Completion} is a feature that fills in the rest of a name | |
478 starting from an abbreviation for it. Completion works by comparing the | |
479 user's input against a list of valid names and determining how much of | |
480 the name is determined uniquely by what the user has typed. For | |
481 example, when you type @kbd{C-x b} (@code{switch-to-buffer}) and then | |
482 type the first few letters of the name of the buffer to which you wish | |
483 to switch, and then type @key{TAB} (@code{minibuffer-complete}), Emacs | |
484 extends the name as far as it can. | |
485 | |
486 Standard Emacs commands offer completion for names of symbols, files, | |
487 buffers, and processes; with the functions in this section, you can | |
488 implement completion for other kinds of names. | |
489 | |
490 The @code{try-completion} function is the basic primitive for | |
491 completion: it returns the longest determined completion of a given | |
492 initial string, with a given set of strings to match against. | |
493 | |
494 The function @code{completing-read} provides a higher-level interface | |
495 for completion. A call to @code{completing-read} specifies how to | |
496 determine the list of valid names. The function then activates the | |
497 minibuffer with a local keymap that binds a few keys to commands useful | |
498 for completion. Other functions provide convenient simple interfaces | |
499 for reading certain kinds of names with completion. | |
500 | |
501 @menu | |
502 * Basic Completion:: Low-level functions for completing strings. | |
503 (These are too low level to use the minibuffer.) | |
504 * Minibuffer Completion:: Invoking the minibuffer with completion. | |
505 * Completion Commands:: Minibuffer commands that do completion. | |
506 * High-Level Completion:: Convenient special cases of completion | |
507 (reading buffer name, file name, etc.) | |
508 * Reading File Names:: Using completion to read file names. | |
509 * Programmed Completion:: Finding the completions for a given file name. | |
510 @end menu | |
511 | |
512 @node Basic Completion | |
513 @subsection Basic Completion Functions | |
514 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
515 The two functions @code{try-completion} and @code{all-completions} |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
516 have nothing in themselves to do with minibuffers. We describe them in |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
517 this chapter so as to keep them near the higher-level completion |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
518 features that do use the minibuffer. |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
519 |
6555 | 520 @defun try-completion string collection &optional predicate |
521 This function returns the longest common substring of all possible | |
522 completions of @var{string} in @var{collection}. The value of | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
523 @var{collection} must be an alist, an obarray, or a function that |
6555 | 524 implements a virtual set of strings (see below). |
525 | |
526 Completion compares @var{string} against each of the permissible | |
527 completions specified by @var{collection}; if the beginning of the | |
528 permissible completion equals @var{string}, it matches. If no permissible | |
529 completions match, @code{try-completion} returns @code{nil}. If only | |
530 one permissible completion matches, and the match is exact, then | |
531 @code{try-completion} returns @code{t}. Otherwise, the value is the | |
532 longest initial sequence common to all the permissible completions that | |
533 match. | |
534 | |
535 If @var{collection} is an alist (@pxref{Association Lists}), the | |
536 @sc{car}s of the alist elements form the set of permissible completions. | |
537 | |
538 @cindex obarray in completion | |
539 If @var{collection} is an obarray (@pxref{Creating Symbols}), the names | |
540 of all symbols in the obarray form the set of permissible completions. The | |
541 global variable @code{obarray} holds an obarray containing the names of | |
542 all interned Lisp symbols. | |
543 | |
544 Note that the only valid way to make a new obarray is to create it | |
545 empty and then add symbols to it one by one using @code{intern}. | |
546 Also, you cannot intern a given symbol in more than one obarray. | |
547 | |
548 If the argument @var{predicate} is non-@code{nil}, then it must be a | |
549 function of one argument. It is used to test each possible match, and | |
550 the match is accepted only if @var{predicate} returns non-@code{nil}. | |
551 The argument given to @var{predicate} is either a cons cell from the alist | |
552 (the @sc{car} of which is a string) or else it is a symbol (@emph{not} a | |
553 symbol name) from the obarray. | |
554 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
555 You can also use a symbol that is a function as @var{collection}. Then |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
556 the function is solely responsible for performing completion; |
6555 | 557 @code{try-completion} returns whatever this function returns. The |
558 function is called with three arguments: @var{string}, @var{predicate} | |
559 and @code{nil}. (The reason for the third argument is so that the same | |
560 function can be used in @code{all-completions} and do the appropriate | |
561 thing in either case.) @xref{Programmed Completion}. | |
562 | |
563 In the first of the following examples, the string @samp{foo} is | |
564 matched by three of the alist @sc{car}s. All of the matches begin with | |
565 the characters @samp{fooba}, so that is the result. In the second | |
566 example, there is only one possible match, and it is exact, so the value | |
567 is @code{t}. | |
568 | |
569 @smallexample | |
570 @group | |
571 (try-completion | |
572 "foo" | |
573 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))) | |
574 @result{} "fooba" | |
575 @end group | |
576 | |
577 @group | |
578 (try-completion "foo" '(("barfoo" 2) ("foo" 3))) | |
579 @result{} t | |
580 @end group | |
581 @end smallexample | |
582 | |
583 In the following example, numerous symbols begin with the characters | |
584 @samp{forw}, and all of them begin with the word @samp{forward}. In | |
585 most of the symbols, this is followed with a @samp{-}, but not in all, | |
586 so no more than @samp{forward} can be completed. | |
587 | |
588 @smallexample | |
589 @group | |
590 (try-completion "forw" obarray) | |
591 @result{} "forward" | |
592 @end group | |
593 @end smallexample | |
594 | |
595 Finally, in the following example, only two of the three possible | |
596 matches pass the predicate @code{test} (the string @samp{foobaz} is | |
597 too short). Both of those begin with the string @samp{foobar}. | |
598 | |
599 @smallexample | |
600 @group | |
601 (defun test (s) | |
602 (> (length (car s)) 6)) | |
603 @result{} test | |
604 @end group | |
605 @group | |
606 (try-completion | |
607 "foo" | |
608 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)) | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
609 'test) |
6555 | 610 @result{} "foobar" |
611 @end group | |
612 @end smallexample | |
613 @end defun | |
614 | |
12067 | 615 @defun all-completions string collection &optional predicate nospace |
6555 | 616 This function returns a list of all possible completions of |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
617 @var{string}. The arguments to this function are the same as those of |
6555 | 618 @code{try-completion}. |
619 | |
620 If @var{collection} is a function, it is called with three arguments: | |
621 @var{string}, @var{predicate} and @code{t}; then @code{all-completions} | |
622 returns whatever the function returns. @xref{Programmed Completion}. | |
623 | |
12067 | 624 If @var{nospace} is non-@code{nil}, completions that start with a space |
625 are ignored unless @var{string} also starts with a space. | |
626 | |
6555 | 627 Here is an example, using the function @code{test} shown in the |
628 example for @code{try-completion}: | |
629 | |
630 @smallexample | |
631 @group | |
632 (defun test (s) | |
633 (> (length (car s)) 6)) | |
634 @result{} test | |
635 @end group | |
636 | |
637 @group | |
638 (all-completions | |
639 "foo" | |
640 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)) | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
641 'test) |
6555 | 642 @result{} ("foobar1" "foobar2") |
643 @end group | |
644 @end smallexample | |
645 @end defun | |
646 | |
647 @defvar completion-ignore-case | |
648 If the value of this variable is | |
649 non-@code{nil}, Emacs does not consider case significant in completion. | |
650 @end defvar | |
651 | |
652 @node Minibuffer Completion | |
653 @subsection Completion and the Minibuffer | |
654 | |
655 This section describes the basic interface for reading from the | |
656 minibuffer with completion. | |
657 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
658 @defun completing-read prompt collection &optional predicate require-match initial hist default inherit-input-method |
6555 | 659 This function reads a string in the minibuffer, assisting the user by |
660 providing completion. It activates the minibuffer with prompt | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
661 @var{prompt}, which must be a string. |
6555 | 662 |
663 The actual completion is done by passing @var{collection} and | |
664 @var{predicate} to the function @code{try-completion}. This happens in | |
665 certain commands bound in the local keymaps used for completion. | |
666 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
667 If @var{require-match} is @code{nil}, the exit commands work regardless |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
668 of the input in the minibuffer. If @var{require-match} is @code{t}, the |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
669 usual minibuffer exit commands won't exit unless the input completes to |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
670 an element of @var{collection}. If @var{require-match} is neither |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
671 @code{nil} nor @code{t}, then the exit commands won't exit unless the |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
672 input already in the buffer matches an element of @var{collection}. |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
673 |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
674 However, empty input is always permitted, regardless of the value of |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
675 @var{require-match}; in that case, @code{completing-read} returns |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
676 @var{default}. The value of @var{default} (if non-@code{nil}) is also |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
677 available to the user through the history commands. |
6555 | 678 |
8753 | 679 The user can exit with null input by typing @key{RET} with an empty |
16238
75913ae7ac7e
Clarify how completing-read returns an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
16157
diff
changeset
|
680 minibuffer. Then @code{completing-read} returns @code{""}. This is how |
75913ae7ac7e
Clarify how completing-read returns an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
16157
diff
changeset
|
681 the user requests whatever default the command uses for the value being |
75913ae7ac7e
Clarify how completing-read returns an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
16157
diff
changeset
|
682 read. The user can return using @key{RET} in this way regardless of the |
75913ae7ac7e
Clarify how completing-read returns an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
16157
diff
changeset
|
683 value of @var{require-match}, and regardless of whether the empty string |
75913ae7ac7e
Clarify how completing-read returns an empty string.
Richard M. Stallman <rms@gnu.org>
parents:
16157
diff
changeset
|
684 is included in @var{collection}. |
8753 | 685 |
6555 | 686 The function @code{completing-read} works by calling |
687 @code{read-minibuffer}. It uses @code{minibuffer-local-completion-map} | |
688 as the keymap if @var{require-match} is @code{nil}, and uses | |
689 @code{minibuffer-local-must-match-map} if @var{require-match} is | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
690 non-@code{nil}. @xref{Completion Commands}. |
6555 | 691 |
692 The argument @var{hist} specifies which history list variable to use for | |
693 saving the input and for minibuffer history commands. It defaults to | |
694 @code{minibuffer-history}. @xref{Minibuffer History}. | |
695 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
696 If @var{initial} is non-@code{nil}, @code{completing-read} inserts it |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
697 into the minibuffer as part of the input. Then it allows the user to |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
698 edit the input, providing several commands to attempt completion. |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
699 In most cases, we recommend using @var{default}, and not @var{initial}. |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
700 |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
701 If the argument @var{inherit-input-method} is non-@code{nil}, then the |
22252
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
702 minibuffer inherits the current input method (@pxref{Input |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
703 Methods}) and the setting of @code{enable-multibyte-characters} |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
704 (@pxref{Text Representations}) from whichever buffer was current before |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
705 entering the minibuffer. |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
706 |
6555 | 707 Completion ignores case when comparing the input against the possible |
708 matches, if the built-in variable @code{completion-ignore-case} is | |
709 non-@code{nil}. @xref{Basic Completion}. | |
710 | |
711 Here's an example of using @code{completing-read}: | |
712 | |
713 @smallexample | |
714 @group | |
715 (completing-read | |
716 "Complete a foo: " | |
717 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)) | |
718 nil t "fo") | |
719 @end group | |
720 | |
721 @group | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
722 ;; @r{After evaluation of the preceding expression,} |
6555 | 723 ;; @r{the following appears in the minibuffer:} |
724 | |
725 ---------- Buffer: Minibuffer ---------- | |
726 Complete a foo: fo@point{} | |
727 ---------- Buffer: Minibuffer ---------- | |
728 @end group | |
729 @end smallexample | |
730 | |
731 @noindent | |
732 If the user then types @kbd{@key{DEL} @key{DEL} b @key{RET}}, | |
733 @code{completing-read} returns @code{barfoo}. | |
734 | |
735 The @code{completing-read} function binds three variables to pass | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
736 information to the commands that actually do completion. These |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
737 variables are @code{minibuffer-completion-table}, |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
738 @code{minibuffer-completion-predicate} and |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
739 @code{minibuffer-completion-confirm}. For more information about them, |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
740 see @ref{Completion Commands}. |
6555 | 741 @end defun |
742 | |
743 @node Completion Commands | |
25751
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
744 @subsection Minibuffer Commands that Do Completion |
6555 | 745 |
746 This section describes the keymaps, commands and user options used in | |
747 the minibuffer to do completion. | |
748 | |
749 @defvar minibuffer-local-completion-map | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
750 @code{completing-read} uses this value as the local keymap when an |
6555 | 751 exact match of one of the completions is not required. By default, this |
752 keymap makes the following bindings: | |
753 | |
754 @table @asis | |
755 @item @kbd{?} | |
756 @code{minibuffer-completion-help} | |
757 | |
758 @item @key{SPC} | |
759 @code{minibuffer-complete-word} | |
760 | |
761 @item @key{TAB} | |
762 @code{minibuffer-complete} | |
763 @end table | |
764 | |
765 @noindent | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
766 with other characters bound as in @code{minibuffer-local-map} |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
767 (@pxref{Text from Minibuffer}). |
6555 | 768 @end defvar |
769 | |
770 @defvar minibuffer-local-must-match-map | |
771 @code{completing-read} uses this value as the local keymap when an | |
772 exact match of one of the completions is required. Therefore, no keys | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
773 are bound to @code{exit-minibuffer}, the command that exits the |
6555 | 774 minibuffer unconditionally. By default, this keymap makes the following |
775 bindings: | |
776 | |
777 @table @asis | |
778 @item @kbd{?} | |
779 @code{minibuffer-completion-help} | |
780 | |
781 @item @key{SPC} | |
782 @code{minibuffer-complete-word} | |
783 | |
784 @item @key{TAB} | |
785 @code{minibuffer-complete} | |
786 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
787 @item @kbd{C-j} |
6555 | 788 @code{minibuffer-complete-and-exit} |
789 | |
790 @item @key{RET} | |
791 @code{minibuffer-complete-and-exit} | |
792 @end table | |
793 | |
794 @noindent | |
795 with other characters bound as in @code{minibuffer-local-map}. | |
796 @end defvar | |
797 | |
798 @defvar minibuffer-completion-table | |
799 The value of this variable is the alist or obarray used for completion | |
800 in the minibuffer. This is the global variable that contains what | |
801 @code{completing-read} passes to @code{try-completion}. It is used by | |
802 minibuffer completion commands such as @code{minibuffer-complete-word}. | |
803 @end defvar | |
804 | |
805 @defvar minibuffer-completion-predicate | |
806 This variable's value is the predicate that @code{completing-read} | |
807 passes to @code{try-completion}. The variable is also used by the other | |
808 minibuffer completion functions. | |
809 @end defvar | |
810 | |
811 @deffn Command minibuffer-complete-word | |
812 This function completes the minibuffer contents by at most a single | |
813 word. Even if the minibuffer contents have only one completion, | |
814 @code{minibuffer-complete-word} does not add any characters beyond the | |
815 first character that is not a word constituent. @xref{Syntax Tables}. | |
816 @end deffn | |
817 | |
818 @deffn Command minibuffer-complete | |
819 This function completes the minibuffer contents as far as possible. | |
820 @end deffn | |
821 | |
822 @deffn Command minibuffer-complete-and-exit | |
823 This function completes the minibuffer contents, and exits if | |
824 confirmation is not required, i.e., if | |
13319
ce09d77f76a6
Minor fix in minibuffer-complete-and-exit.
Richard M. Stallman <rms@gnu.org>
parents:
12226
diff
changeset
|
825 @code{minibuffer-completion-confirm} is @code{nil}. If confirmation |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
826 @emph{is} required, it is given by repeating this command |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
827 immediately---the command is programmed to work without confirmation |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
828 when run twice in succession. |
6555 | 829 @end deffn |
830 | |
831 @defvar minibuffer-completion-confirm | |
832 When the value of this variable is non-@code{nil}, Emacs asks for | |
833 confirmation of a completion before exiting the minibuffer. The | |
834 function @code{minibuffer-complete-and-exit} checks the value of this | |
835 variable before it exits. | |
836 @end defvar | |
837 | |
838 @deffn Command minibuffer-completion-help | |
839 This function creates a list of the possible completions of the | |
840 current minibuffer contents. It works by calling @code{all-completions} | |
841 using the value of the variable @code{minibuffer-completion-table} as | |
842 the @var{collection} argument, and the value of | |
843 @code{minibuffer-completion-predicate} as the @var{predicate} argument. | |
844 The list of completions is displayed as text in a buffer named | |
845 @samp{*Completions*}. | |
846 @end deffn | |
847 | |
848 @defun display-completion-list completions | |
849 This function displays @var{completions} to the stream in | |
7337
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
850 @code{standard-output}, usually a buffer. (@xref{Read and Print}, for more |
6555 | 851 information about streams.) The argument @var{completions} is normally |
852 a list of completions just returned by @code{all-completions}, but it | |
853 does not have to be. Each element may be a symbol or a string, either | |
854 of which is simply printed, or a list of two strings, which is printed | |
855 as if the strings were concatenated. | |
856 | |
857 This function is called by @code{minibuffer-completion-help}. The | |
858 most common way to use it is together with | |
859 @code{with-output-to-temp-buffer}, like this: | |
860 | |
861 @example | |
862 (with-output-to-temp-buffer "*Completions*" | |
863 (display-completion-list | |
864 (all-completions (buffer-string) my-alist))) | |
865 @end example | |
866 @end defun | |
867 | |
868 @defopt completion-auto-help | |
869 If this variable is non-@code{nil}, the completion commands | |
870 automatically display a list of possible completions whenever nothing | |
871 can be completed because the next character is not uniquely determined. | |
872 @end defopt | |
873 | |
874 @node High-Level Completion | |
875 @subsection High-Level Completion Functions | |
876 | |
877 This section describes the higher-level convenient functions for | |
878 reading certain sorts of names with completion. | |
879 | |
12098 | 880 In most cases, you should not call these functions in the middle of a |
881 Lisp function. When possible, do all minibuffer input as part of | |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
882 reading the arguments for a command, in the @code{interactive} |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
883 specification. @xref{Defining Commands}. |
12098 | 884 |
6555 | 885 @defun read-buffer prompt &optional default existing |
886 This function reads the name of a buffer and returns it as a string. | |
887 The argument @var{default} is the default name to use, the value to | |
888 return if the user exits with an empty minibuffer. If non-@code{nil}, | |
889 it should be a string or a buffer. It is mentioned in the prompt, but | |
890 is not inserted in the minibuffer as initial input. | |
891 | |
892 If @var{existing} is non-@code{nil}, then the name specified must be | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
893 that of an existing buffer. The usual commands to exit the minibuffer |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
894 do not exit if the text is not valid, and @key{RET} does completion to |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
895 attempt to find a valid name. (However, @var{default} is not checked |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
896 for validity; it is returned, whatever it is, if the user exits with the |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
897 minibuffer empty.) |
6555 | 898 |
899 In the following example, the user enters @samp{minibuffer.t}, and | |
900 then types @key{RET}. The argument @var{existing} is @code{t}, and the | |
901 only buffer name starting with the given input is | |
902 @samp{minibuffer.texi}, so that name is the value. | |
903 | |
904 @example | |
905 (read-buffer "Buffer name? " "foo" t) | |
906 @group | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
907 ;; @r{After evaluation of the preceding expression,} |
6555 | 908 ;; @r{the following prompt appears,} |
909 ;; @r{with an empty minibuffer:} | |
910 @end group | |
911 | |
912 @group | |
913 ---------- Buffer: Minibuffer ---------- | |
914 Buffer name? (default foo) @point{} | |
915 ---------- Buffer: Minibuffer ---------- | |
916 @end group | |
917 | |
918 @group | |
919 ;; @r{The user types @kbd{minibuffer.t @key{RET}}.} | |
920 @result{} "minibuffer.texi" | |
921 @end group | |
922 @end example | |
923 @end defun | |
924 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
925 @defvar read-buffer-function |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
926 This variable specifies how to read buffer names. For example, if you |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
927 set this variable to @code{iswitchb-read-buffer}, all Emacs commands |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
928 that call @code{read-buffer} to read a buffer name will actually use the |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
929 @code{iswitchb} package to read it. |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
930 @end defvar |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
931 |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
932 @defun read-command prompt &optional default |
6555 | 933 This function reads the name of a command and returns it as a Lisp |
934 symbol. The argument @var{prompt} is used as in | |
935 @code{read-from-minibuffer}. Recall that a command is anything for | |
936 which @code{commandp} returns @code{t}, and a command name is a symbol | |
937 for which @code{commandp} returns @code{t}. @xref{Interactive Call}. | |
938 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
939 The argument @var{default} specifies what to return if the user enters |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
940 null input. It can be a symbol or a string; if it is a string, |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
941 @code{read-command} interns it before returning it. If @var{default} is |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
942 @code{nil}, that means no default has been specified; then if the user |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
943 enters null input, the return value is @code{nil}. |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
944 |
6555 | 945 @example |
946 (read-command "Command name? ") | |
947 | |
948 @group | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
949 ;; @r{After evaluation of the preceding expression,} |
6555 | 950 ;; @r{the following prompt appears with an empty minibuffer:} |
951 @end group | |
952 | |
953 @group | |
954 ---------- Buffer: Minibuffer ---------- | |
955 Command name? | |
956 ---------- Buffer: Minibuffer ---------- | |
957 @end group | |
958 @end example | |
959 | |
960 @noindent | |
961 If the user types @kbd{forward-c @key{RET}}, then this function returns | |
962 @code{forward-char}. | |
963 | |
16736
981e116b4ac6
Minor cleanups for overfull hboxes.
Richard M. Stallman <rms@gnu.org>
parents:
16238
diff
changeset
|
964 The @code{read-command} function is a simplified interface to |
981e116b4ac6
Minor cleanups for overfull hboxes.
Richard M. Stallman <rms@gnu.org>
parents:
16238
diff
changeset
|
965 @code{completing-read}. It uses the variable @code{obarray} so as to |
981e116b4ac6
Minor cleanups for overfull hboxes.
Richard M. Stallman <rms@gnu.org>
parents:
16238
diff
changeset
|
966 complete in the set of extant Lisp symbols, and it uses the |
6555 | 967 @code{commandp} predicate so as to accept only command names: |
968 | |
969 @cindex @code{commandp} example | |
970 @example | |
971 @group | |
972 (read-command @var{prompt}) | |
973 @equiv{} | |
974 (intern (completing-read @var{prompt} obarray | |
975 'commandp t nil)) | |
976 @end group | |
977 @end example | |
978 @end defun | |
979 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
980 @defun read-variable prompt &optional default |
6555 | 981 This function reads the name of a user variable and returns it as a |
982 symbol. | |
983 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
984 The argument @var{default} specifies what to return if the user enters |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
985 null input. It can be a symbol or a string; if it is a string, |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
986 @code{read-variable} interns it before returning it. If @var{default} |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
987 is @code{nil}, that means no default has been specified; then if the |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
988 user enters null input, the return value is @code{nil}. |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
989 |
6555 | 990 @example |
991 @group | |
992 (read-variable "Variable name? ") | |
993 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
994 ;; @r{After evaluation of the preceding expression,} |
6555 | 995 ;; @r{the following prompt appears,} |
996 ;; @r{with an empty minibuffer:} | |
997 @end group | |
998 | |
999 @group | |
1000 ---------- Buffer: Minibuffer ---------- | |
1001 Variable name? @point{} | |
1002 ---------- Buffer: Minibuffer ---------- | |
1003 @end group | |
1004 @end example | |
1005 | |
1006 @noindent | |
1007 If the user then types @kbd{fill-p @key{RET}}, @code{read-variable} | |
1008 returns @code{fill-prefix}. | |
1009 | |
1010 This function is similar to @code{read-command}, but uses the | |
1011 predicate @code{user-variable-p} instead of @code{commandp}: | |
1012 | |
1013 @cindex @code{user-variable-p} example | |
1014 @example | |
1015 @group | |
1016 (read-variable @var{prompt}) | |
1017 @equiv{} | |
1018 (intern | |
1019 (completing-read @var{prompt} obarray | |
1020 'user-variable-p t nil)) | |
1021 @end group | |
1022 @end example | |
1023 @end defun | |
1024 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
1025 See also the functions @code{read-coding-system} and |
22252
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
1026 @code{read-non-nil-coding-system}, in @ref{User-Chosen Coding Systems}. |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
1027 |
6555 | 1028 @node Reading File Names |
1029 @subsection Reading File Names | |
1030 | |
1031 Here is another high-level completion function, designed for reading a | |
1032 file name. It provides special features including automatic insertion | |
1033 of the default directory. | |
1034 | |
1035 @defun read-file-name prompt &optional directory default existing initial | |
1036 This function reads a file name in the minibuffer, prompting with | |
1037 @var{prompt} and providing completion. If @var{default} is | |
1038 non-@code{nil}, then the function returns @var{default} if the user just | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1039 types @key{RET}. @var{default} is not checked for validity; it is |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1040 returned, whatever it is, if the user exits with the minibuffer empty. |
6555 | 1041 |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1042 If @var{existing} is non-@code{nil}, then the user must specify the name |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1043 of an existing file; @key{RET} performs completion to make the name |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1044 valid if possible, and then refuses to exit if it is not valid. If the |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1045 value of @var{existing} is neither @code{nil} nor @code{t}, then |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1046 @key{RET} also requires confirmation after completion. If |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1047 @var{existing} is @code{nil}, then the name of a nonexistent file is |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1048 acceptable. |
6555 | 1049 |
1050 The argument @var{directory} specifies the directory to use for | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1051 completion of relative file names. If @code{insert-default-directory} |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1052 is non-@code{nil}, @var{directory} is also inserted in the minibuffer as |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1053 initial input. It defaults to the current buffer's value of |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1054 @code{default-directory}. |
6555 | 1055 |
1056 @c Emacs 19 feature | |
1057 If you specify @var{initial}, that is an initial file name to insert in | |
22252
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
1058 the buffer (after @var{directory}, if that is inserted). In this |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1059 case, point goes at the beginning of @var{initial}. The default for |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1060 @var{initial} is @code{nil}---don't insert any file name. To see what |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
1061 @var{initial} does, try the command @kbd{C-x C-v}. @strong{Note:} we |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
1062 recommend using @var{default} rather than @var{initial} in most cases. |
6555 | 1063 |
1064 Here is an example: | |
1065 | |
1066 @example | |
1067 @group | |
1068 (read-file-name "The file is ") | |
1069 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1070 ;; @r{After evaluation of the preceding expression,} |
6555 | 1071 ;; @r{the following appears in the minibuffer:} |
1072 @end group | |
1073 | |
1074 @group | |
1075 ---------- Buffer: Minibuffer ---------- | |
1076 The file is /gp/gnu/elisp/@point{} | |
1077 ---------- Buffer: Minibuffer ---------- | |
1078 @end group | |
1079 @end example | |
1080 | |
1081 @noindent | |
1082 Typing @kbd{manual @key{TAB}} results in the following: | |
1083 | |
1084 @example | |
1085 @group | |
1086 ---------- Buffer: Minibuffer ---------- | |
1087 The file is /gp/gnu/elisp/manual.texi@point{} | |
1088 ---------- Buffer: Minibuffer ---------- | |
1089 @end group | |
1090 @end example | |
1091 | |
1092 @c Wordy to avoid overfull hbox in smallbook mode. | |
1093 @noindent | |
1094 If the user types @key{RET}, @code{read-file-name} returns the file name | |
1095 as the string @code{"/gp/gnu/elisp/manual.texi"}. | |
1096 @end defun | |
1097 | |
1098 @defopt insert-default-directory | |
1099 This variable is used by @code{read-file-name}. Its value controls | |
1100 whether @code{read-file-name} starts by placing the name of the default | |
1101 directory in the minibuffer, plus the initial file name if any. If the | |
1102 value of this variable is @code{nil}, then @code{read-file-name} does | |
12098 | 1103 not place any initial input in the minibuffer (unless you specify |
1104 initial input with the @var{initial} argument). In that case, the | |
6555 | 1105 default directory is still used for completion of relative file names, |
1106 but is not displayed. | |
1107 | |
1108 For example: | |
1109 | |
1110 @example | |
1111 @group | |
1112 ;; @r{Here the minibuffer starts out with the default directory.} | |
1113 (let ((insert-default-directory t)) | |
1114 (read-file-name "The file is ")) | |
1115 @end group | |
1116 | |
1117 @group | |
1118 ---------- Buffer: Minibuffer ---------- | |
1119 The file is ~lewis/manual/@point{} | |
1120 ---------- Buffer: Minibuffer ---------- | |
1121 @end group | |
1122 | |
1123 @group | |
1124 ;; @r{Here the minibuffer is empty and only the prompt} | |
1125 ;; @r{appears on its line.} | |
1126 (let ((insert-default-directory nil)) | |
1127 (read-file-name "The file is ")) | |
1128 @end group | |
1129 | |
1130 @group | |
1131 ---------- Buffer: Minibuffer ---------- | |
1132 The file is @point{} | |
1133 ---------- Buffer: Minibuffer ---------- | |
1134 @end group | |
1135 @end example | |
1136 @end defopt | |
1137 | |
1138 @node Programmed Completion | |
1139 @subsection Programmed Completion | |
1140 @cindex programmed completion | |
1141 | |
1142 Sometimes it is not possible to create an alist or an obarray | |
1143 containing all the intended possible completions. In such a case, you | |
1144 can supply your own function to compute the completion of a given string. | |
1145 This is called @dfn{programmed completion}. | |
1146 | |
1147 To use this feature, pass a symbol with a function definition as the | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1148 @var{collection} argument to @code{completing-read}. The function |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1149 @code{completing-read} arranges to pass your completion function along |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1150 to @code{try-completion} and @code{all-completions}, which will then let |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1151 your function do all the work. |
6555 | 1152 |
1153 The completion function should accept three arguments: | |
1154 | |
1155 @itemize @bullet | |
1156 @item | |
1157 The string to be completed. | |
1158 | |
1159 @item | |
1160 The predicate function to filter possible matches, or @code{nil} if | |
1161 none. Your function should call the predicate for each possible match, | |
1162 and ignore the possible match if the predicate returns @code{nil}. | |
1163 | |
1164 @item | |
1165 A flag specifying the type of operation. | |
1166 @end itemize | |
1167 | |
1168 There are three flag values for three operations: | |
1169 | |
1170 @itemize @bullet | |
1171 @item | |
1172 @code{nil} specifies @code{try-completion}. The completion function | |
1173 should return the completion of the specified string, or @code{t} if the | |
16157
1713fe640e41
Clarify value returned by programmed completion function.
Richard M. Stallman <rms@gnu.org>
parents:
15768
diff
changeset
|
1174 string is a unique and exact match already, or @code{nil} if the string |
1713fe640e41
Clarify value returned by programmed completion function.
Richard M. Stallman <rms@gnu.org>
parents:
15768
diff
changeset
|
1175 matches no possibility. |
1713fe640e41
Clarify value returned by programmed completion function.
Richard M. Stallman <rms@gnu.org>
parents:
15768
diff
changeset
|
1176 |
1713fe640e41
Clarify value returned by programmed completion function.
Richard M. Stallman <rms@gnu.org>
parents:
15768
diff
changeset
|
1177 If the string is an exact match for one possibility, but also matches |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
1178 other longer possibilities, the function should return the string, not |
16157
1713fe640e41
Clarify value returned by programmed completion function.
Richard M. Stallman <rms@gnu.org>
parents:
15768
diff
changeset
|
1179 @code{t}. |
6555 | 1180 |
1181 @item | |
1182 @code{t} specifies @code{all-completions}. The completion function | |
1183 should return a list of all possible completions of the specified | |
1184 string. | |
1185 | |
1186 @item | |
1187 @code{lambda} specifies a test for an exact match. The completion | |
1188 function should return @code{t} if the specified string is an exact | |
1189 match for some possibility; @code{nil} otherwise. | |
1190 @end itemize | |
1191 | |
1192 It would be consistent and clean for completion functions to allow | |
12098 | 1193 lambda expressions (lists that are functions) as well as function |
6555 | 1194 symbols as @var{collection}, but this is impossible. Lists as |
1195 completion tables are already assigned another meaning---as alists. It | |
1196 would be unreliable to fail to handle an alist normally because it is | |
1197 also a possible function. So you must arrange for any function you wish | |
1198 to use for completion to be encapsulated in a symbol. | |
1199 | |
1200 Emacs uses programmed completion when completing file names. | |
1201 @xref{File Name Completion}. | |
1202 | |
1203 @node Yes-or-No Queries | |
1204 @section Yes-or-No Queries | |
1205 @cindex asking the user questions | |
1206 @cindex querying the user | |
1207 @cindex yes-or-no questions | |
1208 | |
1209 This section describes functions used to ask the user a yes-or-no | |
1210 question. The function @code{y-or-n-p} can be answered with a single | |
1211 character; it is useful for questions where an inadvertent wrong answer | |
1212 will not have serious consequences. @code{yes-or-no-p} is suitable for | |
1213 more momentous questions, since it requires three or four characters to | |
1214 answer. | |
1215 | |
7337
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1216 If either of these functions is called in a command that was invoked |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1217 using the mouse---more precisely, if @code{last-nonmenu-event} |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1218 (@pxref{Command Loop Info}) is either @code{nil} or a list---then it |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1219 uses a dialog box or pop-up menu to ask the question. Otherwise, it |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1220 uses keyboard input. You can force use of the mouse or use of keyboard |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1221 input by binding @code{last-nonmenu-event} to a suitable value around |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1222 the call. |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1223 |
6555 | 1224 Strictly speaking, @code{yes-or-no-p} uses the minibuffer and |
1225 @code{y-or-n-p} does not; but it seems best to describe them together. | |
1226 | |
1227 @defun y-or-n-p prompt | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1228 This function asks the user a question, expecting input in the echo |
6555 | 1229 area. It returns @code{t} if the user types @kbd{y}, @code{nil} if the |
1230 user types @kbd{n}. This function also accepts @key{SPC} to mean yes | |
1231 and @key{DEL} to mean no. It accepts @kbd{C-]} to mean ``quit'', like | |
1232 @kbd{C-g}, because the question might look like a minibuffer and for | |
1233 that reason the user might try to use @kbd{C-]} to get out. The answer | |
1234 is a single character, with no @key{RET} needed to terminate it. Upper | |
1235 and lower case are equivalent. | |
1236 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1237 ``Asking the question'' means printing @var{prompt} in the echo area, |
6555 | 1238 followed by the string @w{@samp{(y or n) }}. If the input is not one of |
1239 the expected answers (@kbd{y}, @kbd{n}, @kbd{@key{SPC}}, | |
1240 @kbd{@key{DEL}}, or something that quits), the function responds | |
1241 @samp{Please answer y or n.}, and repeats the request. | |
1242 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1243 This function does not actually use the minibuffer, since it does not |
6555 | 1244 allow editing of the answer. It actually uses the echo area (@pxref{The |
1245 Echo Area}), which uses the same screen space as the minibuffer. The | |
1246 cursor moves to the echo area while the question is being asked. | |
1247 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1248 The answers and their meanings, even @samp{y} and @samp{n}, are not |
6555 | 1249 hardwired. The keymap @code{query-replace-map} specifies them. |
1250 @xref{Search and Replace}. | |
1251 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1252 In the following example, the user first types @kbd{q}, which is |
6555 | 1253 invalid. At the next prompt the user types @kbd{y}. |
1254 | |
1255 @smallexample | |
1256 @group | |
1257 (y-or-n-p "Do you need a lift? ") | |
1258 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1259 ;; @r{After evaluation of the preceding expression,} |
6555 | 1260 ;; @r{the following prompt appears in the echo area:} |
1261 @end group | |
1262 | |
1263 @group | |
1264 ---------- Echo area ---------- | |
1265 Do you need a lift? (y or n) | |
1266 ---------- Echo area ---------- | |
1267 @end group | |
1268 | |
1269 ;; @r{If the user then types @kbd{q}, the following appears:} | |
1270 | |
1271 @group | |
1272 ---------- Echo area ---------- | |
1273 Please answer y or n. Do you need a lift? (y or n) | |
1274 ---------- Echo area ---------- | |
1275 @end group | |
1276 | |
1277 ;; @r{When the user types a valid answer,} | |
1278 ;; @r{it is displayed after the question:} | |
1279 | |
1280 @group | |
1281 ---------- Echo area ---------- | |
1282 Do you need a lift? (y or n) y | |
1283 ---------- Echo area ---------- | |
1284 @end group | |
1285 @end smallexample | |
1286 | |
1287 @noindent | |
1288 We show successive lines of echo area messages, but only one actually | |
1289 appears on the screen at a time. | |
1290 @end defun | |
1291 | |
15768
b913a75fddee
Add y-or-n-p-with-timeout.
Richard M. Stallman <rms@gnu.org>
parents:
13319
diff
changeset
|
1292 @defun y-or-n-p-with-timeout prompt seconds default-value |
b913a75fddee
Add y-or-n-p-with-timeout.
Richard M. Stallman <rms@gnu.org>
parents:
13319
diff
changeset
|
1293 Like @code{y-or-n-p}, except that if the user fails to answer within |
b913a75fddee
Add y-or-n-p-with-timeout.
Richard M. Stallman <rms@gnu.org>
parents:
13319
diff
changeset
|
1294 @var{seconds} seconds, this function stops waiting and returns |
b913a75fddee
Add y-or-n-p-with-timeout.
Richard M. Stallman <rms@gnu.org>
parents:
13319
diff
changeset
|
1295 @var{default-value}. It works by setting up a timer; see @ref{Timers}. |
b913a75fddee
Add y-or-n-p-with-timeout.
Richard M. Stallman <rms@gnu.org>
parents:
13319
diff
changeset
|
1296 The argument @var{seconds} may be an integer or a floating point number. |
b913a75fddee
Add y-or-n-p-with-timeout.
Richard M. Stallman <rms@gnu.org>
parents:
13319
diff
changeset
|
1297 @end defun |
b913a75fddee
Add y-or-n-p-with-timeout.
Richard M. Stallman <rms@gnu.org>
parents:
13319
diff
changeset
|
1298 |
6555 | 1299 @defun yes-or-no-p prompt |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1300 This function asks the user a question, expecting input in the |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1301 minibuffer. It returns @code{t} if the user enters @samp{yes}, |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1302 @code{nil} if the user types @samp{no}. The user must type @key{RET} to |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1303 finalize the response. Upper and lower case are equivalent. |
6555 | 1304 |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1305 @code{yes-or-no-p} starts by displaying @var{prompt} in the echo area, |
6555 | 1306 followed by @w{@samp{(yes or no) }}. The user must type one of the |
1307 expected responses; otherwise, the function responds @samp{Please answer | |
1308 yes or no.}, waits about two seconds and repeats the request. | |
1309 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1310 @code{yes-or-no-p} requires more work from the user than |
6555 | 1311 @code{y-or-n-p} and is appropriate for more crucial decisions. |
1312 | |
1313 Here is an example: | |
1314 | |
1315 @smallexample | |
1316 @group | |
1317 (yes-or-no-p "Do you really want to remove everything? ") | |
1318 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1319 ;; @r{After evaluation of the preceding expression,} |
6555 | 1320 ;; @r{the following prompt appears,} |
1321 ;; @r{with an empty minibuffer:} | |
1322 @end group | |
1323 | |
1324 @group | |
1325 ---------- Buffer: minibuffer ---------- | |
1326 Do you really want to remove everything? (yes or no) | |
1327 ---------- Buffer: minibuffer ---------- | |
1328 @end group | |
1329 @end smallexample | |
1330 | |
1331 @noindent | |
1332 If the user first types @kbd{y @key{RET}}, which is invalid because this | |
1333 function demands the entire word @samp{yes}, it responds by displaying | |
1334 these prompts, with a brief pause between them: | |
1335 | |
1336 @smallexample | |
1337 @group | |
1338 ---------- Buffer: minibuffer ---------- | |
1339 Please answer yes or no. | |
1340 Do you really want to remove everything? (yes or no) | |
1341 ---------- Buffer: minibuffer ---------- | |
1342 @end group | |
1343 @end smallexample | |
1344 @end defun | |
1345 | |
1346 @node Multiple Queries | |
1347 @section Asking Multiple Y-or-N Questions | |
1348 | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1349 When you have a series of similar questions to ask, such as ``Do you |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1350 want to save this buffer'' for each buffer in turn, you should use |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1351 @code{map-y-or-n-p} to ask the collection of questions, rather than |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1352 asking each question individually. This gives the user certain |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1353 convenient facilities such as the ability to answer the whole series at |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1354 once. |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1355 |
26696
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1356 @defun map-y-or-n-p prompter actor list &optional help action-alist no-cursor-in-echo-area |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
1357 This function asks the user a series of questions, reading a |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
16736
diff
changeset
|
1358 single-character answer in the echo area for each one. |
6555 | 1359 |
1360 The value of @var{list} specifies the objects to ask questions about. | |
1361 It should be either a list of objects or a generator function. If it is | |
1362 a function, it should expect no arguments, and should return either the | |
1363 next object to ask about, or @code{nil} meaning stop asking questions. | |
1364 | |
1365 The argument @var{prompter} specifies how to ask each question. If | |
1366 @var{prompter} is a string, the question text is computed like this: | |
1367 | |
1368 @example | |
1369 (format @var{prompter} @var{object}) | |
1370 @end example | |
1371 | |
1372 @noindent | |
1373 where @var{object} is the next object to ask about (as obtained from | |
1374 @var{list}). | |
1375 | |
1376 If not a string, @var{prompter} should be a function of one argument | |
12226 | 1377 (the next object to ask about) and should return the question text. If |
1378 the value is a string, that is the question to ask the user. The | |
1379 function can also return @code{t} meaning do act on this object (and | |
1380 don't ask the user), or @code{nil} meaning ignore this object (and don't | |
1381 ask the user). | |
6555 | 1382 |
1383 The argument @var{actor} says how to act on the answers that the user | |
1384 gives. It should be a function of one argument, and it is called with | |
1385 each object that the user says yes for. Its argument is always an | |
1386 object obtained from @var{list}. | |
1387 | |
1388 If the argument @var{help} is given, it should be a list of this form: | |
1389 | |
1390 @example | |
1391 (@var{singular} @var{plural} @var{action}) | |
1392 @end example | |
1393 | |
1394 @noindent | |
1395 where @var{singular} is a string containing a singular noun that | |
1396 describes the objects conceptually being acted on, @var{plural} is the | |
1397 corresponding plural noun, and @var{action} is a transitive verb | |
1398 describing what @var{actor} does. | |
1399 | |
1400 If you don't specify @var{help}, the default is @code{("object" | |
1401 "objects" "act on")}. | |
1402 | |
1403 Each time a question is asked, the user may enter @kbd{y}, @kbd{Y}, or | |
1404 @key{SPC} to act on that object; @kbd{n}, @kbd{N}, or @key{DEL} to skip | |
1405 that object; @kbd{!} to act on all following objects; @key{ESC} or | |
1406 @kbd{q} to exit (skip all following objects); @kbd{.} (period) to act on | |
1407 the current object and then exit; or @kbd{C-h} to get help. These are | |
1408 the same answers that @code{query-replace} accepts. The keymap | |
1409 @code{query-replace-map} defines their meaning for @code{map-y-or-n-p} | |
1410 as well as for @code{query-replace}; see @ref{Search and Replace}. | |
1411 | |
1412 You can use @var{action-alist} to specify additional possible answers | |
1413 and what they mean. It is an alist of elements of the form | |
1414 @code{(@var{char} @var{function} @var{help})}, each of which defines one | |
1415 additional answer. In this element, @var{char} is a character (the | |
1416 answer); @var{function} is a function of one argument (an object from | |
1417 @var{list}); @var{help} is a string. | |
1418 | |
1419 When the user responds with @var{char}, @code{map-y-or-n-p} calls | |
1420 @var{function}. If it returns non-@code{nil}, the object is considered | |
1421 ``acted upon'', and @code{map-y-or-n-p} advances to the next object in | |
1422 @var{list}. If it returns @code{nil}, the prompt is repeated for the | |
1423 same object. | |
1424 | |
26696
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1425 Normally, @code{map-y-or-n-p} binds @code{cursor-in-echo-area} while |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1426 prompting. But if @var{no-cursor-in-echo-area} is non-@code{nil}, it |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1427 does not do that. |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1428 |
7337
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1429 If @code{map-y-or-n-p} is called in a command that was invoked using the |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1430 mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1431 Loop Info}) is either @code{nil} or a list---then it uses a dialog box |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1432 or pop-up menu to ask the question. In this case, it does not use |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1433 keyboard input or the echo area. You can force use of the mouse or use |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1434 of keyboard input by binding @code{last-nonmenu-event} to a suitable |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1435 value around the call. |
cd57cd335fff
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7221
diff
changeset
|
1436 |
6555 | 1437 The return value of @code{map-y-or-n-p} is the number of objects acted on. |
1438 @end defun | |
1439 | |
23147 | 1440 @node Reading a Password |
1441 @section Reading a Password | |
1442 @cindex passwords, reading | |
1443 | |
1444 To read a password to pass to another program, you can use the | |
1445 function @code{read-passwd}. | |
1446 | |
1447 @tindex read-passwd | |
1448 @defun read-passwd prompt &optional confirm default | |
1449 This function reads a password, prompting with @var{prompt}. It does | |
1450 not echo the password as the user types it; instead, it echoes @samp{.} | |
1451 for each character in the password. | |
1452 | |
1453 The optional argument @var{confirm}, if non-@code{nil}, says to read the | |
1454 password twice and insist it must be the same both times. If it isn't | |
1455 the same, the user has to type it over and over until the last two | |
1456 times match. | |
1457 | |
1458 The optional argument @var{default} specifies the default password to | |
1459 return if the user enters empty input. If @var{default} is @code{nil}, | |
1460 then @code{read-passwd} returns the null string in that case. | |
1461 @end defun | |
1462 | |
6555 | 1463 @node Minibuffer Misc |
1464 @section Minibuffer Miscellany | |
1465 | |
1466 This section describes some basic functions and variables related to | |
1467 minibuffers. | |
1468 | |
1469 @deffn Command exit-minibuffer | |
1470 This command exits the active minibuffer. It is normally bound to | |
1471 keys in minibuffer local keymaps. | |
1472 @end deffn | |
1473 | |
1474 @deffn Command self-insert-and-exit | |
1475 This command exits the active minibuffer after inserting the last | |
1476 character typed on the keyboard (found in @code{last-command-char}; | |
1477 @pxref{Command Loop Info}). | |
1478 @end deffn | |
1479 | |
1480 @deffn Command previous-history-element n | |
1481 This command replaces the minibuffer contents with the value of the | |
1482 @var{n}th previous (older) history element. | |
1483 @end deffn | |
1484 | |
1485 @deffn Command next-history-element n | |
1486 This command replaces the minibuffer contents with the value of the | |
1487 @var{n}th more recent history element. | |
1488 @end deffn | |
1489 | |
26696
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1490 @deffn Command previous-matching-history-element pattern n |
6555 | 1491 This command replaces the minibuffer contents with the value of the |
26696
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1492 @var{n}th previous (older) history element that matches @var{pattern} (a |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1493 regular expression). |
6555 | 1494 @end deffn |
1495 | |
26696
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1496 @deffn Command next-matching-history-element pattern n |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1497 This command replaces the minibuffer contents with the value of the |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1498 @var{n}th next (newer) history element that matches @var{pattern} (a |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1499 regular expression). |
6555 | 1500 @end deffn |
1501 | |
12098 | 1502 @defun minibuffer-prompt |
1503 This function returns the prompt string of the currently active | |
1504 minibuffer. If no minibuffer is active, it returns @code{nil}. | |
1505 @end defun | |
1506 | |
26696
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1507 @tindex minibuffer-prompt-end |
ef5e7bbe6f19
Current version from /gd/gnu/elisp.
Dave Love <fx@gnu.org>
parents:
25751
diff
changeset
|
1508 @defun minibuffer-prompt-end |
25751
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
1509 This function, available starting in Emacs 21, returns the current |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
1510 position of the end of the minibuffer prompt, if a minibuffer is |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
1511 current. Otherwise, it returns zero. |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
1512 @end defun |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
1513 |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
1514 @defun minubuffer-prompt-width |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
1515 This function returns the current display-width of the minibuffer |
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
23147
diff
changeset
|
1516 prompt, if a minibuffer is current. Otherwise, it returns zero. |
12098 | 1517 @end defun |
1518 | |
6555 | 1519 @defvar minibuffer-setup-hook |
1520 This is a normal hook that is run whenever the minibuffer is entered. | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1521 @xref{Hooks}. |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1522 @end defvar |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1523 |
8529
464f7abd0b26
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7337
diff
changeset
|
1524 @defvar minibuffer-exit-hook |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1525 This is a normal hook that is run whenever the minibuffer is exited. |
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1526 @xref{Hooks}. |
6555 | 1527 @end defvar |
1528 | |
1529 @defvar minibuffer-help-form | |
1530 The current value of this variable is used to rebind @code{help-form} | |
1531 locally inside the minibuffer (@pxref{Help Functions}). | |
1532 @end defvar | |
1533 | |
12067 | 1534 @defun active-minibuffer-window |
1535 This function returns the currently active minibuffer window, or | |
1536 @code{nil} if none is currently active. | |
1537 @end defun | |
1538 | |
6555 | 1539 @defun minibuffer-window &optional frame |
12067 | 1540 This function returns the minibuffer window used for frame @var{frame}. |
1541 If @var{frame} is @code{nil}, that stands for the current frame. Note | |
1542 that the minibuffer window used by a frame need not be part of that | |
1543 frame---a frame that has no minibuffer of its own necessarily uses some | |
1544 other frame's minibuffer window. | |
6555 | 1545 @end defun |
1546 | |
1547 @c Emacs 19 feature | |
1548 @defun window-minibuffer-p window | |
1549 This function returns non-@code{nil} if @var{window} is a minibuffer window. | |
1550 @end defun | |
1551 | |
1552 It is not correct to determine whether a given window is a minibuffer by | |
1553 comparing it with the result of @code{(minibuffer-window)}, because | |
1554 there can be more than one minibuffer window if there is more than one | |
1555 frame. | |
1556 | |
1557 @defun minibuffer-window-active-p window | |
1558 This function returns non-@code{nil} if @var{window}, assumed to be | |
1559 a minibuffer window, is currently active. | |
1560 @end defun | |
1561 | |
1562 @defvar minibuffer-scroll-window | |
1563 If the value of this variable is non-@code{nil}, it should be a window | |
1564 object. When the function @code{scroll-other-window} is called in the | |
1565 minibuffer, it scrolls this window. | |
1566 @end defvar | |
1567 | |
1568 Finally, some functions and variables deal with recursive minibuffers | |
1569 (@pxref{Recursive Editing}): | |
1570 | |
1571 @defun minibuffer-depth | |
1572 This function returns the current depth of activations of the | |
1573 minibuffer, a nonnegative integer. If no minibuffers are active, it | |
1574 returns zero. | |
1575 @end defun | |
1576 | |
1577 @defopt enable-recursive-minibuffers | |
1578 If this variable is non-@code{nil}, you can invoke commands (such as | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
1579 @code{find-file}) that use minibuffers even while the minibuffer window |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
1580 is active. Such invocation produces a recursive editing level for a new |
6555 | 1581 minibuffer. The outer-level minibuffer is invisible while you are |
1582 editing the inner one. | |
1583 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
1584 If this variable is @code{nil}, you cannot invoke minibuffer |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
1585 commands when the minibuffer window is active, not even if you switch to |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
1586 another window to do it. |
6555 | 1587 @end defopt |
1588 | |
1589 @c Emacs 19 feature | |
1590 If a command name has a property @code{enable-recursive-minibuffers} | |
7221
a2c7acc3be9c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6555
diff
changeset
|
1591 that is non-@code{nil}, then the command can use the minibuffer to read |
6555 | 1592 arguments even if it is invoked from the minibuffer. The minibuffer |
12098 | 1593 command @code{next-matching-history-element} (normally @kbd{M-s} in the |
1594 minibuffer) uses this feature. |