Mercurial > emacs
comparison lispref/minibuf.texi @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 23a1cea22d13 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 @c -*-texinfo-*- | 1 @c -*-texinfo-*- |
2 @c This is part of the GNU Emacs Lisp Reference Manual. | 2 @c This is part of the GNU Emacs Lisp Reference Manual. |
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001 | 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001, 2002, |
4 @c Free Software Foundation, Inc. | 4 @c 2003, 2004, 2005 Free Software Foundation, Inc. |
5 @c See the file elisp.texi for copying conditions. | 5 @c See the file elisp.texi for copying conditions. |
6 @setfilename ../info/minibuf | 6 @setfilename ../info/minibuf |
7 @node Minibuffers, Command Loop, Read and Print, Top | 7 @node Minibuffers, Command Loop, Read and Print, Top |
8 @chapter Minibuffers | 8 @chapter Minibuffers |
9 @cindex arguments, reading | 9 @cindex arguments, reading |
10 @cindex complex arguments | 10 @cindex complex arguments |
11 @cindex minibuffer | 11 @cindex minibuffer |
12 | 12 |
13 A @dfn{minibuffer} is a special buffer that Emacs commands use to read | 13 A @dfn{minibuffer} is a special buffer that Emacs commands use to |
14 arguments more complicated than the single numeric prefix argument. | 14 read arguments more complicated than the single numeric prefix |
15 These arguments include file names, buffer names, and command names (as | 15 argument. These arguments include file names, buffer names, and |
16 in @kbd{M-x}). The minibuffer is displayed on the bottom line of the | 16 command names (as in @kbd{M-x}). The minibuffer is displayed on the |
17 frame, in the same place as the echo area, but only while it is in use | 17 bottom line of the frame, in the same place as the echo area |
18 for reading an argument. | 18 (@pxref{The Echo Area}), but only while it is in use for reading an |
19 argument. | |
19 | 20 |
20 @menu | 21 @menu |
21 * Intro to Minibuffers:: Basic information about minibuffers. | 22 * Intro to Minibuffers:: Basic information about minibuffers. |
22 * Text from Minibuffer:: How to read a straight text string. | 23 * Text from Minibuffer:: How to read a straight text string. |
23 * Object from Minibuffer:: How to read a Lisp object or expression. | 24 * Object from Minibuffer:: How to read a Lisp object or expression. |
24 * Minibuffer History:: Recording previous minibuffer inputs | 25 * Minibuffer History:: Recording previous minibuffer inputs |
25 so the user can reuse them. | 26 so the user can reuse them. |
27 * Initial Input:: Specifying initial contents for the minibuffer. | |
26 * Completion:: How to invoke and customize completion. | 28 * Completion:: How to invoke and customize completion. |
27 * Yes-or-No Queries:: Asking a question with a simple answer. | 29 * Yes-or-No Queries:: Asking a question with a simple answer. |
28 * Multiple Queries:: Asking a series of similar questions. | 30 * Multiple Queries:: Asking a series of similar questions. |
29 * Reading a Password:: Reading a password from the terminal. | 31 * Reading a Password:: Reading a password from the terminal. |
32 * Minibuffer Commands:: Commands used as key bindings in minibuffers. | |
33 * Minibuffer Contents:: How such commands access the minibuffer text. | |
34 * Minibuffer Windows:: Operating on the special minibuffer windows. | |
35 * Recursive Mini:: Whether recursive entry to minibuffer is allowed. | |
30 * Minibuffer Misc:: Various customization hooks and variables. | 36 * Minibuffer Misc:: Various customization hooks and variables. |
31 @end menu | 37 @end menu |
32 | 38 |
33 @node Intro to Minibuffers | 39 @node Intro to Minibuffers |
34 @section Introduction to Minibuffers | 40 @section Introduction to Minibuffers |
61 resize it permanently by using the window sizing commands in the frame's | 67 resize it permanently by using the window sizing commands in the frame's |
62 other window, when the minibuffer is not active. If the frame contains | 68 other window, when the minibuffer is not active. If the frame contains |
63 just a minibuffer, you can change the minibuffer's size by changing the | 69 just a minibuffer, you can change the minibuffer's size by changing the |
64 frame's size. | 70 frame's size. |
65 | 71 |
72 Use of the minibuffer reads input events, and that alters the values | |
73 of variables such as @code{this-command} and @code{last-command} | |
74 (@pxref{Command Loop Info}). Your program should bind them around the | |
75 code that uses the minibuffer, if you do not want that to change them. | |
76 | |
66 If a command uses a minibuffer while there is an active minibuffer, | 77 If a command uses a minibuffer while there is an active minibuffer, |
67 this is called a @dfn{recursive minibuffer}. The first minibuffer is | 78 this is called a @dfn{recursive minibuffer}. The first minibuffer is |
68 named @w{@samp{ *Minibuf-0*}}. Recursive minibuffers are named by | 79 named @w{@samp{ *Minibuf-0*}}. Recursive minibuffers are named by |
69 incrementing the number at the end of the name. (The names begin with a | 80 incrementing the number at the end of the name. (The names begin with a |
70 space so that they won't show up in normal buffer lists.) Of several | 81 space so that they won't show up in normal buffer lists.) Of several |
71 recursive minibuffers, the innermost (or most recently entered) is the | 82 recursive minibuffers, the innermost (or most recently entered) is the |
72 active minibuffer. We usually call this ``the'' minibuffer. You can | 83 active minibuffer. We usually call this ``the'' minibuffer. You can |
73 permit or forbid recursive minibuffers by setting the variable | 84 permit or forbid recursive minibuffers by setting the variable |
74 @code{enable-recursive-minibuffers} or by putting properties of that | 85 @code{enable-recursive-minibuffers} or by putting properties of that |
75 name on command symbols (@pxref{Minibuffer Misc}). | 86 name on command symbols (@pxref{Recursive Mini}). |
76 | 87 |
77 Like other buffers, a minibuffer may use any of several local keymaps | 88 Like other buffers, a minibuffer uses a local keymap |
78 (@pxref{Keymaps}); these contain various exit commands and in some cases | 89 (@pxref{Keymaps}) to specify special key bindings. The function that |
79 completion commands (@pxref{Completion}). | 90 invokes the minibuffer also sets up its local map according to the job |
80 | 91 to be done. @xref{Text from Minibuffer}, for the non-completion |
81 @itemize @bullet | 92 minibuffer local maps. @xref{Completion Commands}, for the minibuffer |
82 @item | 93 local maps for completion. |
83 @code{minibuffer-local-map} is for ordinary input (no completion). | |
84 | |
85 @item | |
86 @code{minibuffer-local-ns-map} is similar, except that @key{SPC} exits | |
87 just like @key{RET}. This is used mainly for Mocklisp compatibility. | |
88 | |
89 @item | |
90 @code{minibuffer-local-completion-map} is for permissive completion. | |
91 | |
92 @item | |
93 @code{minibuffer-local-must-match-map} is for strict completion and | |
94 for cautious completion. | |
95 @end itemize | |
96 | 94 |
97 When Emacs is running in batch mode, any request to read from the | 95 When Emacs is running in batch mode, any request to read from the |
98 minibuffer actually reads a line from the standard input descriptor that | 96 minibuffer actually reads a line from the standard input descriptor that |
99 was supplied when Emacs was started. | 97 was supplied when Emacs was started. |
100 | 98 |
102 @section Reading Text Strings with the Minibuffer | 100 @section Reading Text Strings with the Minibuffer |
103 | 101 |
104 Most often, the minibuffer is used to read text as a string. It can | 102 Most often, the minibuffer is used to read text as a string. It can |
105 also be used to read a Lisp object in textual form. The most basic | 103 also be used to read a Lisp object in textual form. The most basic |
106 primitive for minibuffer input is @code{read-from-minibuffer}; it can do | 104 primitive for minibuffer input is @code{read-from-minibuffer}; it can do |
107 either one. | 105 either one. There are also specialized commands for reading |
106 commands, variables, file names, etc. (@pxref{Completion}). | |
108 | 107 |
109 In most cases, you should not call minibuffer input functions in the | 108 In most cases, you should not call minibuffer input functions in the |
110 middle of a Lisp function. Instead, do all minibuffer input as part of | 109 middle of a Lisp function. Instead, do all minibuffer input as part of |
111 reading the arguments for a command, in the @code{interactive} | 110 reading the arguments for a command, in the @code{interactive} |
112 specification. @xref{Defining Commands}. | 111 specification. @xref{Defining Commands}. |
113 | 112 |
114 @defun read-from-minibuffer prompt-string &optional initial-contents keymap read hist default inherit-input-method | 113 @defun read-from-minibuffer prompt-string &optional initial-contents keymap read hist default inherit-input-method keep-all |
115 This function is the most general way to get input through the | 114 This function is the most general way to get input through the |
116 minibuffer. By default, it accepts arbitrary text and returns it as a | 115 minibuffer. By default, it accepts arbitrary text and returns it as a |
117 string; however, if @var{read} is non-@code{nil}, then it uses | 116 string; however, if @var{read} is non-@code{nil}, then it uses |
118 @code{read} to convert the text into a Lisp object (@pxref{Input | 117 @code{read} to convert the text into a Lisp object (@pxref{Input |
119 Functions}). | 118 Functions}). |
128 However, if @var{read} is non-@code{nil}, @code{read-from-minibuffer} | 127 However, if @var{read} is non-@code{nil}, @code{read-from-minibuffer} |
129 reads the text and returns the resulting Lisp object, unevaluated. | 128 reads the text and returns the resulting Lisp object, unevaluated. |
130 (@xref{Input Functions}, for information about reading.) | 129 (@xref{Input Functions}, for information about reading.) |
131 | 130 |
132 The argument @var{default} specifies a default value to make available | 131 The argument @var{default} specifies a default value to make available |
133 through the history commands. It should be a string, or @code{nil}. If | 132 through the history commands. It should be a string, or @code{nil}. |
134 @var{read} is non-@code{nil}, then @var{default} is also used as the | 133 If non-@code{nil}, the user can access it using |
135 input to @code{read}, if the user enters empty input. However, in the | 134 @code{next-history-element}, usually bound in the minibuffer to |
136 usual case (where @var{read} is @code{nil}), @code{read-from-minibuffer} | 135 @kbd{M-n}. If @var{read} is non-@code{nil}, then @var{default} is |
137 does not return @var{default} when the user enters empty input; it | 136 also used as the input to @code{read}, if the user enters empty input. |
138 returns an empty string, @code{""}. In this respect, it is different | 137 (If @var{read} is non-@code{nil} and @var{default} is @code{nil}, empty |
139 from all the other minibuffer input functions in this chapter. | 138 input results in an @code{end-of-file} error.) However, in the usual |
139 case (where @var{read} is @code{nil}), @code{read-from-minibuffer} | |
140 ignores @var{default} when the user enters empty input and returns an | |
141 empty string, @code{""}. In this respect, it is different from all | |
142 the other minibuffer input functions in this chapter. | |
140 | 143 |
141 If @var{keymap} is non-@code{nil}, that keymap is the local keymap to | 144 If @var{keymap} is non-@code{nil}, that keymap is the local keymap to |
142 use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the | 145 use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the |
143 value of @code{minibuffer-local-map} is used as the keymap. Specifying | 146 value of @code{minibuffer-local-map} is used as the keymap. Specifying |
144 a keymap is the most important way to customize the minibuffer for | 147 a keymap is the most important way to customize the minibuffer for |
157 minibuffer inherits the current input method (@pxref{Input Methods}) and | 160 minibuffer inherits the current input method (@pxref{Input Methods}) and |
158 the setting of @code{enable-multibyte-characters} (@pxref{Text | 161 the setting of @code{enable-multibyte-characters} (@pxref{Text |
159 Representations}) from whichever buffer was current before entering the | 162 Representations}) from whichever buffer was current before entering the |
160 minibuffer. | 163 minibuffer. |
161 | 164 |
162 If @var{initial-contents} is a string, @code{read-from-minibuffer} | 165 If @var{keep-all} is non-@code{nil}, even empty and duplicate inputs |
163 inserts it into the minibuffer, leaving point at the end, before the | 166 are added to the history list. |
164 user starts to edit the text. The minibuffer appears with this text as | 167 |
165 its initial contents. | 168 Use of @var{initial-contents} is mostly deprecated; we recommend using |
166 | 169 a non-@code{nil} value only in conjunction with specifying a cons cell |
167 Alternatively, @var{initial-contents} can be a cons cell of the form | 170 for @var{hist}. @xref{Initial Input}. |
168 @code{(@var{string} . @var{position})}. This means to insert | |
169 @var{string} in the minibuffer but put point @var{position} characters | |
170 from the beginning, rather than at the end. | |
171 | |
172 @strong{Usage note:} The @var{initial-contents} argument and the | |
173 @var{default} argument are two alternative features for more or less the | |
174 same job. It does not make sense to use both features in a single call | |
175 to @code{read-from-minibuffer}. In general, we recommend using | |
176 @var{default}, since this permits the user to insert the default value | |
177 when it is wanted, but does not burden the user with deleting it from | |
178 the minibuffer on other occasions. | |
179 @end defun | 171 @end defun |
180 | 172 |
181 @defun read-string prompt &optional initial history default inherit-input-method | 173 @defun read-string prompt &optional initial history default inherit-input-method |
182 This function reads a string from the minibuffer and returns it. The | 174 This function reads a string from the minibuffer and returns it. The |
183 arguments @var{prompt} and @var{initial} are used as in | 175 arguments @var{prompt}, @var{initial}, @var{history} and |
184 @code{read-from-minibuffer}. The keymap used is | 176 @var{inherit-input-method} are used as in @code{read-from-minibuffer}. |
185 @code{minibuffer-local-map}. | 177 The keymap used is @code{minibuffer-local-map}. |
186 | 178 |
187 The optional argument @var{history}, if non-nil, specifies a history | 179 The optional argument @var{default} is used as in |
188 list and optionally the initial position in the list. The optional | 180 @code{read-from-minibuffer}, except that, if non-@code{nil}, it also |
189 argument @var{default} specifies a default value to return if the user | 181 specifies a default value to return if the user enters null input. As |
190 enters null input; it should be a string. The optional argument | 182 in @code{read-from-minibuffer} it should be a string, or @code{nil}, |
191 @var{inherit-input-method} specifies whether to inherit the current | 183 which is equivalent to an empty string. |
192 buffer's input method. | |
193 | 184 |
194 This function is a simplified interface to the | 185 This function is a simplified interface to the |
195 @code{read-from-minibuffer} function: | 186 @code{read-from-minibuffer} function: |
196 | 187 |
197 @smallexample | 188 @smallexample |
199 (read-string @var{prompt} @var{initial} @var{history} @var{default} @var{inherit}) | 190 (read-string @var{prompt} @var{initial} @var{history} @var{default} @var{inherit}) |
200 @equiv{} | 191 @equiv{} |
201 (let ((value | 192 (let ((value |
202 (read-from-minibuffer @var{prompt} @var{initial} nil nil | 193 (read-from-minibuffer @var{prompt} @var{initial} nil nil |
203 @var{history} @var{default} @var{inherit}))) | 194 @var{history} @var{default} @var{inherit}))) |
204 (if (equal value "") | 195 (if (and (equal value "") @var{default}) |
205 @var{default} | 196 @var{default} |
206 value)) | 197 value)) |
207 @end group | 198 @end group |
208 @end smallexample | 199 @end smallexample |
209 @end defun | 200 @end defun |
210 | 201 |
211 @defvar minibuffer-allow-text-properties | 202 @defvar minibuffer-allow-text-properties |
212 If this variable is @code{nil}, then @code{read-from-minibuffer} strips | 203 If this variable is @code{nil}, then @code{read-from-minibuffer} strips |
213 all text properties from the minibuffer input before returning it. | 204 all text properties from the minibuffer input before returning it. |
214 Since all minibuffer input uses @code{read-from-minibuffer}, this | 205 This variable also affects @code{read-string}. However, |
215 variable applies to all minibuffer input. | 206 @code{read-no-blanks-input} (see below), as well as |
216 | 207 @code{read-minibuffer} and related functions (@pxref{Object from |
217 Note that the completion functions discard text properties unconditionally, | 208 Minibuffer,, Reading Lisp Objects With the Minibuffer}), and all |
218 regardless of the value of this variable. | 209 functions that do minibuffer input with completion, discard text |
210 properties unconditionally, regardless of the value of this variable. | |
219 @end defvar | 211 @end defvar |
220 | 212 |
221 @defvar minibuffer-local-map | 213 @defvar minibuffer-local-map |
214 @anchor{Definition of minibuffer-local-map} | |
222 This is the default local keymap for reading from the minibuffer. By | 215 This is the default local keymap for reading from the minibuffer. By |
223 default, it makes the following bindings: | 216 default, it makes the following bindings: |
224 | 217 |
225 @table @asis | 218 @table @asis |
226 @item @kbd{C-j} | 219 @item @kbd{C-j} |
231 | 224 |
232 @item @kbd{C-g} | 225 @item @kbd{C-g} |
233 @code{abort-recursive-edit} | 226 @code{abort-recursive-edit} |
234 | 227 |
235 @item @kbd{M-n} | 228 @item @kbd{M-n} |
229 @itemx @key{DOWN} | |
236 @code{next-history-element} | 230 @code{next-history-element} |
237 | 231 |
238 @item @kbd{M-p} | 232 @item @kbd{M-p} |
233 @itemx @key{UP} | |
239 @code{previous-history-element} | 234 @code{previous-history-element} |
240 | 235 |
236 @item @kbd{M-s} | |
237 @code{next-matching-history-element} | |
238 | |
241 @item @kbd{M-r} | 239 @item @kbd{M-r} |
242 @code{next-matching-history-element} | |
243 | |
244 @item @kbd{M-s} | |
245 @code{previous-matching-history-element} | 240 @code{previous-matching-history-element} |
246 @end table | 241 @end table |
247 @end defvar | 242 @end defvar |
248 | 243 |
249 @c In version 18, initial is required | 244 @c In version 18, initial is required |
258 function, and passes the value of the @code{minibuffer-local-ns-map} | 253 function, and passes the value of the @code{minibuffer-local-ns-map} |
259 keymap as the @var{keymap} argument for that function. Since the keymap | 254 keymap as the @var{keymap} argument for that function. Since the keymap |
260 @code{minibuffer-local-ns-map} does not rebind @kbd{C-q}, it @emph{is} | 255 @code{minibuffer-local-ns-map} does not rebind @kbd{C-q}, it @emph{is} |
261 possible to put a space into the string, by quoting it. | 256 possible to put a space into the string, by quoting it. |
262 | 257 |
258 This function discards text properties, regardless of the value of | |
259 @code{minibuffer-allow-text-properties}. | |
260 | |
263 @smallexample | 261 @smallexample |
264 @group | 262 @group |
265 (read-no-blanks-input @var{prompt} @var{initial}) | 263 (read-no-blanks-input @var{prompt} @var{initial}) |
266 @equiv{} | 264 @equiv{} |
267 (read-from-minibuffer @var{prompt} @var{initial} minibuffer-local-ns-map) | 265 (let (minibuffer-allow-text-properties) |
266 (read-from-minibuffer @var{prompt} @var{initial} minibuffer-local-ns-map)) | |
268 @end group | 267 @end group |
269 @end smallexample | 268 @end smallexample |
270 @end defun | 269 @end defun |
271 | 270 |
272 @defvar minibuffer-local-ns-map | 271 @defvar minibuffer-local-ns-map |
305 | 304 |
306 @smallexample | 305 @smallexample |
307 @group | 306 @group |
308 (read-minibuffer @var{prompt} @var{initial}) | 307 (read-minibuffer @var{prompt} @var{initial}) |
309 @equiv{} | 308 @equiv{} |
310 (read-from-minibuffer @var{prompt} @var{initial} nil t) | 309 (let (minibuffer-allow-text-properties) |
310 (read-from-minibuffer @var{prompt} @var{initial} nil t)) | |
311 @end group | 311 @end group |
312 @end smallexample | 312 @end smallexample |
313 | 313 |
314 Here is an example in which we supply the string @code{"(testing)"} as | 314 Here is an example in which we supply the string @code{"(testing)"} as |
315 initial input: | 315 initial input: |
403 | 403 |
404 There are many separate history lists, used for different kinds of | 404 There are many separate history lists, used for different kinds of |
405 inputs. It's the Lisp programmer's job to specify the right history | 405 inputs. It's the Lisp programmer's job to specify the right history |
406 list for each use of the minibuffer. | 406 list for each use of the minibuffer. |
407 | 407 |
408 The basic minibuffer input functions @code{read-from-minibuffer} and | 408 You specify the history list with the optional @var{hist} argument |
409 @code{completing-read} both accept an optional argument named @var{hist} | 409 to either @code{read-from-minibuffer} or @code{completing-read}. Here |
410 which is how you specify the history list. Here are the possible | 410 are the possible values for it: |
411 values: | |
412 | 411 |
413 @table @asis | 412 @table @asis |
414 @item @var{variable} | 413 @item @var{variable} |
415 Use @var{variable} (a symbol) as the history list. | 414 Use @var{variable} (a symbol) as the history list. |
416 | 415 |
417 @item (@var{variable} . @var{startpos}) | 416 @item (@var{variable} . @var{startpos}) |
418 Use @var{variable} (a symbol) as the history list, and assume that the | 417 Use @var{variable} (a symbol) as the history list, and assume that the |
419 initial history position is @var{startpos} (an integer, counting from | 418 initial history position is @var{startpos} (a nonnegative integer). |
420 zero which specifies the most recent element of the history). | 419 |
421 | 420 Specifying 0 for @var{startpos} is equivalent to just specifying the |
422 If you specify @var{startpos}, then you should also specify that element | 421 symbol @var{variable}. @code{previous-history-element} will display |
423 of the history as the initial minibuffer contents, for consistency. | 422 the most recent element of the history list in the minibuffer. If you |
423 specify a positive @var{startpos}, the minibuffer history functions | |
424 behave as if @code{(elt @var{variable} (1- @var{STARTPOS}))} were the | |
425 history element currently shown in the minibuffer. | |
426 | |
427 For consistency, you should also specify that element of the history | |
428 as the initial minibuffer contents, using the @var{initial} argument | |
429 to the minibuffer input function (@pxref{Initial Input}). | |
424 @end table | 430 @end table |
425 | 431 |
426 If you don't specify @var{hist}, then the default history list | 432 If you don't specify @var{hist}, then the default history list |
427 @code{minibuffer-history} is used. For other standard history lists, | 433 @code{minibuffer-history} is used. For other standard history lists, |
428 see below. You can also create your own history list variable; just | 434 see below. You can also create your own history list variable; just |
438 Emacs functions that add a new element to a history list can also | 444 Emacs functions that add a new element to a history list can also |
439 delete old elements if the list gets too long. The variable | 445 delete old elements if the list gets too long. The variable |
440 @code{history-length} specifies the maximum length for most history | 446 @code{history-length} specifies the maximum length for most history |
441 lists. To specify a different maximum length for a particular history | 447 lists. To specify a different maximum length for a particular history |
442 list, put the length in the @code{history-length} property of the | 448 list, put the length in the @code{history-length} property of the |
443 history list symbol. | 449 history list symbol. The variable @code{history-delete-duplicates} |
450 specifies whether to delete duplicates in history. | |
444 | 451 |
445 @defvar history-length | 452 @defvar history-length |
446 The value of this variable specifies the maximum length for all | 453 The value of this variable specifies the maximum length for all |
447 history lists that don't specify their own maximum lengths. If the | 454 history lists that don't specify their own maximum lengths. If the |
448 value is @code{t}, that means there no maximum (don't delete old | 455 value is @code{t}, that means there no maximum (don't delete old |
449 elements). | 456 elements). |
450 @end defvar | 457 @end defvar |
451 | 458 |
459 @defvar history-delete-duplicates | |
460 If the value of this variable is @code{t}, that means when adding a | |
461 new history element, all previous identical elements are deleted. | |
462 @end defvar | |
463 | |
452 Here are some of the standard minibuffer history list variables: | 464 Here are some of the standard minibuffer history list variables: |
453 | 465 |
454 @defvar minibuffer-history | 466 @defvar minibuffer-history |
455 The default history list for minibuffer history input. | 467 The default history list for minibuffer history input. |
456 @end defvar | 468 @end defvar |
481 @end defvar | 493 @end defvar |
482 | 494 |
483 @defvar read-expression-history | 495 @defvar read-expression-history |
484 A history list for arguments that are Lisp expressions to evaluate. | 496 A history list for arguments that are Lisp expressions to evaluate. |
485 @end defvar | 497 @end defvar |
498 | |
499 @node Initial Input | |
500 @section Initial Input | |
501 | |
502 Several of the functions for minibuffer input have an argument called | |
503 @var{initial} or @var{initial-contents}. This is a mostly-deprecated | |
504 feature for specifiying that the minibuffer should start out with | |
505 certain text, instead of empty as usual. | |
506 | |
507 If @var{initial} is a string, the minibuffer starts out containing the | |
508 text of the string, with point at the end, when the user starts to | |
509 edit the text. If the user simply types @key{RET} to exit the | |
510 minibuffer, it will use the initial input string to determine the | |
511 value to return. | |
512 | |
513 @strong{We discourage use of a non-@code{nil} value for | |
514 @var{initial}}, because initial input is an intrusive interface. | |
515 History lists and default values provide a much more convenient method | |
516 to offer useful default inputs to the user. | |
517 | |
518 There is just one situation where you should specify a string for an | |
519 @var{initial} argument. This is when you specify a cons cell for the | |
520 @var{hist} or @var{history} argument. @xref{Minibuffer History}. | |
521 | |
522 @var{initial} can also be a cons cell of the form @code{(@var{string} | |
523 . @var{position})}. This means to insert @var{string} in the | |
524 minibuffer but put point at @var{position} within the string's text. | |
525 | |
526 As a historical accident, @var{position} was implemented | |
527 inconsistently in different functions. In @code{completing-read}, | |
528 @var{position}'s value is interpreted as origin-zero; that is, a value | |
529 of 0 means the beginning of the string, 1 means after the first | |
530 character, etc. In @code{read-minibuffer}, and the other | |
531 non-completion minibuffer input functions that support this argument, | |
532 1 means the beginning of the string 2 means after the first character, | |
533 etc. | |
534 | |
535 Use of a cons cell as the value for @var{initial} arguments is | |
536 deprecated in user code. | |
486 | 537 |
487 @node Completion | 538 @node Completion |
488 @section Completion | 539 @section Completion |
489 @cindex completion | 540 @cindex completion |
490 | 541 |
518 * Minibuffer Completion:: Invoking the minibuffer with completion. | 569 * Minibuffer Completion:: Invoking the minibuffer with completion. |
519 * Completion Commands:: Minibuffer commands that do completion. | 570 * Completion Commands:: Minibuffer commands that do completion. |
520 * High-Level Completion:: Convenient special cases of completion | 571 * High-Level Completion:: Convenient special cases of completion |
521 (reading buffer name, file name, etc.) | 572 (reading buffer name, file name, etc.) |
522 * Reading File Names:: Using completion to read file names. | 573 * Reading File Names:: Using completion to read file names. |
523 * Programmed Completion:: Finding the completions for a given file name. | 574 * Programmed Completion:: Writing your own completion-function. |
524 @end menu | 575 @end menu |
525 | 576 |
526 @node Basic Completion | 577 @node Basic Completion |
527 @subsection Basic Completion Functions | 578 @subsection Basic Completion Functions |
528 | 579 |
529 The two functions @code{try-completion} and @code{all-completions} | 580 The completion functions @code{try-completion}, |
530 have nothing in themselves to do with minibuffers. We describe them in | 581 @code{all-completions} and @code{test-completion} have nothing in |
531 this chapter so as to keep them near the higher-level completion | 582 themselves to do with minibuffers. We describe them in this chapter |
532 features that do use the minibuffer. | 583 so as to keep them near the higher-level completion features that do |
584 use the minibuffer. | |
533 | 585 |
534 @defun try-completion string collection &optional predicate | 586 @defun try-completion string collection &optional predicate |
535 This function returns the longest common substring of all possible | 587 This function returns the longest common substring of all possible |
536 completions of @var{string} in @var{collection}. The value of | 588 completions of @var{string} in @var{collection}. The value of |
537 @var{collection} must be an alist, an obarray, or a function that | 589 @var{collection} must be a list of strings or symbols, an alist, an |
538 implements a virtual set of strings (see below). | 590 obarray, a hash table, or a function that implements a virtual set of |
591 strings (see below). | |
539 | 592 |
540 Completion compares @var{string} against each of the permissible | 593 Completion compares @var{string} against each of the permissible |
541 completions specified by @var{collection}; if the beginning of the | 594 completions specified by @var{collection}; if the beginning of the |
542 permissible completion equals @var{string}, it matches. If no permissible | 595 permissible completion equals @var{string}, it matches. If no permissible |
543 completions match, @code{try-completion} returns @code{nil}. If only | 596 completions match, @code{try-completion} returns @code{nil}. If only |
545 @code{try-completion} returns @code{t}. Otherwise, the value is the | 598 @code{try-completion} returns @code{t}. Otherwise, the value is the |
546 longest initial sequence common to all the permissible completions that | 599 longest initial sequence common to all the permissible completions that |
547 match. | 600 match. |
548 | 601 |
549 If @var{collection} is an alist (@pxref{Association Lists}), the | 602 If @var{collection} is an alist (@pxref{Association Lists}), the |
550 @sc{car}s of the alist elements form the set of permissible completions. | 603 permissible completions are the elements of the alist that are either |
604 strings, symbols, or conses whose @sc{car} is a string or symbol. | |
605 Symbols are converted to strings using @code{symbol-name}. | |
606 Other elements of the alist are ignored. (Remember that in Emacs Lisp, | |
607 the elements of alists do not @emph{have} to be conses.) As all | |
608 elements of the alist can be strings, this case actually includes | |
609 lists of strings or symbols, even though we usually do not think of | |
610 such lists as alists. | |
551 | 611 |
552 @cindex obarray in completion | 612 @cindex obarray in completion |
553 If @var{collection} is an obarray (@pxref{Creating Symbols}), the names | 613 If @var{collection} is an obarray (@pxref{Creating Symbols}), the names |
554 of all symbols in the obarray form the set of permissible completions. The | 614 of all symbols in the obarray form the set of permissible completions. The |
555 global variable @code{obarray} holds an obarray containing the names of | 615 global variable @code{obarray} holds an obarray containing the names of |
557 | 617 |
558 Note that the only valid way to make a new obarray is to create it | 618 Note that the only valid way to make a new obarray is to create it |
559 empty and then add symbols to it one by one using @code{intern}. | 619 empty and then add symbols to it one by one using @code{intern}. |
560 Also, you cannot intern a given symbol in more than one obarray. | 620 Also, you cannot intern a given symbol in more than one obarray. |
561 | 621 |
562 If the argument @var{predicate} is non-@code{nil}, then it must be a | 622 If @var{collection} is a hash table, then the keys that are strings |
563 function of one argument. It is used to test each possible match, and | 623 are the possible completions. Other keys are ignored. |
564 the match is accepted only if @var{predicate} returns non-@code{nil}. | |
565 The argument given to @var{predicate} is either a cons cell from the alist | |
566 (the @sc{car} of which is a string) or else it is a symbol (@emph{not} a | |
567 symbol name) from the obarray. | |
568 | 624 |
569 You can also use a symbol that is a function as @var{collection}. Then | 625 You can also use a symbol that is a function as @var{collection}. Then |
570 the function is solely responsible for performing completion; | 626 the function is solely responsible for performing completion; |
571 @code{try-completion} returns whatever this function returns. The | 627 @code{try-completion} returns whatever this function returns. The |
572 function is called with three arguments: @var{string}, @var{predicate} | 628 function is called with three arguments: @var{string}, @var{predicate} |
573 and @code{nil}. (The reason for the third argument is so that the same | 629 and @code{nil}. (The reason for the third argument is so that the same |
574 function can be used in @code{all-completions} and do the appropriate | 630 function can be used in @code{all-completions} and do the appropriate |
575 thing in either case.) @xref{Programmed Completion}. | 631 thing in either case.) @xref{Programmed Completion}. |
576 | 632 |
633 If the argument @var{predicate} is non-@code{nil}, then it must be a | |
634 function of one argument, unless @var{collection} is a hash table, in | |
635 which case it should be a function of two arguments. It is used to | |
636 test each possible match, and the match is accepted only if | |
637 @var{predicate} returns non-@code{nil}. The argument given to | |
638 @var{predicate} is either a string or a cons cell (the @sc{car} of | |
639 which is a string) from the alist, or a symbol (@emph{not} a symbol | |
640 name) from the obarray. If @var{collection} is a hash table, | |
641 @var{predicate} is called with two arguments, the string key and the | |
642 associated value. | |
643 | |
644 In addition, to be acceptable, a completion must also match all the | |
645 regular expressions in @code{completion-regexp-list}. (Unless | |
646 @var{collection} is a function, in which case that function has to | |
647 handle @code{completion-regexp-list} itself.) | |
648 | |
577 In the first of the following examples, the string @samp{foo} is | 649 In the first of the following examples, the string @samp{foo} is |
578 matched by three of the alist @sc{car}s. All of the matches begin with | 650 matched by three of the alist @sc{car}s. All of the matches begin with |
579 the characters @samp{fooba}, so that is the result. In the second | 651 the characters @samp{fooba}, so that is the result. In the second |
580 example, there is only one possible match, and it is exact, so the value | 652 example, there is only one possible match, and it is exact, so the value |
581 is @code{t}. | 653 is @code{t}. |
626 @end smallexample | 698 @end smallexample |
627 @end defun | 699 @end defun |
628 | 700 |
629 @defun all-completions string collection &optional predicate nospace | 701 @defun all-completions string collection &optional predicate nospace |
630 This function returns a list of all possible completions of | 702 This function returns a list of all possible completions of |
631 @var{string}. The arguments to this function (aside from @var{nospace}) | 703 @var{string}. The arguments to this function (aside from |
632 are the same as those of @code{try-completion}. If @var{nospace} is | 704 @var{nospace}) are the same as those of @code{try-completion}. Also, |
633 non-@code{nil}, completions that start with a space are ignored unless | 705 this function uses @code{completion-regexp-list} in the same way that |
634 @var{string} also starts with a space. | 706 @code{try-completion} does. The optional argument @var{nospace} only |
707 matters if @var{string} is the empty string. In that case, if | |
708 @var{nospace} is non-@code{nil}, completions that start with a space | |
709 are ignored. | |
635 | 710 |
636 If @var{collection} is a function, it is called with three arguments: | 711 If @var{collection} is a function, it is called with three arguments: |
637 @var{string}, @var{predicate} and @code{t}; then @code{all-completions} | 712 @var{string}, @var{predicate} and @code{t}; then @code{all-completions} |
638 returns whatever the function returns. @xref{Programmed Completion}. | 713 returns whatever the function returns. @xref{Programmed Completion}. |
639 | 714 |
655 @result{} ("foobar1" "foobar2") | 730 @result{} ("foobar1" "foobar2") |
656 @end group | 731 @end group |
657 @end smallexample | 732 @end smallexample |
658 @end defun | 733 @end defun |
659 | 734 |
735 @defun test-completion string collection &optional predicate | |
736 @anchor{Definition of test-completion} | |
737 This function returns non-@code{nil} if @var{string} is a valid | |
738 completion possibility specified by @var{collection} and | |
739 @var{predicate}. The arguments are the same as in | |
740 @code{try-completion}. For instance, if @var{collection} is a list of | |
741 strings, this is true if @var{string} appears in the list and | |
742 @var{predicate} is satisfied. | |
743 | |
744 @code{test-completion} uses @code{completion-regexp-list} in the same | |
745 way that @code{try-completion} does. | |
746 | |
747 If @var{predicate} is non-@code{nil} and if @var{collection} contains | |
748 several strings that are equal to each other, as determined by | |
749 @code{compare-strings} according to @code{completion-ignore-case}, | |
750 then @var{predicate} should accept either all or none of them. | |
751 Otherwise, the return value of @code{test-completion} is essentially | |
752 unpredictable. | |
753 | |
754 If @var{collection} is a function, it is called with three arguments, | |
755 the values @var{string}, @var{predicate} and @code{lambda}; whatever | |
756 it returns, @code{test-completion} returns in turn. | |
757 @end defun | |
758 | |
660 @defvar completion-ignore-case | 759 @defvar completion-ignore-case |
661 If the value of this variable is | 760 If the value of this variable is non-@code{nil}, Emacs does not |
662 non-@code{nil}, Emacs does not consider case significant in completion. | 761 consider case significant in completion. |
663 @end defvar | 762 @end defvar |
763 | |
764 @defvar completion-regexp-list | |
765 This is a list of regular expressions. The completion functions only | |
766 consider a completion acceptable if it matches all regular expressions | |
767 in this list, with @code{case-fold-search} (@pxref{Searching and Case}) | |
768 bound to the value of @code{completion-ignore-case}. | |
769 @end defvar | |
770 | |
771 @defmac lazy-completion-table var fun | |
772 This macro provides a way to initialize the variable @var{var} as a | |
773 collection for completion in a lazy way, not computing its actual | |
774 contents until they are first needed. You use this macro to produce a | |
775 value that you store in @var{var}. The actual computation of the | |
776 proper value is done the first time you do completion using @var{var}. | |
777 It is done by calling @var{fun} with no arguments. The | |
778 value @var{fun} returns becomes the permanent value of @var{var}. | |
779 | |
780 Here is an example of use: | |
781 | |
782 @smallexample | |
783 (defvar foo (lazy-completion-table foo make-my-alist)) | |
784 @end smallexample | |
785 @end defmac | |
664 | 786 |
665 @node Minibuffer Completion | 787 @node Minibuffer Completion |
666 @subsection Completion and the Minibuffer | 788 @subsection Completion and the Minibuffer |
667 | 789 |
668 This section describes the basic interface for reading from the | 790 This section describes the basic interface for reading from the |
672 This function reads a string in the minibuffer, assisting the user by | 794 This function reads a string in the minibuffer, assisting the user by |
673 providing completion. It activates the minibuffer with prompt | 795 providing completion. It activates the minibuffer with prompt |
674 @var{prompt}, which must be a string. | 796 @var{prompt}, which must be a string. |
675 | 797 |
676 The actual completion is done by passing @var{collection} and | 798 The actual completion is done by passing @var{collection} and |
677 @var{predicate} to the function @code{try-completion}. This happens in | 799 @var{predicate} to the function @code{try-completion}. This happens |
678 certain commands bound in the local keymaps used for completion. | 800 in certain commands bound in the local keymaps used for completion. |
801 Some of these commands also call @code{test-completion}. Thus, if | |
802 @var{predicate} is non-@code{nil}, it should be compatible with | |
803 @var{collection} and @code{completion-ignore-case}. @xref{Definition | |
804 of test-completion}. | |
679 | 805 |
680 If @var{require-match} is @code{nil}, the exit commands work regardless | 806 If @var{require-match} is @code{nil}, the exit commands work regardless |
681 of the input in the minibuffer. If @var{require-match} is @code{t}, the | 807 of the input in the minibuffer. If @var{require-match} is @code{t}, the |
682 usual minibuffer exit commands won't exit unless the input completes to | 808 usual minibuffer exit commands won't exit unless the input completes to |
683 an element of @var{collection}. If @var{require-match} is neither | 809 an element of @var{collection}. If @var{require-match} is neither |
684 @code{nil} nor @code{t}, then the exit commands won't exit unless the | 810 @code{nil} nor @code{t}, then the exit commands won't exit unless the |
685 input already in the buffer matches an element of @var{collection}. | 811 input already in the buffer matches an element of @var{collection}. |
686 | 812 |
687 However, empty input is always permitted, regardless of the value of | 813 However, empty input is always permitted, regardless of the value of |
688 @var{require-match}; in that case, @code{completing-read} returns | 814 @var{require-match}; in that case, @code{completing-read} returns |
689 @var{default}. The value of @var{default} (if non-@code{nil}) is also | 815 @var{default}, or @code{""}, if @var{default} is @code{nil}. The |
690 available to the user through the history commands. | 816 value of @var{default} (if non-@code{nil}) is also available to the |
691 | 817 user through the history commands. |
692 The user can exit with null input by typing @key{RET} with an empty | 818 |
693 minibuffer. Then @code{completing-read} returns @code{""}. This is how | 819 The function @code{completing-read} uses |
694 the user requests whatever default the command uses for the value being | 820 @code{minibuffer-local-completion-map} as the keymap if |
695 read. The user can return using @key{RET} in this way regardless of the | 821 @var{require-match} is @code{nil}, and uses |
696 value of @var{require-match}, and regardless of whether the empty string | |
697 is included in @var{collection}. | |
698 | |
699 The function @code{completing-read} works by calling | |
700 @code{read-minibuffer}. It uses @code{minibuffer-local-completion-map} | |
701 as the keymap if @var{require-match} is @code{nil}, and uses | |
702 @code{minibuffer-local-must-match-map} if @var{require-match} is | 822 @code{minibuffer-local-must-match-map} if @var{require-match} is |
703 non-@code{nil}. @xref{Completion Commands}. | 823 non-@code{nil}. @xref{Completion Commands}. |
704 | 824 |
705 The argument @var{hist} specifies which history list variable to use for | 825 The argument @var{hist} specifies which history list variable to use for |
706 saving the input and for minibuffer history commands. It defaults to | 826 saving the input and for minibuffer history commands. It defaults to |
707 @code{minibuffer-history}. @xref{Minibuffer History}. | 827 @code{minibuffer-history}. @xref{Minibuffer History}. |
708 | 828 |
709 If @var{initial} is non-@code{nil}, @code{completing-read} inserts it | 829 The argument @var{initial} is mostly deprecated; we recommend using a |
710 into the minibuffer as part of the input. Then it allows the user to | 830 non-@code{nil} value only in conjunction with specifying a cons cell |
711 edit the input, providing several commands to attempt completion. | 831 for @var{hist}. @xref{Initial Input}. For default input, use |
712 In most cases, we recommend using @var{default}, and not @var{initial}. | 832 @var{default} instead. |
713 | |
714 @strong{We discourage use of a non-@code{nil} value for | |
715 @var{initial}}, because it is an intrusive interface. The history | |
716 list feature (which did not exist when we introduced @var{initial}) | |
717 offers a far more convenient and general way for the user to get the | |
718 default and edit it, and it is always available. | |
719 | 833 |
720 If the argument @var{inherit-input-method} is non-@code{nil}, then the | 834 If the argument @var{inherit-input-method} is non-@code{nil}, then the |
721 minibuffer inherits the current input method (@pxref{Input | 835 minibuffer inherits the current input method (@pxref{Input |
722 Methods}) and the setting of @code{enable-multibyte-characters} | 836 Methods}) and the setting of @code{enable-multibyte-characters} |
723 (@pxref{Text Representations}) from whichever buffer was current before | 837 (@pxref{Text Representations}) from whichever buffer was current before |
724 entering the minibuffer. | 838 entering the minibuffer. |
725 | 839 |
726 Completion ignores case when comparing the input against the possible | 840 If the built-in variable @code{completion-ignore-case} is |
727 matches, if the built-in variable @code{completion-ignore-case} is | 841 non-@code{nil}, completion ignores case when comparing the input |
728 non-@code{nil}. @xref{Basic Completion}. | 842 against the possible matches. @xref{Basic Completion}. In this mode |
843 of operation, @var{predicate} must also ignore case, or you will get | |
844 surprising results. | |
729 | 845 |
730 Here's an example of using @code{completing-read}: | 846 Here's an example of using @code{completing-read}: |
731 | 847 |
732 @smallexample | 848 @smallexample |
733 @group | 849 @group |
749 | 865 |
750 @noindent | 866 @noindent |
751 If the user then types @kbd{@key{DEL} @key{DEL} b @key{RET}}, | 867 If the user then types @kbd{@key{DEL} @key{DEL} b @key{RET}}, |
752 @code{completing-read} returns @code{barfoo}. | 868 @code{completing-read} returns @code{barfoo}. |
753 | 869 |
754 The @code{completing-read} function binds three variables to pass | 870 The @code{completing-read} function binds variables to pass |
755 information to the commands that actually do completion. These | 871 information to the commands that actually do completion. |
756 variables are @code{minibuffer-completion-table}, | 872 They are described in the following section. |
757 @code{minibuffer-completion-predicate} and | |
758 @code{minibuffer-completion-confirm}. For more information about them, | |
759 see @ref{Completion Commands}. | |
760 @end defun | 873 @end defun |
761 | 874 |
762 @node Completion Commands | 875 @node Completion Commands |
763 @subsection Minibuffer Commands that Do Completion | 876 @subsection Minibuffer Commands that Do Completion |
764 | 877 |
765 This section describes the keymaps, commands and user options used in | 878 This section describes the keymaps, commands and user options used |
766 the minibuffer to do completion. | 879 in the minibuffer to do completion. The description refers to the |
767 | 880 situation when Partial Completion mode is disabled (as it is by |
768 @defvar minibuffer-local-completion-map | 881 default). When enabled, this minor mode uses its own alternatives to |
769 @code{completing-read} uses this value as the local keymap when an | 882 some of the commands described below. @xref{Completion Options,,, |
770 exact match of one of the completions is not required. By default, this | 883 emacs, The GNU Emacs Manual}, for a short description of Partial |
771 keymap makes the following bindings: | 884 Completion mode. |
772 | |
773 @table @asis | |
774 @item @kbd{?} | |
775 @code{minibuffer-completion-help} | |
776 | |
777 @item @key{SPC} | |
778 @code{minibuffer-complete-word} | |
779 | |
780 @item @key{TAB} | |
781 @code{minibuffer-complete} | |
782 @end table | |
783 | |
784 @noindent | |
785 with other characters bound as in @code{minibuffer-local-map} | |
786 (@pxref{Text from Minibuffer}). | |
787 @end defvar | |
788 | |
789 @defvar minibuffer-local-must-match-map | |
790 @code{completing-read} uses this value as the local keymap when an | |
791 exact match of one of the completions is required. Therefore, no keys | |
792 are bound to @code{exit-minibuffer}, the command that exits the | |
793 minibuffer unconditionally. By default, this keymap makes the following | |
794 bindings: | |
795 | |
796 @table @asis | |
797 @item @kbd{?} | |
798 @code{minibuffer-completion-help} | |
799 | |
800 @item @key{SPC} | |
801 @code{minibuffer-complete-word} | |
802 | |
803 @item @key{TAB} | |
804 @code{minibuffer-complete} | |
805 | |
806 @item @kbd{C-j} | |
807 @code{minibuffer-complete-and-exit} | |
808 | |
809 @item @key{RET} | |
810 @code{minibuffer-complete-and-exit} | |
811 @end table | |
812 | |
813 @noindent | |
814 with other characters bound as in @code{minibuffer-local-map}. | |
815 @end defvar | |
816 | 885 |
817 @defvar minibuffer-completion-table | 886 @defvar minibuffer-completion-table |
818 The value of this variable is the alist or obarray used for completion | 887 The value of this variable is the collection used for completion in |
819 in the minibuffer. This is the global variable that contains what | 888 the minibuffer. This is the global variable that contains what |
820 @code{completing-read} passes to @code{try-completion}. It is used by | 889 @code{completing-read} passes to @code{try-completion}. It is used by |
821 minibuffer completion commands such as @code{minibuffer-complete-word}. | 890 minibuffer completion commands such as @code{minibuffer-complete-word}. |
822 @end defvar | 891 @end defvar |
823 | 892 |
824 @defvar minibuffer-completion-predicate | 893 @defvar minibuffer-completion-predicate |
825 This variable's value is the predicate that @code{completing-read} | 894 This variable's value is the predicate that @code{completing-read} |
826 passes to @code{try-completion}. The variable is also used by the other | 895 passes to @code{try-completion}. The variable is also used by the other |
827 minibuffer completion functions. | 896 minibuffer completion functions. |
897 @end defvar | |
898 | |
899 @defvar minibuffer-completion-confirm | |
900 When the value of this variable is non-@code{nil}, Emacs asks for | |
901 confirmation of a completion before exiting the minibuffer. | |
902 @code{completing-read} binds this variable, and the function | |
903 @code{minibuffer-complete-and-exit} checks the value before exiting. | |
828 @end defvar | 904 @end defvar |
829 | 905 |
830 @deffn Command minibuffer-complete-word | 906 @deffn Command minibuffer-complete-word |
831 This function completes the minibuffer contents by at most a single | 907 This function completes the minibuffer contents by at most a single |
832 word. Even if the minibuffer contents have only one completion, | 908 word. Even if the minibuffer contents have only one completion, |
844 @code{minibuffer-completion-confirm} is @code{nil}. If confirmation | 920 @code{minibuffer-completion-confirm} is @code{nil}. If confirmation |
845 @emph{is} required, it is given by repeating this command | 921 @emph{is} required, it is given by repeating this command |
846 immediately---the command is programmed to work without confirmation | 922 immediately---the command is programmed to work without confirmation |
847 when run twice in succession. | 923 when run twice in succession. |
848 @end deffn | 924 @end deffn |
849 | |
850 @defvar minibuffer-completion-confirm | |
851 When the value of this variable is non-@code{nil}, Emacs asks for | |
852 confirmation of a completion before exiting the minibuffer. The | |
853 function @code{minibuffer-complete-and-exit} checks the value of this | |
854 variable before it exits. | |
855 @end defvar | |
856 | 925 |
857 @deffn Command minibuffer-completion-help | 926 @deffn Command minibuffer-completion-help |
858 This function creates a list of the possible completions of the | 927 This function creates a list of the possible completions of the |
859 current minibuffer contents. It works by calling @code{all-completions} | 928 current minibuffer contents. It works by calling @code{all-completions} |
860 using the value of the variable @code{minibuffer-completion-table} as | 929 using the value of the variable @code{minibuffer-completion-table} as |
862 @code{minibuffer-completion-predicate} as the @var{predicate} argument. | 931 @code{minibuffer-completion-predicate} as the @var{predicate} argument. |
863 The list of completions is displayed as text in a buffer named | 932 The list of completions is displayed as text in a buffer named |
864 @samp{*Completions*}. | 933 @samp{*Completions*}. |
865 @end deffn | 934 @end deffn |
866 | 935 |
867 @defun display-completion-list completions | 936 @defun display-completion-list completions &optional common-substring |
868 This function displays @var{completions} to the stream in | 937 This function displays @var{completions} to the stream in |
869 @code{standard-output}, usually a buffer. (@xref{Read and Print}, for more | 938 @code{standard-output}, usually a buffer. (@xref{Read and Print}, for more |
870 information about streams.) The argument @var{completions} is normally | 939 information about streams.) The argument @var{completions} is normally |
871 a list of completions just returned by @code{all-completions}, but it | 940 a list of completions just returned by @code{all-completions}, but it |
872 does not have to be. Each element may be a symbol or a string, either | 941 does not have to be. Each element may be a symbol or a string, either |
873 of which is simply printed, or a list of two strings, which is printed | 942 of which is simply printed. It can also be a list of two strings, |
874 as if the strings were concatenated. | 943 which is printed as if the strings were concatenated. The first of |
944 the two strings is the actual completion, the second string serves as | |
945 annotation. | |
946 | |
947 The argument @var{common-substring} is the prefix that is common to | |
948 all the completions. With normal Emacs completion, it is usually the | |
949 same as the string that was completed. @code{display-completion-list} | |
950 uses this to highlight text in the completion list for better visual | |
951 feedback. This is not needed in the minibuffer; for minibuffer | |
952 completion, you can pass @code{nil}. | |
875 | 953 |
876 This function is called by @code{minibuffer-completion-help}. The | 954 This function is called by @code{minibuffer-completion-help}. The |
877 most common way to use it is together with | 955 most common way to use it is together with |
878 @code{with-output-to-temp-buffer}, like this: | 956 @code{with-output-to-temp-buffer}, like this: |
879 | 957 |
880 @example | 958 @example |
881 (with-output-to-temp-buffer "*Completions*" | 959 (with-output-to-temp-buffer "*Completions*" |
882 (display-completion-list | 960 (display-completion-list |
883 (all-completions (buffer-string) my-alist))) | 961 (all-completions (buffer-string) my-alist) |
962 (buffer-string))) | |
884 @end example | 963 @end example |
885 @end defun | 964 @end defun |
886 | 965 |
887 @defopt completion-auto-help | 966 @defopt completion-auto-help |
888 If this variable is non-@code{nil}, the completion commands | 967 If this variable is non-@code{nil}, the completion commands |
889 automatically display a list of possible completions whenever nothing | 968 automatically display a list of possible completions whenever nothing |
890 can be completed because the next character is not uniquely determined. | 969 can be completed because the next character is not uniquely determined. |
891 @end defopt | 970 @end defopt |
971 | |
972 @defvar minibuffer-local-completion-map | |
973 @code{completing-read} uses this value as the local keymap when an | |
974 exact match of one of the completions is not required. By default, this | |
975 keymap makes the following bindings: | |
976 | |
977 @table @asis | |
978 @item @kbd{?} | |
979 @code{minibuffer-completion-help} | |
980 | |
981 @item @key{SPC} | |
982 @code{minibuffer-complete-word} | |
983 | |
984 @item @key{TAB} | |
985 @code{minibuffer-complete} | |
986 @end table | |
987 | |
988 @noindent | |
989 with other characters bound as in @code{minibuffer-local-map} | |
990 (@pxref{Definition of minibuffer-local-map}). | |
991 @end defvar | |
992 | |
993 @defvar minibuffer-local-must-match-map | |
994 @code{completing-read} uses this value as the local keymap when an | |
995 exact match of one of the completions is required. Therefore, no keys | |
996 are bound to @code{exit-minibuffer}, the command that exits the | |
997 minibuffer unconditionally. By default, this keymap makes the following | |
998 bindings: | |
999 | |
1000 @table @asis | |
1001 @item @kbd{?} | |
1002 @code{minibuffer-completion-help} | |
1003 | |
1004 @item @key{SPC} | |
1005 @code{minibuffer-complete-word} | |
1006 | |
1007 @item @key{TAB} | |
1008 @code{minibuffer-complete} | |
1009 | |
1010 @item @kbd{C-j} | |
1011 @code{minibuffer-complete-and-exit} | |
1012 | |
1013 @item @key{RET} | |
1014 @code{minibuffer-complete-and-exit} | |
1015 @end table | |
1016 | |
1017 @noindent | |
1018 with other characters bound as in @code{minibuffer-local-map}. | |
1019 @end defvar | |
1020 | |
1021 @defvar minibuffer-local-filename-completion-map | |
1022 This is like @code{minibuffer-local-completion-map} | |
1023 except that it does not bind @key{SPC}. This keymap is used by the | |
1024 function @code{read-file-name}. | |
1025 @end defvar | |
1026 | |
1027 @defvar minibuffer-local-must-match-filename-map | |
1028 This is like @code{minibuffer-local-must-match-map} | |
1029 except that it does not bind @key{SPC}. This keymap is used by the | |
1030 function @code{read-file-name}. | |
1031 @end defvar | |
892 | 1032 |
893 @node High-Level Completion | 1033 @node High-Level Completion |
894 @subsection High-Level Completion Functions | 1034 @subsection High-Level Completion Functions |
895 | 1035 |
896 This section describes the higher-level convenient functions for | 1036 This section describes the higher-level convenient functions for |
906 The argument @var{default} is the default name to use, the value to | 1046 The argument @var{default} is the default name to use, the value to |
907 return if the user exits with an empty minibuffer. If non-@code{nil}, | 1047 return if the user exits with an empty minibuffer. If non-@code{nil}, |
908 it should be a string or a buffer. It is mentioned in the prompt, but | 1048 it should be a string or a buffer. It is mentioned in the prompt, but |
909 is not inserted in the minibuffer as initial input. | 1049 is not inserted in the minibuffer as initial input. |
910 | 1050 |
1051 The argument @var{prompt} should be a string ending with a colon and a | |
1052 space. If @var{default} is non-@code{nil}, the function inserts it in | |
1053 @var{prompt} before the colon to follow the convention for reading from | |
1054 the minibuffer with a default value (@pxref{Programming Tips}). | |
1055 | |
911 If @var{existing} is non-@code{nil}, then the name specified must be | 1056 If @var{existing} is non-@code{nil}, then the name specified must be |
912 that of an existing buffer. The usual commands to exit the minibuffer | 1057 that of an existing buffer. The usual commands to exit the minibuffer |
913 do not exit if the text is not valid, and @key{RET} does completion to | 1058 do not exit if the text is not valid, and @key{RET} does completion to |
914 attempt to find a valid name. (However, @var{default} is not checked | 1059 attempt to find a valid name. If @var{existing} is neither @code{nil} |
915 for validity; it is returned, whatever it is, if the user exits with the | 1060 nor @code{t}, confirmation is required after completion. (However, |
916 minibuffer empty.) | 1061 @var{default} is not checked for validity; it is returned, whatever it |
1062 is, if the user exits with the minibuffer empty.) | |
917 | 1063 |
918 In the following example, the user enters @samp{minibuffer.t}, and | 1064 In the following example, the user enters @samp{minibuffer.t}, and |
919 then types @key{RET}. The argument @var{existing} is @code{t}, and the | 1065 then types @key{RET}. The argument @var{existing} is @code{t}, and the |
920 only buffer name starting with the given input is | 1066 only buffer name starting with the given input is |
921 @samp{minibuffer.texi}, so that name is the value. | 1067 @samp{minibuffer.texi}, so that name is the value. |
922 | 1068 |
923 @example | 1069 @example |
924 (read-buffer "Buffer name? " "foo" t) | 1070 (read-buffer "Buffer name: " "foo" t) |
925 @group | 1071 @group |
926 ;; @r{After evaluation of the preceding expression,} | 1072 ;; @r{After evaluation of the preceding expression,} |
927 ;; @r{the following prompt appears,} | 1073 ;; @r{the following prompt appears,} |
928 ;; @r{with an empty minibuffer:} | 1074 ;; @r{with an empty minibuffer:} |
929 @end group | 1075 @end group |
930 | 1076 |
931 @group | 1077 @group |
932 ---------- Buffer: Minibuffer ---------- | 1078 ---------- Buffer: Minibuffer ---------- |
933 Buffer name? (default foo) @point{} | 1079 Buffer name (default foo): @point{} |
934 ---------- Buffer: Minibuffer ---------- | 1080 ---------- Buffer: Minibuffer ---------- |
935 @end group | 1081 @end group |
936 | 1082 |
937 @group | 1083 @group |
938 ;; @r{The user types @kbd{minibuffer.t @key{RET}}.} | 1084 ;; @r{The user types @kbd{minibuffer.t @key{RET}}.} |
957 | 1103 |
958 The argument @var{default} specifies what to return if the user enters | 1104 The argument @var{default} specifies what to return if the user enters |
959 null input. It can be a symbol or a string; if it is a string, | 1105 null input. It can be a symbol or a string; if it is a string, |
960 @code{read-command} interns it before returning it. If @var{default} is | 1106 @code{read-command} interns it before returning it. If @var{default} is |
961 @code{nil}, that means no default has been specified; then if the user | 1107 @code{nil}, that means no default has been specified; then if the user |
962 enters null input, the return value is @code{nil}. | 1108 enters null input, the return value is @code{(intern "")}, that is, a |
1109 symbol whose name is an empty string. | |
963 | 1110 |
964 @example | 1111 @example |
965 (read-command "Command name? ") | 1112 (read-command "Command name? ") |
966 | 1113 |
967 @group | 1114 @group |
995 @end group | 1142 @end group |
996 @end example | 1143 @end example |
997 @end defun | 1144 @end defun |
998 | 1145 |
999 @defun read-variable prompt &optional default | 1146 @defun read-variable prompt &optional default |
1147 @anchor{Definition of read-variable} | |
1000 This function reads the name of a user variable and returns it as a | 1148 This function reads the name of a user variable and returns it as a |
1001 symbol. | 1149 symbol. |
1002 | 1150 |
1003 The argument @var{default} specifies what to return if the user enters | 1151 The argument @var{default} specifies what to return if the user enters |
1004 null input. It can be a symbol or a string; if it is a string, | 1152 null input. It can be a symbol or a string; if it is a string, |
1005 @code{read-variable} interns it before returning it. If @var{default} | 1153 @code{read-variable} interns it before returning it. If @var{default} |
1006 is @code{nil}, that means no default has been specified; then if the | 1154 is @code{nil}, that means no default has been specified; then if the |
1007 user enters null input, the return value is @code{nil}. | 1155 user enters null input, the return value is @code{(intern "")}. |
1008 | 1156 |
1009 @example | 1157 @example |
1010 @group | 1158 @group |
1011 (read-variable "Variable name? ") | 1159 (read-variable "Variable name? ") |
1012 | 1160 |
1049 | 1197 |
1050 Here is another high-level completion function, designed for reading a | 1198 Here is another high-level completion function, designed for reading a |
1051 file name. It provides special features including automatic insertion | 1199 file name. It provides special features including automatic insertion |
1052 of the default directory. | 1200 of the default directory. |
1053 | 1201 |
1054 @defun read-file-name prompt &optional directory default existing initial | 1202 @defun read-file-name prompt &optional directory default existing initial predicate |
1055 This function reads a file name in the minibuffer, prompting with | 1203 This function reads a file name in the minibuffer, prompting with |
1056 @var{prompt} and providing completion. If @var{default} is | 1204 @var{prompt} and providing completion. |
1057 non-@code{nil}, then the function returns @var{default} if the user just | |
1058 types @key{RET}. @var{default} is not checked for validity; it is | |
1059 returned, whatever it is, if the user exits with the minibuffer empty. | |
1060 | 1205 |
1061 If @var{existing} is non-@code{nil}, then the user must specify the name | 1206 If @var{existing} is non-@code{nil}, then the user must specify the name |
1062 of an existing file; @key{RET} performs completion to make the name | 1207 of an existing file; @key{RET} performs completion to make the name |
1063 valid if possible, and then refuses to exit if it is not valid. If the | 1208 valid if possible, and then refuses to exit if it is not valid. If the |
1064 value of @var{existing} is neither @code{nil} nor @code{t}, then | 1209 value of @var{existing} is neither @code{nil} nor @code{t}, then |
1065 @key{RET} also requires confirmation after completion. If | 1210 @key{RET} also requires confirmation after completion. If |
1066 @var{existing} is @code{nil}, then the name of a nonexistent file is | 1211 @var{existing} is @code{nil}, then the name of a nonexistent file is |
1067 acceptable. | 1212 acceptable. |
1068 | 1213 |
1214 The function @code{read-file-name} uses | |
1215 @code{minibuffer-local-filename-completion-map} as the keymap if | |
1216 @var{existing} is @code{nil}, and uses | |
1217 @code{minibuffer-local-must-match-filename-map} if @var{existing} is | |
1218 non-@code{nil}. @xref{Completion Commands}. | |
1219 | |
1069 The argument @var{directory} specifies the directory to use for | 1220 The argument @var{directory} specifies the directory to use for |
1070 completion of relative file names. If @code{insert-default-directory} | 1221 completion of relative file names. It should be an absolute directory |
1071 is non-@code{nil}, @var{directory} is also inserted in the minibuffer as | 1222 name. If @code{insert-default-directory} is non-@code{nil}, |
1072 initial input. It defaults to the current buffer's value of | 1223 @var{directory} is also inserted in the minibuffer as initial input. |
1073 @code{default-directory}. | 1224 It defaults to the current buffer's value of @code{default-directory}. |
1074 | 1225 |
1075 @c Emacs 19 feature | 1226 @c Emacs 19 feature |
1076 If you specify @var{initial}, that is an initial file name to insert in | 1227 If you specify @var{initial}, that is an initial file name to insert |
1077 the buffer (after @var{directory}, if that is inserted). In this | 1228 in the buffer (after @var{directory}, if that is inserted). In this |
1078 case, point goes at the beginning of @var{initial}. The default for | 1229 case, point goes at the beginning of @var{initial}. The default for |
1079 @var{initial} is @code{nil}---don't insert any file name. To see what | 1230 @var{initial} is @code{nil}---don't insert any file name. To see what |
1080 @var{initial} does, try the command @kbd{C-x C-v}. @strong{Note:} we | 1231 @var{initial} does, try the command @kbd{C-x C-v}. @strong{Please |
1081 recommend using @var{default} rather than @var{initial} in most cases. | 1232 note:} we recommend using @var{default} rather than @var{initial} in |
1233 most cases. | |
1234 | |
1235 If @var{default} is non-@code{nil}, then the function returns | |
1236 @var{default} if the user exits the minibuffer with the same non-empty | |
1237 contents that @code{read-file-name} inserted initially. The initial | |
1238 minibuffer contents are always non-empty if | |
1239 @code{insert-default-directory} is non-@code{nil}, as it is by | |
1240 default. @var{default} is not checked for validity, regardless of the | |
1241 value of @var{existing}. However, if @var{existing} is | |
1242 non-@code{nil}, the initial minibuffer contents should be a valid file | |
1243 (or directory) name. Otherwise @code{read-file-name} attempts | |
1244 completion if the user exits without any editing, and does not return | |
1245 @var{default}. @var{default} is also available through the history | |
1246 commands. | |
1247 | |
1248 If @var{default} is @code{nil}, @code{read-file-name} tries to find a | |
1249 substitute default to use in its place, which it treats in exactly the | |
1250 same way as if it had been specified explicitly. If @var{default} is | |
1251 @code{nil}, but @var{initial} is non-@code{nil}, then the default is | |
1252 the absolute file name obtained from @var{directory} and | |
1253 @var{initial}. If both @var{default} and @var{initial} are @code{nil} | |
1254 and the buffer is visiting a file, @code{read-file-name} uses the | |
1255 absolute file name of that file as default. If the buffer is not | |
1256 visiting a file, then there is no default. In that case, if the user | |
1257 types @key{RET} without any editing, @code{read-file-name} simply | |
1258 returns the pre-inserted contents of the minibuffer. | |
1259 | |
1260 If the user types @key{RET} in an empty minibuffer, this function | |
1261 returns an empty string, regardless of the value of @var{existing}. | |
1262 This is, for instance, how the user can make the current buffer visit | |
1263 no file using @code{M-x set-visited-file-name}. | |
1264 | |
1265 If @var{predicate} is non-@code{nil}, it specifies a function of one | |
1266 argument that decides which file names are acceptable completion | |
1267 possibilities. A file name is an acceptable value if @var{predicate} | |
1268 returns non-@code{nil} for it. | |
1269 | |
1270 @code{read-file-name} does not automatically expand file names. You | |
1271 must call @code{expand-file-name} yourself if an absolute file name is | |
1272 required. | |
1082 | 1273 |
1083 Here is an example: | 1274 Here is an example: |
1084 | 1275 |
1085 @example | 1276 @example |
1086 @group | 1277 @group |
1112 @noindent | 1303 @noindent |
1113 If the user types @key{RET}, @code{read-file-name} returns the file name | 1304 If the user types @key{RET}, @code{read-file-name} returns the file name |
1114 as the string @code{"/gp/gnu/elisp/manual.texi"}. | 1305 as the string @code{"/gp/gnu/elisp/manual.texi"}. |
1115 @end defun | 1306 @end defun |
1116 | 1307 |
1308 @defvar read-file-name-function | |
1309 If non-@code{nil}, this should be a function that accepts the same | |
1310 arguments as @code{read-file-name}. When @code{read-file-name} is | |
1311 called, it calls this function with the supplied arguments instead of | |
1312 doing its usual work. | |
1313 @end defvar | |
1314 | |
1315 @defvar read-file-name-completion-ignore-case | |
1316 If this variable is non-@code{nil}, @code{read-file-name} ignores case | |
1317 when performing completion. | |
1318 @end defvar | |
1319 | |
1320 @defun read-directory-name prompt &optional directory default existing initial | |
1321 This function is like @code{read-file-name} but allows only directory | |
1322 names as completion possibilities. | |
1323 | |
1324 If @var{default} is @code{nil} and @var{initial} is non-@code{nil}, | |
1325 @code{read-directory-name} constructs a substitute default by | |
1326 combining @var{directory} (or the current buffer's default directory | |
1327 if @var{directory} is @code{nil}) and @var{initial}. If both | |
1328 @var{default} and @var{initial} are @code{nil}, this function uses | |
1329 @var{directory} as substitute default, or the current buffer's default | |
1330 directory if @var{directory} is @code{nil}. | |
1331 @end defun | |
1332 | |
1117 @defopt insert-default-directory | 1333 @defopt insert-default-directory |
1118 This variable is used by @code{read-file-name}. Its value controls | 1334 This variable is used by @code{read-file-name}, and thus, indirectly, |
1119 whether @code{read-file-name} starts by placing the name of the default | 1335 by most commands reading file names. (This includes all commands that |
1120 directory in the minibuffer, plus the initial file name if any. If the | 1336 use the code letters @samp{f} or @samp{F} in their interactive form. |
1121 value of this variable is @code{nil}, then @code{read-file-name} does | 1337 @xref{Interactive Codes,, Code Characters for interactive}.) Its |
1122 not place any initial input in the minibuffer (unless you specify | 1338 value controls whether @code{read-file-name} starts by placing the |
1123 initial input with the @var{initial} argument). In that case, the | 1339 name of the default directory in the minibuffer, plus the initial file |
1124 default directory is still used for completion of relative file names, | 1340 name if any. If the value of this variable is @code{nil}, then |
1125 but is not displayed. | 1341 @code{read-file-name} does not place any initial input in the |
1342 minibuffer (unless you specify initial input with the @var{initial} | |
1343 argument). In that case, the default directory is still used for | |
1344 completion of relative file names, but is not displayed. | |
1345 | |
1346 If this variable is @code{nil} and the initial minibuffer contents are | |
1347 empty, the user may have to explicitly fetch the next history element | |
1348 to access a default value. If the variable is non-@code{nil}, the | |
1349 initial minibuffer contents are always non-empty and the user can | |
1350 always request a default value by immediately typing @key{RET} in an | |
1351 unedited minibuffer. (See above.) | |
1126 | 1352 |
1127 For example: | 1353 For example: |
1128 | 1354 |
1129 @example | 1355 @example |
1130 @group | 1356 @group |
1201 @code{t} specifies @code{all-completions}. The completion function | 1427 @code{t} specifies @code{all-completions}. The completion function |
1202 should return a list of all possible completions of the specified | 1428 should return a list of all possible completions of the specified |
1203 string. | 1429 string. |
1204 | 1430 |
1205 @item | 1431 @item |
1206 @code{lambda} specifies a test for an exact match. The completion | 1432 @code{lambda} specifies @code{test-completion}. The completion |
1207 function should return @code{t} if the specified string is an exact | 1433 function should return @code{t} if the specified string is an exact |
1208 match for some possibility; @code{nil} otherwise. | 1434 match for some possibility; @code{nil} otherwise. |
1209 @end itemize | 1435 @end itemize |
1210 | 1436 |
1211 It would be consistent and clean for completion functions to allow | 1437 It would be consistent and clean for completion functions to allow |
1212 lambda expressions (lists that are functions) as well as function | 1438 lambda expressions (lists that are functions) as well as function |
1213 symbols as @var{collection}, but this is impossible. Lists as | 1439 symbols as @var{collection}, but this is impossible. Lists as |
1214 completion tables are already assigned another meaning---as alists. It | 1440 completion tables already have other meanings, and it would be |
1215 would be unreliable to fail to handle an alist normally because it is | 1441 unreliable to treat one differently just because it is also a possible |
1216 also a possible function. So you must arrange for any function you wish | 1442 function. So you must arrange for any function you wish to use for |
1217 to use for completion to be encapsulated in a symbol. | 1443 completion to be encapsulated in a symbol. |
1218 | 1444 |
1219 Emacs uses programmed completion when completing file names. | 1445 Emacs uses programmed completion when completing file names. |
1220 @xref{File Name Completion}. | 1446 @xref{File Name Completion}. |
1447 | |
1448 @defmac dynamic-completion-table function | |
1449 This macro is a convenient way to write a function that can act as | |
1450 programmed completion function. The argument @var{function} should be | |
1451 a function that takes one argument, a string, and returns an alist of | |
1452 possible completions of it. You can think of | |
1453 @code{dynamic-completion-table} as a transducer between that interface | |
1454 and the interface for programmed completion functions. | |
1455 @end defmac | |
1221 | 1456 |
1222 @node Yes-or-No Queries | 1457 @node Yes-or-No Queries |
1223 @section Yes-or-No Queries | 1458 @section Yes-or-No Queries |
1224 @cindex asking the user questions | 1459 @cindex asking the user questions |
1225 @cindex querying the user | 1460 @cindex querying the user |
1476 The optional argument @var{default} specifies the default password to | 1711 The optional argument @var{default} specifies the default password to |
1477 return if the user enters empty input. If @var{default} is @code{nil}, | 1712 return if the user enters empty input. If @var{default} is @code{nil}, |
1478 then @code{read-passwd} returns the null string in that case. | 1713 then @code{read-passwd} returns the null string in that case. |
1479 @end defun | 1714 @end defun |
1480 | 1715 |
1481 @node Minibuffer Misc | 1716 @node Minibuffer Commands |
1482 @section Minibuffer Miscellany | 1717 @section Minibuffer Commands |
1483 | 1718 |
1484 This section describes some basic functions and variables related to | 1719 This section describes some commands meant for use in the |
1485 minibuffers. | 1720 minibuffer. |
1486 | 1721 |
1487 @deffn Command exit-minibuffer | 1722 @deffn Command exit-minibuffer |
1488 This command exits the active minibuffer. It is normally bound to | 1723 This command exits the active minibuffer. It is normally bound to |
1489 keys in minibuffer local keymaps. | 1724 keys in minibuffer local keymaps. |
1490 @end deffn | 1725 @end deffn |
1515 This command replaces the minibuffer contents with the value of the | 1750 This command replaces the minibuffer contents with the value of the |
1516 @var{n}th next (newer) history element that matches @var{pattern} (a | 1751 @var{n}th next (newer) history element that matches @var{pattern} (a |
1517 regular expression). | 1752 regular expression). |
1518 @end deffn | 1753 @end deffn |
1519 | 1754 |
1520 @defun minibuffer-prompt | 1755 @node Minibuffer Windows |
1521 This function returns the prompt string of the currently active | 1756 @section Minibuffer Windows |
1522 minibuffer. If no minibuffer is active, it returns @code{nil}. | 1757 |
1523 @end defun | 1758 These functions access and select minibuffer windows |
1524 | 1759 and test whether they are active. |
1525 @defun minibuffer-prompt-end | |
1526 @tindex minibuffer-prompt-end | |
1527 This function, available starting in Emacs 21, returns the current | |
1528 position of the end of the minibuffer prompt, if a minibuffer is | |
1529 current. Otherwise, it returns the minimum valid buffer position. | |
1530 @end defun | |
1531 | |
1532 @defun minibuffer-contents | |
1533 @tindex minibuffer-contents | |
1534 This function, available starting in Emacs 21, returns the editable | |
1535 contents of the minibuffer (that is, everything except the prompt) as | |
1536 a string, if a minibuffer is current. Otherwise, it returns the | |
1537 entire contents of the current buffer. | |
1538 @end defun | |
1539 | |
1540 @defun minibuffer-contents-no-properties | |
1541 @tindex minibuffer-contents-no-properties | |
1542 This is like @code{minibuffer-contents}, except that it does not copy text | |
1543 properties, just the characters themselves. @xref{Text Properties}. | |
1544 @end defun | |
1545 | |
1546 @defun delete-minibuffer-contents | |
1547 @tindex delete-minibuffer-contents | |
1548 This function, available starting in Emacs 21, erases the editable | |
1549 contents of the minibuffer (that is, everything except the prompt), if | |
1550 a minibuffer is current. Otherwise, it erases the entire buffer. | |
1551 @end defun | |
1552 | |
1553 @defun minibuffer-prompt-width | |
1554 This function returns the current display-width of the minibuffer | |
1555 prompt, if a minibuffer is current. Otherwise, it returns zero. | |
1556 @end defun | |
1557 | |
1558 @defvar minibuffer-setup-hook | |
1559 This is a normal hook that is run whenever the minibuffer is entered. | |
1560 @xref{Hooks}. | |
1561 @end defvar | |
1562 | |
1563 @defvar minibuffer-exit-hook | |
1564 This is a normal hook that is run whenever the minibuffer is exited. | |
1565 @xref{Hooks}. | |
1566 @end defvar | |
1567 | |
1568 @defvar minibuffer-help-form | |
1569 The current value of this variable is used to rebind @code{help-form} | |
1570 locally inside the minibuffer (@pxref{Help Functions}). | |
1571 @end defvar | |
1572 | 1760 |
1573 @defun active-minibuffer-window | 1761 @defun active-minibuffer-window |
1574 This function returns the currently active minibuffer window, or | 1762 This function returns the currently active minibuffer window, or |
1575 @code{nil} if none is currently active. | 1763 @code{nil} if none is currently active. |
1576 @end defun | 1764 @end defun |
1577 | 1765 |
1578 @defun minibuffer-window &optional frame | 1766 @defun minibuffer-window &optional frame |
1767 @anchor{Definition of minibuffer-window} | |
1579 This function returns the minibuffer window used for frame @var{frame}. | 1768 This function returns the minibuffer window used for frame @var{frame}. |
1580 If @var{frame} is @code{nil}, that stands for the current frame. Note | 1769 If @var{frame} is @code{nil}, that stands for the current frame. Note |
1581 that the minibuffer window used by a frame need not be part of that | 1770 that the minibuffer window used by a frame need not be part of that |
1582 frame---a frame that has no minibuffer of its own necessarily uses some | 1771 frame---a frame that has no minibuffer of its own necessarily uses some |
1583 other frame's minibuffer window. | 1772 other frame's minibuffer window. |
1584 @end defun | 1773 @end defun |
1585 | 1774 |
1775 @defun set-minibuffer-window window | |
1776 This function specifies @var{window} as the minibuffer window to use. | |
1777 This affects where the minibuffer is displayed if you put text in it | |
1778 without invoking the usual minibuffer commands. It has no effect on | |
1779 the usual minibuffer input functions because they all start by | |
1780 choosing the minibuffer window according to the current frame. | |
1781 @end defun | |
1782 | |
1586 @c Emacs 19 feature | 1783 @c Emacs 19 feature |
1587 @defun window-minibuffer-p window | 1784 @defun window-minibuffer-p &optional window |
1588 This function returns non-@code{nil} if @var{window} is a minibuffer window. | 1785 This function returns non-@code{nil} if @var{window} is a minibuffer |
1786 window. | |
1787 @var{window} defaults to the selected window. | |
1589 @end defun | 1788 @end defun |
1590 | 1789 |
1591 It is not correct to determine whether a given window is a minibuffer by | 1790 It is not correct to determine whether a given window is a minibuffer by |
1592 comparing it with the result of @code{(minibuffer-window)}, because | 1791 comparing it with the result of @code{(minibuffer-window)}, because |
1593 there can be more than one minibuffer window if there is more than one | 1792 there can be more than one minibuffer window if there is more than one |
1596 @defun minibuffer-window-active-p window | 1795 @defun minibuffer-window-active-p window |
1597 This function returns non-@code{nil} if @var{window}, assumed to be | 1796 This function returns non-@code{nil} if @var{window}, assumed to be |
1598 a minibuffer window, is currently active. | 1797 a minibuffer window, is currently active. |
1599 @end defun | 1798 @end defun |
1600 | 1799 |
1601 @defvar minibuffer-scroll-window | 1800 @node Minibuffer Contents |
1602 If the value of this variable is non-@code{nil}, it should be a window | 1801 @section Minibuffer Contents |
1603 object. When the function @code{scroll-other-window} is called in the | 1802 |
1604 minibuffer, it scrolls this window. | 1803 These functions access the minibuffer prompt and contents. |
1605 @end defvar | 1804 |
1606 | 1805 @defun minibuffer-prompt |
1607 Finally, some functions and variables deal with recursive minibuffers | 1806 This function returns the prompt string of the currently active |
1807 minibuffer. If no minibuffer is active, it returns @code{nil}. | |
1808 @end defun | |
1809 | |
1810 @defun minibuffer-prompt-end | |
1811 @tindex minibuffer-prompt-end | |
1812 This function returns the current | |
1813 position of the end of the minibuffer prompt, if a minibuffer is | |
1814 current. Otherwise, it returns the minimum valid buffer position. | |
1815 @end defun | |
1816 | |
1817 @defun minibuffer-prompt-width | |
1818 This function returns the current display-width of the minibuffer | |
1819 prompt, if a minibuffer is current. Otherwise, it returns zero. | |
1820 @end defun | |
1821 | |
1822 @defun minibuffer-contents | |
1823 @tindex minibuffer-contents | |
1824 This function returns the editable | |
1825 contents of the minibuffer (that is, everything except the prompt) as | |
1826 a string, if a minibuffer is current. Otherwise, it returns the | |
1827 entire contents of the current buffer. | |
1828 @end defun | |
1829 | |
1830 @defun minibuffer-contents-no-properties | |
1831 @tindex minibuffer-contents-no-properties | |
1832 This is like @code{minibuffer-contents}, except that it does not copy text | |
1833 properties, just the characters themselves. @xref{Text Properties}. | |
1834 @end defun | |
1835 | |
1836 @defun minibuffer-completion-contents | |
1837 @tindex minibuffer-completion-contents | |
1838 This is like @code{minibuffer-contents}, except that it returns only | |
1839 the contents before point. That is the part that completion commands | |
1840 operate on. @xref{Minibuffer Completion}. | |
1841 @end defun | |
1842 | |
1843 @defun delete-minibuffer-contents | |
1844 @tindex delete-minibuffer-contents | |
1845 This function erases the editable contents of the minibuffer (that is, | |
1846 everything except the prompt), if a minibuffer is current. Otherwise, | |
1847 it erases the entire current buffer. | |
1848 @end defun | |
1849 | |
1850 @node Recursive Mini | |
1851 @section Recursive Minibuffers | |
1852 | |
1853 These functions and variables deal with recursive minibuffers | |
1608 (@pxref{Recursive Editing}): | 1854 (@pxref{Recursive Editing}): |
1609 | 1855 |
1610 @defun minibuffer-depth | 1856 @defun minibuffer-depth |
1611 This function returns the current depth of activations of the | 1857 This function returns the current depth of activations of the |
1612 minibuffer, a nonnegative integer. If no minibuffers are active, it | 1858 minibuffer, a nonnegative integer. If no minibuffers are active, it |
1626 @end defopt | 1872 @end defopt |
1627 | 1873 |
1628 @c Emacs 19 feature | 1874 @c Emacs 19 feature |
1629 If a command name has a property @code{enable-recursive-minibuffers} | 1875 If a command name has a property @code{enable-recursive-minibuffers} |
1630 that is non-@code{nil}, then the command can use the minibuffer to read | 1876 that is non-@code{nil}, then the command can use the minibuffer to read |
1631 arguments even if it is invoked from the minibuffer. The minibuffer | 1877 arguments even if it is invoked from the minibuffer. A command can |
1632 command @code{next-matching-history-element} (normally @kbd{M-s} in the | 1878 also achieve this by binding @code{enable-recursive-minibuffers} |
1633 minibuffer) uses this feature. | 1879 to @code{t} in the interactive declaration (@pxref{Using Interactive}). |
1880 The minibuffer command @code{next-matching-history-element} (normally | |
1881 @kbd{M-s} in the minibuffer) does the latter. | |
1882 | |
1883 @node Minibuffer Misc | |
1884 @section Minibuffer Miscellany | |
1885 | |
1886 @defun minibufferp &optional buffer-or-name | |
1887 This function returns non-@code{nil} if @var{buffer-or-name} is a | |
1888 minibuffer. If @var{buffer-or-name} is omitted, it tests the current | |
1889 buffer. | |
1890 @end defun | |
1891 | |
1892 @defvar minibuffer-setup-hook | |
1893 This is a normal hook that is run whenever the minibuffer is entered. | |
1894 @xref{Hooks}. | |
1895 @end defvar | |
1896 | |
1897 @defvar minibuffer-exit-hook | |
1898 This is a normal hook that is run whenever the minibuffer is exited. | |
1899 @xref{Hooks}. | |
1900 @end defvar | |
1901 | |
1902 @defvar minibuffer-help-form | |
1903 @anchor{Definition of minibuffer-help-form} | |
1904 The current value of this variable is used to rebind @code{help-form} | |
1905 locally inside the minibuffer (@pxref{Help Functions}). | |
1906 @end defvar | |
1907 | |
1908 @defvar minibuffer-scroll-window | |
1909 @anchor{Definition of minibuffer-scroll-window} | |
1910 If the value of this variable is non-@code{nil}, it should be a window | |
1911 object. When the function @code{scroll-other-window} is called in the | |
1912 minibuffer, it scrolls this window. | |
1913 @end defvar | |
1914 | |
1915 @defun minibuffer-selected-window | |
1916 This function returns the window which was selected when the | |
1917 minibuffer was entered. If selected window is not a minibuffer | |
1918 window, it returns @code{nil}. | |
1919 @end defun | |
1920 | |
1921 @defopt max-mini-window-height | |
1922 This variable specifies the maximum height for resizing minibuffer | |
1923 windows. If a float, it specifies a fraction of the height of the | |
1924 frame. If an integer, it specifies a number of lines. | |
1925 @end defopt | |
1926 | |
1927 @defun minibuffer-message string | |
1928 This function displays @var{string} temporarily at the end of the | |
1929 minibuffer text, for two seconds, or until the next input event | |
1930 arrives, whichever comes first. | |
1931 @end defun | |
1932 | |
1933 @ignore | |
1934 arch-tag: bba7f945-9078-477f-a2ce-18818a6e1218 | |
1935 @end ignore |