]> code.delx.au - gnu-emacs/blob - man/mini.texi
Typo, copyright fix.
[gnu-emacs] / man / mini.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 86, 87, 93, 94, 95, 1997 Free Software Foundation, Inc.
3 @c See file emacs.texi for copying conditions.
4 @node Minibuffer, M-x, Basic, Top
5 @chapter The Minibuffer
6 @cindex minibuffer
7
8 The @dfn{minibuffer} is the facility used by Emacs commands to read
9 arguments more complicated than a single number. Minibuffer arguments
10 can be file names, buffer names, Lisp function names, Emacs command
11 names, Lisp expressions, and many other things, depending on the command
12 reading the argument. You can use the usual Emacs editing commands in
13 the minibuffer to edit the argument text.
14
15 @cindex prompt
16 When the minibuffer is in use, it appears in the echo area, and the
17 terminal's cursor moves there. The beginning of the minibuffer line
18 displays a @dfn{prompt} which says what kind of input you should supply and
19 how it will be used. Often this prompt is derived from the name of the
20 command that the argument is for. The prompt normally ends with a colon.
21
22 @cindex default argument
23 Sometimes a @dfn{default argument} appears in parentheses after the
24 colon; it too is part of the prompt. The default will be used as the
25 argument value if you enter an empty argument (for example, just type
26 @key{RET}). For example, commands that read buffer names always show a
27 default, which is the name of the buffer that will be used if you type
28 just @key{RET}.
29
30 The simplest way to enter a minibuffer argument is to type the text
31 you want, terminated by @key{RET} which exits the minibuffer. You can
32 cancel the command that wants the argument, and get out of the
33 minibuffer, by typing @kbd{C-g}.
34
35 Since the minibuffer uses the screen space of the echo area, it can
36 conflict with other ways Emacs customarily uses the echo area. Here is how
37 Emacs handles such conflicts:
38
39 @itemize @bullet
40 @item
41 If a command gets an error while you are in the minibuffer, this does
42 not cancel the minibuffer. However, the echo area is needed for the
43 error message and therefore the minibuffer itself is hidden for a
44 while. It comes back after a few seconds, or as soon as you type
45 anything.
46
47 @item
48 If in the minibuffer you use a command whose purpose is to print a
49 message in the echo area, such as @kbd{C-x =}, the message is printed
50 normally, and the minibuffer is hidden for a while. It comes back
51 after a few seconds, or as soon as you type anything.
52
53 @item
54 Echoing of keystrokes does not take place while the minibuffer is in
55 use.
56 @end itemize
57
58 @menu
59 * File: Minibuffer File. Entering file names with the minibuffer.
60 * Edit: Minibuffer Edit. How to edit in the minibuffer.
61 * Completion:: An abbreviation facility for minibuffer input.
62 * Minibuffer History:: Reusing recent minibuffer arguments.
63 * Repetition:: Re-executing commands that used the minibuffer.
64 @end menu
65
66 @node Minibuffer File
67 @section Minibuffers for File Names
68
69 Sometimes the minibuffer starts out with text in it. For example, when
70 you are supposed to give a file name, the minibuffer starts out containing
71 the @dfn{default directory}, which ends with a slash. This is to inform
72 you which directory the file will be found in if you do not specify a
73 directory.
74
75 @c Separate paragraph to clean up ugly pagebreak--rms
76 @need 1500
77 For example, the minibuffer might start out with these contents:
78
79 @example
80 Find File: /u2/emacs/src/
81 @end example
82
83 @noindent
84 where @samp{Find File:@: } is the prompt. Typing @kbd{buffer.c}
85 specifies the file @file{/u2/emacs/src/buffer.c}. To find files in
86 nearby directories, use @kbd{..}; thus, if you type
87 @kbd{../lisp/simple.el}, you will get the file named
88 @file{/u2/emacs/lisp/simple.el}. Alternatively, you can kill with
89 @kbd{M-@key{DEL}} the directory names you don't want (@pxref{Words}).
90
91 If you don't want any of the default, you can kill it with @kbd{C-a
92 C-k}. But you don't need to kill the default; you can simply ignore it.
93 Insert an absolute file name, one starting with a slash or a tilde,
94 after the default directory. For example, to specify the file
95 @file{/etc/termcap}, just insert that name, giving these minibuffer
96 contents:
97
98 @example
99 Find File: /u2/emacs/src//etc/termcap
100 @end example
101
102 @noindent
103 @cindex // in file name
104 @cindex double slash in file name
105 @cindex slashes repeated in file name
106 GNU Emacs gives a special meaning to a double slash (which is not
107 normally a useful thing to write): it means, ``ignore everything before
108 the second slash in the pair.'' Thus, @samp{/u2/emacs/src/} is ignored
109 in the example above, and you get the file @file{/etc/termcap}.
110
111 If you set @code{insert-default-directory} to @code{nil}, the default
112 directory is not inserted in the minibuffer. This way, the minibuffer
113 starts out empty. But the name you type, if relative, is still
114 interpreted with respect to the same default directory.
115
116 @node Minibuffer Edit
117 @section Editing in the Minibuffer
118
119 The minibuffer is an Emacs buffer (albeit a peculiar one), and the usual
120 Emacs commands are available for editing the text of an argument you are
121 entering.
122
123 Since @key{RET} in the minibuffer is defined to exit the minibuffer,
124 you can't use it to insert a newline in the minibuffer. To do that,
125 type @kbd{C-o} or @kbd{C-q C-j}. (Recall that a newline is really the
126 character control-J.)
127
128 The minibuffer has its own window which always has space on the screen
129 but acts as if it were not there when the minibuffer is not in use. When
130 the minibuffer is in use, its window is just like the others; you can
131 switch to another window with @kbd{C-x o}, edit text in other windows and
132 perhaps even visit more files, before returning to the minibuffer to submit
133 the argument. You can kill text in another window, return to the
134 minibuffer window, and then yank the text to use it in the argument.
135 @xref{Windows}.
136
137 @cindex height of minibuffer
138 @cindex size of minibuffer
139 @cindex growing minibuffer
140 @cindex resizing minibuffer
141 @vindex max-mini-window-height
142 There are some restrictions on the use of the minibuffer window,
143 however. You cannot switch buffers in it---the minibuffer and its
144 window are permanently attached. Also, you cannot split or kill the
145 minibuffer window. But you can make it taller in the normal fashion
146 with @kbd{C-x ^}. The minibuffer window expands vertically as necessary
147 to hold the text that you put in the minibuffer. Customize the variable
148 @code{max-mini-window-height} to control the maximum height for resizing
149 the minibuffer window.
150
151 @vindex minibuffer-scroll-overlap
152 Scrolling works specially in the minibuffer window. When the
153 minibuffer is just one line high, and it contains a long line of text
154 that won't fit on the screen, scrolling automatically maintains an
155 overlap of a certain number of characters from one continuation line to
156 the next. The variable @code{minibuffer-scroll-overlap} specifies how
157 many characters of overlap; the default is 20.
158
159 If while in the minibuffer you issue a command that displays help text
160 of any sort in another window, you can use the @kbd{C-M-v} command while
161 in the minibuffer to scroll the help text. This lasts until you exit
162 the minibuffer. This feature is especially useful if a completing
163 minibuffer gives you a list of possible completions. @xref{Other Window}.
164
165 @vindex enable-recursive-minibuffers
166 Emacs normally disallows most commands that use the minibuffer while
167 the minibuffer is active. This rule is to prevent recursive minibuffers
168 from confusing novice users. If you want to be able to use such
169 commands in the minibuffer, set the variable
170 @code{enable-recursive-minibuffers} to a non-@code{nil} value.
171
172 @node Completion
173 @section Completion
174 @cindex completion
175
176 For certain kinds of arguments, you can use @dfn{completion} to enter
177 the argument value. Completion means that you type part of the
178 argument, then Emacs visibly fills in the rest, or as much as
179 can be determined from the part you have typed.
180
181 When completion is available, certain keys---@key{TAB}, @key{RET}, and
182 @key{SPC}---are rebound to complete the text present in the minibuffer
183 into a longer string that it stands for, by matching it against a set of
184 @dfn{completion alternatives} provided by the command reading the
185 argument. @kbd{?} is defined to display a list of possible completions
186 of what you have inserted.
187
188 For example, when @kbd{M-x} uses the minibuffer to read the name of a
189 command, it provides a list of all available Emacs command names to
190 complete against. The completion keys match the text in the minibuffer
191 against all the command names, find any additional name characters
192 implied by the ones already present in the minibuffer, and add those
193 characters to the ones you have given. This is what makes it possible
194 to type @kbd{M-x ins @key{SPC} b @key{RET}} instead of @kbd{M-x
195 insert-buffer @key{RET}} (for example).
196
197 Case is normally significant in completion, because it is significant
198 in most of the names that you can complete (buffer names, file names and
199 command names). Thus, @samp{fo} does not complete to @samp{Foo}.
200 Completion does ignore case distinctions for certain arguments in which
201 case does not matter.
202
203 @menu
204 * Example: Completion Example.
205 * Commands: Completion Commands.
206 * Strict Completion::
207 * Options: Completion Options.
208 @end menu
209
210 @node Completion Example
211 @subsection Completion Example
212
213 @kindex TAB @r{(completion)}
214 @findex minibuffer-complete
215 A concrete example may help here. If you type @kbd{M-x au @key{TAB}},
216 the @key{TAB} looks for alternatives (in this case, command names) that
217 start with @samp{au}. There are several, including
218 @code{auto-fill-mode} and @code{auto-save-mode}---but they are all the
219 same as far as @code{auto-}, so the @samp{au} in the minibuffer changes
220 to @samp{auto-}.@refill
221
222 If you type @key{TAB} again immediately, there are multiple
223 possibilities for the very next character---it could be any of
224 @samp{cfilrs}---so no more characters are added; instead, @key{TAB}
225 displays a list of all possible completions in another window.
226
227 If you go on to type @kbd{f @key{TAB}}, this @key{TAB} sees
228 @samp{auto-f}. The only command name starting this way is
229 @code{auto-fill-mode}, so completion fills in the rest of that. You now
230 have @samp{auto-fill-mode} in the minibuffer after typing just @kbd{au
231 @key{TAB} f @key{TAB}}. Note that @key{TAB} has this effect because in
232 the minibuffer it is bound to the command @code{minibuffer-complete}
233 when completion is available.
234
235 @node Completion Commands
236 @subsection Completion Commands
237
238 Here is a list of the completion commands defined in the minibuffer
239 when completion is available.
240
241 @table @kbd
242 @item @key{TAB}
243 Complete the text in the minibuffer as much as possible
244 (@code{minibuffer-complete}).
245 @item @key{SPC}
246 Complete the minibuffer text, but don't go beyond one word
247 (@code{minibuffer-complete-word}).
248 @item @key{RET}
249 Submit the text in the minibuffer as the argument, possibly completing
250 first as described below (@code{minibuffer-complete-and-exit}).
251 @item ?
252 Print a list of all possible completions of the text in the minibuffer
253 (@code{minibuffer-list-completions}).
254 @end table
255
256 @kindex SPC
257 @findex minibuffer-complete-word
258 @key{SPC} completes much like @key{TAB}, but never goes beyond the
259 next hyphen or space. If you have @samp{auto-f} in the minibuffer and
260 type @key{SPC}, it finds that the completion is @samp{auto-fill-mode},
261 but it stops completing after @samp{fill-}. This gives
262 @samp{auto-fill-}. Another @key{SPC} at this point completes all the
263 way to @samp{auto-fill-mode}. @key{SPC} in the minibuffer when
264 completion is available runs the command
265 @code{minibuffer-complete-word}.
266
267 Here are some commands you can use to choose a completion from a
268 window that displays a list of completions:
269
270 @table @kbd
271 @findex mouse-choose-completion
272 @item Mouse-2
273 Clicking mouse button 2 on a completion in the list of possible
274 completions chooses that completion (@code{mouse-choose-completion}).
275 You normally use this command while point is in the minibuffer; but you
276 must click in the list of completions, not in the minibuffer itself.
277
278 @findex switch-to-completions
279 @item @key{PRIOR}
280 @itemx M-v
281 Typing @key{PRIOR} or @key{PAGE-UP}, or @kbd{M-v}, while in the
282 minibuffer, selects the window showing the completion list buffer
283 (@code{switch-to-completions}). This paves the way for using the
284 commands below. (Selecting that window in the usual ways has the same
285 effect, but this way is more convenient.)
286
287 @findex choose-completion
288 @item @key{RET}
289 Typing @key{RET} @emph{in the completion list buffer} chooses the
290 completion that point is in or next to (@code{choose-completion}). To
291 use this command, you must first switch windows to the window that shows
292 the list of completions.
293
294 @findex next-completion
295 @item @key{RIGHT}
296 Typing the right-arrow key @key{RIGHT} @emph{in the completion list
297 buffer} moves point to the following completion (@code{next-completion}).
298
299 @findex previous-completion
300 @item @key{LEFT}
301 Typing the left-arrow key @key{LEFT} @emph{in the completion list
302 buffer} moves point toward the beginning of the buffer, to the previous
303 completion (@code{previous-completion}).
304 @end table
305
306 @node Strict Completion
307 @subsection Strict Completion
308
309 There are three different ways that @key{RET} can work in completing
310 minibuffers, depending on how the argument will be used.
311
312 @itemize @bullet
313 @item
314 @dfn{Strict} completion is used when it is meaningless to give any
315 argument except one of the known alternatives. For example, when
316 @kbd{C-x k} reads the name of a buffer to kill, it is meaningless to
317 give anything but the name of an existing buffer. In strict
318 completion, @key{RET} refuses to exit if the text in the minibuffer
319 does not complete to an exact match.
320
321 @item
322 @dfn{Cautious} completion is similar to strict completion, except that
323 @key{RET} exits only if the text was an exact match already, not
324 needing completion. If the text is not an exact match, @key{RET} does
325 not exit, but it does complete the text. If it completes to an exact
326 match, a second @key{RET} will exit.
327
328 Cautious completion is used for reading file names for files that must
329 already exist.
330
331 @item
332 @dfn{Permissive} completion is used when any string whatever is
333 meaningful, and the list of completion alternatives is just a guide.
334 For example, when @kbd{C-x C-f} reads the name of a file to visit, any
335 file name is allowed, in case you want to create a file. In
336 permissive completion, @key{RET} takes the text in the minibuffer
337 exactly as given, without completing it.
338 @end itemize
339
340 The completion commands display a list of all possible completions in
341 a window whenever there is more than one possibility for the very next
342 character. Also, typing @kbd{?} explicitly requests such a list. If
343 the list of completions is long, you can scroll it with @kbd{C-M-v}
344 (@pxref{Other Window}).
345
346 @node Completion Options
347 @subsection Completion Options
348
349 @vindex completion-ignored-extensions
350 When completion is done on file names, certain file names are usually
351 ignored. The variable @code{completion-ignored-extensions} contains a
352 list of strings; a file whose name ends in any of those strings is
353 ignored as a possible completion. The standard value of this variable
354 has several elements including @code{".o"}, @code{".elc"}, @code{".dvi"}
355 and @code{"~"}. The effect is that, for example, @samp{foo} can
356 complete to @samp{foo.c} even though @samp{foo.o} exists as well.
357 However, if @emph{all} the possible completions end in ``ignored''
358 strings, then they are not ignored. Ignored extensions do not apply to
359 lists of completions---those always mention all possible completions.
360
361 @vindex completion-auto-help
362 Normally, a completion command that finds the next character is undetermined
363 automatically displays a list of all possible completions. If the variable
364 @code{completion-auto-help} is set to @code{nil}, this does not happen,
365 and you must type @kbd{?} to display the possible completions.
366
367 @pindex complete
368 The @code{complete} library implements a more powerful kind of
369 completion that can complete multiple words at a time. For example, it
370 can complete the command name abbreviation @code{p-b} into
371 @code{print-buffer}, because no other command starts with two words
372 whose initials are @samp{p} and @samp{b}. To use this library, put
373 @code{(load "complete")} in your @file{~/.emacs} file (@pxref{Init
374 File}).
375
376 @cindex Icomplete mode
377 Icomplete mode presents a constantly-updated display that tells you
378 what completions are available for the text you've entered so far. The
379 command to enable or disable this minor mode is @kbd{M-x
380 icomplete-mode}.
381
382 @node Minibuffer History
383 @section Minibuffer History
384 @cindex minibuffer history
385 @cindex history of minibuffer input
386
387 Every argument that you enter with the minibuffer is saved on a
388 @dfn{minibuffer history list} so that you can use it again later in
389 another argument. Special commands load the text of an earlier argument
390 in the minibuffer. They discard the old minibuffer contents, so you can
391 think of them as moving through the history of previous arguments.
392
393 @table @kbd
394 @item @key{UP}
395 @itemx M-p
396 Move to the next earlier argument string saved in the minibuffer history
397 (@code{previous-history-element}).
398 @item @key{DOWN}
399 @itemx M-n
400 Move to the next later argument string saved in the minibuffer history
401 (@code{next-history-element}).
402 @item M-r @var{regexp} @key{RET}
403 Move to an earlier saved argument in the minibuffer history that has a
404 match for @var{regexp} (@code{previous-matching-history-element}).
405 @item M-s @var{regexp} @key{RET}
406 Move to a later saved argument in the minibuffer history that has a
407 match for @var{regexp} (@code{next-matching-history-element}).
408 @end table
409
410 @kindex M-p @r{(minibuffer history)}
411 @kindex M-n @r{(minibuffer history)}
412 @findex next-history-element
413 @findex previous-history-element
414 The simplest way to reuse the saved arguments in the history list is
415 to move through the history list one element at a time. While in the
416 minibuffer, use @kbd{M-p} or up-arrow (@code{previous-history-element})
417 to ``move to'' the next earlier minibuffer input, and use @kbd{M-n} or
418 down-arrow (@code{next-history-element}) to ``move to'' the next later
419 input.
420
421 The previous input that you fetch from the history entirely replaces
422 the contents of the minibuffer. To use it as the argument, exit the
423 minibuffer as usual with @key{RET}. You can also edit the text before
424 you reuse it; this does not change the history element that you
425 ``moved'' to, but your new argument does go at the end of the history
426 list in its own right.
427
428 For many minibuffer arguments there is a ``default'' value. In some
429 cases, the minibuffer history commands know the default value. Then you
430 can insert the default value into the minibuffer as text by using
431 @kbd{M-n} to move ``into the future'' in the history. Eventually we
432 hope to make this feature available whenever the minibuffer has a
433 default value.
434
435 @findex previous-matching-history-element
436 @findex next-matching-history-element
437 @kindex M-r @r{(minibuffer history)}
438 @kindex M-s @r{(minibuffer history)}
439 There are also commands to search forward or backward through the
440 history; they search for history elements that match a regular
441 expression that you specify with the minibuffer. @kbd{M-r}
442 (@code{previous-matching-history-element}) searches older elements in
443 the history, while @kbd{M-s} (@code{next-matching-history-element})
444 searches newer elements. By special dispensation, these commands can
445 use the minibuffer to read their arguments even though you are already
446 in the minibuffer when you issue them. As with incremental searching,
447 an uppercase letter in the regular expression makes the search
448 case-sensitive (@pxref{Search Case}).
449
450 @ignore
451 We may change the precise way these commands read their arguments.
452 Perhaps they will search for a match for the string given so far in the
453 minibuffer; perhaps they will search for a literal match rather than a
454 regular expression match; perhaps they will only accept matches at the
455 beginning of a history element; perhaps they will read the string to
456 search for incrementally like @kbd{C-s}. To find out what interface is
457 actually available, type @kbd{C-h f previous-matching-history-element}.
458 @end ignore
459
460 All uses of the minibuffer record your input on a history list, but
461 there are separate history lists for different kinds of arguments. For
462 example, there is a list for file names, used by all the commands that
463 read file names. (As a special feature, this history list records
464 the absolute file name, no more and no less, even if that is not how
465 you entered the file name.)
466
467 There are several other very specific history lists, including one for
468 command names read by @kbd{M-x}, one for buffer names, one for arguments
469 of commands like @code{query-replace}, and one for compilation commands
470 read by @code{compile}. Finally, there is one ``miscellaneous'' history
471 list that most minibuffer arguments use.
472
473 @vindex history-length
474 The variable @code{history-length} specifies the maximum length of a
475 minibuffer history list; once a list gets that long, the oldest element
476 is deleted each time an element is added. If the value of
477 @code{history-length} is @code{t}, though, there is no maximum length
478 and elements are never deleted.
479
480 @node Repetition
481 @section Repeating Minibuffer Commands
482 @cindex command history
483 @cindex history of commands
484
485 Every command that uses the minibuffer at least once is recorded on a
486 special history list, together with the values of its arguments, so that
487 you can repeat the entire command. In particular, every use of
488 @kbd{M-x} is recorded there, since @kbd{M-x} uses the minibuffer to read
489 the command name.
490
491 @findex list-command-history
492 @c widecommands
493 @table @kbd
494 @item C-x @key{ESC} @key{ESC}
495 Re-execute a recent minibuffer command (@code{repeat-complex-command}).
496 @item M-x list-command-history
497 Display the entire command history, showing all the commands
498 @kbd{C-x @key{ESC} @key{ESC}} can repeat, most recent first.
499 @end table
500
501 @kindex C-x ESC ESC
502 @findex repeat-complex-command
503 @kbd{C-x @key{ESC} @key{ESC}} is used to re-execute a recent
504 minibuffer-using command. With no argument, it repeats the last such
505 command. A numeric argument specifies which command to repeat; one
506 means the last one, and larger numbers specify earlier ones.
507
508 @kbd{C-x @key{ESC} @key{ESC}} works by turning the previous command
509 into a Lisp expression and then entering a minibuffer initialized with
510 the text for that expression. If you type just @key{RET}, the command
511 is repeated as before. You can also change the command by editing the
512 Lisp expression. Whatever expression you finally submit is what will be
513 executed. The repeated command is added to the front of the command
514 history unless it is identical to the most recently executed command
515 already there.
516
517 Even if you don't understand Lisp syntax, it will probably be obvious
518 which command is displayed for repetition. If you do not change the
519 text, it will repeat exactly as before.
520
521 Once inside the minibuffer for @kbd{C-x @key{ESC} @key{ESC}}, you can
522 use the minibuffer history commands (@kbd{M-p}, @kbd{M-n}, @kbd{M-r},
523 @kbd{M-s}; @pxref{Minibuffer History}) to move through the history list
524 of saved entire commands. After finding the desired previous command,
525 you can edit its expression as usual and then resubmit it by typing
526 @key{RET} as usual.
527
528 @vindex command-history
529 The list of previous minibuffer-using commands is stored as a Lisp
530 list in the variable @code{command-history}. Each element is a Lisp
531 expression which describes one command and its arguments. Lisp programs
532 can re-execute a command by calling @code{eval} with the
533 @code{command-history} element.