1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001,
3 @c 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Minibuffer, M-x, Basic, Top
6 @chapter The Minibuffer
9 The @dfn{minibuffer} is the facility used by Emacs commands to read
10 arguments more complicated than a single number. Minibuffer arguments
11 can be file names, buffer names, Lisp function names, Emacs command
12 names, Lisp expressions, and many other things, depending on the command
13 reading the argument. You can use the usual Emacs editing commands in
14 the minibuffer to edit the argument text.
17 When the minibuffer is in use, it appears in the echo area, and the
18 terminal's cursor moves there. The beginning of the minibuffer line
19 displays a @dfn{prompt} in a special color, to say what kind of input
20 you should supply and how it will be used. Often this prompt is
21 derived from the name of the command that the argument is for. The
22 prompt normally ends with a colon.
24 @cindex default argument
25 Sometimes a @dfn{default argument} appears in parentheses before the
26 colon; it too is part of the prompt. The default will be used as the
27 argument value if you enter an empty argument (that is, just type
28 @key{RET}). For example, commands that read buffer names always show a
29 default, which is the name of the buffer that will be used if you type
32 The simplest way to enter a minibuffer argument is to type the text
33 you want, terminated by @key{RET} which exits the minibuffer. You can
34 cancel the command that wants the argument, and get out of the
35 minibuffer, by typing @kbd{C-g}.
37 Since the minibuffer uses the screen space of the echo area, it can
38 conflict with other ways Emacs customarily uses the echo area. Here is how
39 Emacs handles such conflicts:
43 If a command gets an error while you are in the minibuffer, this does
44 not cancel the minibuffer. However, the echo area is needed for the
45 error message and therefore the minibuffer itself is hidden for a
46 while. It comes back after a few seconds, or as soon as you type
50 If in the minibuffer you use a command whose purpose is to display a
51 message in the echo area, such as @kbd{C-x =}, the message hides the
52 minibuffer for a while. The minibuffer contents come back after a few
53 seconds, or as soon as you type anything.
56 Echoing of keystrokes does not take place while the minibuffer is in
61 * File: Minibuffer File. Entering file names with the minibuffer.
62 * Edit: Minibuffer Edit. How to edit in the minibuffer.
63 * Completion:: An abbreviation facility for minibuffer input.
64 * Minibuffer History:: Reusing recent minibuffer arguments.
65 * Repetition:: Re-executing commands that used the minibuffer.
69 @section Minibuffers for File Names
71 Sometimes the minibuffer starts out with text in it. For example, when
72 you are supposed to give a file name, the minibuffer starts out containing
73 the @dfn{default directory}, which ends with a slash. This is to inform
74 you which directory the file will be found in if you do not specify a
77 @c Separate paragraph to clean up ugly page break--rms
79 For example, the minibuffer might start out with these contents:
82 Find File: /u2/emacs/src/
86 where @samp{Find File:@: } is the prompt. Typing @kbd{buffer.c} as
87 input specifies the file @file{/u2/emacs/src/buffer.c}. To find files
88 in nearby directories, use @kbd{..}; thus, if you type
89 @kbd{../lisp/simple.el}, you will get the file named
90 @file{/u2/emacs/lisp/simple.el}. Alternatively, you can kill with
91 @kbd{M-@key{DEL}} the directory names you don't want (@pxref{Words}).
93 If you don't want any of the default, you can kill it with @kbd{C-a
94 C-k}. But you don't need to kill the default; you can simply ignore it.
95 Insert an absolute file name, one starting with a slash or a tilde,
96 after the default directory. For example, to specify the file
97 @file{/etc/termcap}, just insert that name, giving these minibuffer
101 Find File: /u2/emacs/src//etc/termcap
105 @cindex // in file name
106 @cindex double slash in file name
107 @cindex slashes repeated in file name
108 @findex file-name-shadow-mode
109 GNU Emacs gives a special meaning to a double slash (which is not
110 normally a useful thing to write): it means, ``ignore everything
111 before the second slash in the pair.'' Thus, @samp{/u2/emacs/src/} is
112 ignored in the example above, and you get the file
113 @file{/etc/termcap}. The ignored part of the file name is dimmed if
114 the terminal allows it; to disable this, turn off
115 @code{file-name-shadow-mode} minor mode.
117 If you set @code{insert-default-directory} to @code{nil}, the default
118 directory is not inserted in the minibuffer. This way, the minibuffer
119 starts out empty. But the name you type, if relative, is still
120 interpreted with respect to the same default directory.
122 @node Minibuffer Edit
123 @section Editing in the Minibuffer
125 The minibuffer is an Emacs buffer (albeit a peculiar one), and the usual
126 Emacs commands are available for editing the text of an argument you are
129 Since @key{RET} in the minibuffer is defined to exit the minibuffer,
130 you can't use it to insert a newline in the minibuffer. To do that,
131 type @kbd{C-o} or @kbd{C-q C-j}. (On text terminals, newline is
132 really the @acronym{ASCII} character control-J.)
134 The minibuffer has its own window which always has space on the screen
135 but acts as if it were not there when the minibuffer is not in use. When
136 the minibuffer is in use, its window is just like the others; you can
137 switch to another window with @kbd{C-x o}, edit text in other windows and
138 perhaps even visit more files, before returning to the minibuffer to submit
139 the argument. You can kill text in another window, return to the
140 minibuffer window, and then yank the text to use it in the argument.
143 @cindex height of minibuffer
144 @cindex size of minibuffer
145 @cindex growing minibuffer
146 @cindex resizing minibuffer
147 There are some restrictions on the use of the minibuffer window,
148 however. You cannot switch buffers in it---the minibuffer and its
149 window are permanently attached. Also, you cannot split or kill the
150 minibuffer window. But you can make it taller in the normal fashion
153 @vindex resize-mini-windows
154 The minibuffer window expands vertically as necessary to hold the
155 text that you put in the minibuffer. If @code{resize-mini-windows} is
156 @code{t} (the default), the window is always resized to fit the size
157 of the text it displays. If its value is the symbol @code{grow-only},
158 the window grows when the size of displayed text increases, but
159 shrinks (back to the normal size) only when the minibuffer becomes
160 inactive. If its value is @code{nil}, you have to adjust the height
163 @vindex max-mini-window-height
164 The variable @code{max-mini-window-height} controls the maximum
165 height for resizing the minibuffer window: a floating-point number
166 specifies a fraction of the frame's height; an integer specifies the
167 maximum number of lines; @code{nil} means do not resize the minibuffer
168 window automatically. The default value is 0.25.
170 If, while in the minibuffer, you issue a command that displays help
171 text of any sort in another window, you can use the @kbd{C-M-v}
172 command while in the minibuffer to scroll the help text.
173 (@kbd{M-@key{PAGEUP}} and @kbd{M-@key{PAGEDOWN}} also operate on that
174 help text.) This lasts until you exit the minibuffer. This feature
175 is especially useful when you display a buffer listing possible
176 completions. @xref{Other Window}.
178 @vindex enable-recursive-minibuffers
179 Emacs normally disallows most commands that use the minibuffer while
180 the minibuffer is active. This rule is to prevent recursive minibuffers
181 from confusing novice users. If you want to be able to use such
182 commands in the minibuffer, set the variable
183 @code{enable-recursive-minibuffers} to a non-@code{nil} value.
189 For certain kinds of arguments, you can use @dfn{completion} to enter
190 the argument value. Completion means that you type part of the
191 argument, then Emacs visibly fills in the rest, or as much as
192 can be determined from the part you have typed.
194 When completion is available, certain keys---@key{TAB}, @key{RET}, and
195 @key{SPC}---are rebound to complete the text in the minibuffer before point
196 into a longer string that it stands for, by matching it against a set of
197 @dfn{completion alternatives} provided by the command reading the
198 argument. @kbd{?} is defined to display a list of possible completions
199 of what you have inserted.
201 For example, when @kbd{M-x} uses the minibuffer to read the name of a
202 command, it provides a list of all available Emacs command names to
203 complete against. The completion keys match the minibuffer text
204 against all the command names, find any additional name characters
205 implied by the ones already present in the minibuffer, and add those
206 characters to the ones you have given. This is what makes it possible
207 to type @kbd{M-x ins @key{SPC} b @key{RET}} instead of @kbd{M-x
208 insert-buffer @key{RET}} (for example).
210 Case is normally significant in completion, because it is significant
211 in most of the names that you can complete (buffer names, file names and
212 command names). Thus, @samp{fo} does not complete to @samp{Foo}.
213 Completion does ignore case distinctions for certain arguments in which
214 case does not matter.
216 Completion acts only on the text before point. If there is text in
217 the minibuffer after point---i.e., if you move point backward after
218 typing some text into the minibuffer---it remains unchanged.
221 * Example: Completion Example. Examples of using completion.
222 * Commands: Completion Commands. A list of completion commands.
223 * Strict Completion:: Different types of completion.
224 * Options: Completion Options. Options for completion.
227 @node Completion Example
228 @subsection Completion Example
230 @kindex TAB @r{(completion)}
231 @findex minibuffer-complete
232 A concrete example may help here. If you type @kbd{M-x au @key{TAB}},
233 the @key{TAB} looks for alternatives (in this case, command names) that
234 start with @samp{au}. There are several, including
235 @code{auto-fill-mode} and @code{auto-save-mode}---but they are all the
236 same as far as @code{auto-}, so the @samp{au} in the minibuffer changes
237 to @samp{auto-}.@refill
239 If you type @key{TAB} again immediately, there are multiple
240 possibilities for the very next character---it could be any of
241 @samp{cfilrs}---so no more characters are added; instead, @key{TAB}
242 displays a list of all possible completions in another window.
244 If you go on to type @kbd{f @key{TAB}}, this @key{TAB} sees
245 @samp{auto-f}. The only command name starting this way is
246 @code{auto-fill-mode}, so completion fills in the rest of that. You now
247 have @samp{auto-fill-mode} in the minibuffer after typing just @kbd{au
248 @key{TAB} f @key{TAB}}. Note that @key{TAB} has this effect because in
249 the minibuffer it is bound to the command @code{minibuffer-complete}
250 when completion is available.
252 @node Completion Commands
253 @subsection Completion Commands
255 Here is a list of the completion commands defined in the minibuffer
256 when completion is available.
260 Complete the text before point in the minibuffer as much as possible
261 (@code{minibuffer-complete}).
263 Complete the minibuffer text before point, but don't go beyond one word
264 (@code{minibuffer-complete-word}).
266 Submit the text in the minibuffer as the argument, possibly completing
269 in the next subsection (@code{minibuffer-complete-and-exit}).
272 in the next node (@code{minibuffer-complete-and-exit}). @xref{Strict
276 Display a list of all possible completions of the text in the minibuffer
277 (@code{minibuffer-completion-help}).
281 @findex minibuffer-complete-word
282 @key{SPC} completes much like @key{TAB}, but never goes beyond the
283 next hyphen or space. If you have @samp{auto-f} in the minibuffer and
284 type @key{SPC}, it finds that the completion is @samp{auto-fill-mode},
285 but it stops completing after @samp{fill-}. This gives
286 @samp{auto-fill-}. Another @key{SPC} at this point completes all the
287 way to @samp{auto-fill-mode}. The command that implements this
288 behavior is called @code{minibuffer-complete-word}.
290 Here are some commands you can use to choose a completion from a
291 window that displays a list of completions:
294 @findex mouse-choose-completion
297 Clicking mouse button 1 or 2 on a completion in the list of possible
298 completions chooses that completion (@code{mouse-choose-completion}).
299 You normally use this command while point is in the minibuffer, but you
300 must click in the list of completions, not in the minibuffer itself.
302 @findex switch-to-completions
305 Typing @key{PRIOR} or @key{PAGE-UP}, or @kbd{M-v}, while in the
306 minibuffer, selects the window showing the completion list buffer
307 (@code{switch-to-completions}). This paves the way for using the
308 commands below. (Selecting that window in the usual ways has the same
309 effect, but this way is more convenient.)
311 @findex choose-completion
313 Typing @key{RET} @emph{in the completion list buffer} chooses the
314 completion that point is in or next to (@code{choose-completion}). To
315 use this command, you must first switch windows to the window that shows
316 the list of completions.
318 @findex next-completion
320 Typing the right-arrow key @key{RIGHT} @emph{in the completion list
321 buffer} moves point to the following completion (@code{next-completion}).
323 @findex previous-completion
325 Typing the left-arrow key @key{LEFT} @emph{in the completion list
326 buffer} moves point toward the beginning of the buffer, to the previous
327 completion (@code{previous-completion}).
330 @node Strict Completion
331 @subsection Strict Completion
333 There are three different ways that @key{RET} can work in completing
334 minibuffers, depending on how the argument will be used.
338 @dfn{Strict} completion is used when it is meaningless to give any
339 argument except one of the known alternatives. For example, when
340 @kbd{C-x k} reads the name of a buffer to kill, it is meaningless to
341 give anything but the name of an existing buffer. In strict
342 completion, @key{RET} refuses to exit if the text in the minibuffer
343 does not complete to an exact match.
346 @dfn{Cautious} completion is similar to strict completion, except that
347 @key{RET} exits only if the text was an exact match already, not
348 needing completion. If the text is not an exact match, @key{RET} does
349 not exit, but it does complete the text. If it completes to an exact
350 match, a second @key{RET} will exit.
352 Cautious completion is used for reading file names for files that must
356 @dfn{Permissive} completion is used when any string whatever is
357 meaningful, and the list of completion alternatives is just a guide.
358 For example, when @kbd{C-x C-f} reads the name of a file to visit, any
359 file name is allowed, in case you want to create a file. In
360 permissive completion, @key{RET} takes the text in the minibuffer
361 exactly as given, without completing it.
364 The completion commands display a list of all possible completions in
365 a window whenever there is more than one possibility for the very next
366 character. Also, typing @kbd{?} explicitly requests such a list. If
367 the list of completions is long, you can scroll it with @kbd{C-M-v}
368 (@pxref{Other Window}).
370 @node Completion Options
371 @subsection Completion Options
373 @vindex completion-ignored-extensions
374 @cindex ignored file names, in completion
375 When completion is done on file names, certain file names are usually
376 ignored. The variable @code{completion-ignored-extensions} contains a
377 list of strings; a file whose name ends in any of those strings is
378 ignored as a possible completion. The standard value of this variable
379 has several elements including @code{".o"}, @code{".elc"}, @code{".dvi"}
380 and @code{"~"}. The effect is that, for example, @samp{foo} can
381 complete to @samp{foo.c} even though @samp{foo.o} exists as well.
382 However, if @emph{all} the possible completions end in ``ignored''
383 strings, then they are not ignored. Ignored extensions do not apply to
384 lists of completions---those always mention all possible completions.
386 If an element of the list in @code{completion-ignored-extensions} ends
387 in a slash @file{/}, it indicates a subdirectory that should be ignored
388 when completing file names. (Elements of
389 @code{completion-ignored-extensions} which do not end in a slash are
390 never considered when a completion candidate is a directory; thus,
391 completion returns directories whose names end in @file{.elc} even
392 though there's an element @code{".elc"} in the list.)
394 @vindex completion-auto-help
395 Normally, a completion command that cannot determine even one
396 additional character automatically displays a list of all possible
397 completions. If the variable @code{completion-auto-help} is set to
398 @code{nil}, this automatic display is disabled, so you must type
399 @kbd{?} to display the list of completions.
401 @cindex Partial Completion mode
402 @vindex partial-completion-mode
403 @findex partial-completion-mode
404 Partial Completion mode implements a more powerful kind of
405 completion that can complete multiple words in parallel. For example,
406 it can complete the command name abbreviation @code{p-b} into
407 @code{print-buffer}, because no other command starts with two words
408 whose initials are @samp{p} and @samp{b}.
410 Partial completion of directories in file names uses @samp{*} to
411 indicate the places for completion; thus, @file{/u*/b*/f*} might
412 complete to @file{/usr/bin/foo}.
414 To enable this mode, use the command @kbd{M-x
415 partial-completion-mode}, or customize the variable
416 @code{partial-completion-mode}. This binds the partial completion
417 commands to @key{TAB}, @key{SPC}, @key{RET}, and @kbd{?}. The usual
418 completion commands are available on @kbd{M-@key{TAB}} (or
419 @kbd{C-M-i}), @kbd{M-@key{SPC}}, @kbd{M-@key{RET}} and @kbd{M-?}.
421 @vindex PC-include-file-path
422 @vindex PC-disable-includes
423 Another feature of Partial Completion mode is to extend
424 @code{find-file} so that @samp{<@var{include}>} stands for the
425 file named @var{include} in some directory in the path
426 @code{PC-include-file-path}. If you set @code{PC-disable-includes} to
427 non-@code{nil}, this feature is disabled.
429 @cindex Icomplete mode
430 @findex icomplete-mode
431 Icomplete mode presents a constantly-updated display that tells you
432 what completions are available for the text you've entered so far. The
433 command to enable or disable this minor mode is @kbd{M-x
436 @node Minibuffer History
437 @section Minibuffer History
438 @cindex minibuffer history
439 @cindex history of minibuffer input
441 Every argument that you enter with the minibuffer is saved on a
442 @dfn{minibuffer history list} so that you can use it again later in
443 another argument. Special commands load the text of an earlier argument
444 in the minibuffer. They discard the old minibuffer contents, so you can
445 think of them as moving through the history of previous arguments.
450 Move to the next earlier argument string saved in the minibuffer history
451 (@code{previous-history-element}).
454 Move to the next later argument string saved in the minibuffer history
455 (@code{next-history-element}).
456 @item M-r @var{regexp} @key{RET}
457 Move to an earlier saved argument in the minibuffer history that has a
458 match for @var{regexp} (@code{previous-matching-history-element}).
459 @item M-s @var{regexp} @key{RET}
460 Move to a later saved argument in the minibuffer history that has a
461 match for @var{regexp} (@code{next-matching-history-element}).
464 @kindex M-p @r{(minibuffer history)}
465 @kindex M-n @r{(minibuffer history)}
466 @findex next-history-element
467 @findex previous-history-element
468 The simplest way to reuse the saved arguments in the history list is
469 to move through the history list one element at a time. While in the
470 minibuffer, use @kbd{M-p} or up-arrow
471 (@code{previous-history-element}) to ``move to'' the next earlier
472 minibuffer input, and use @kbd{M-n} or down-arrow
473 (@code{next-history-element}) to ``move to'' the next later input.
474 These commands don't move the cursor, they bring different saved
475 strings into the minibuffer. But you can think of them as ``moving''
476 through the history list.
478 The previous input that you fetch from the history entirely replaces
479 the contents of the minibuffer. To use it as the argument, exit the
480 minibuffer as usual with @key{RET}. You can also edit the text before
481 you reuse it; this does not change the history element that you
482 ``moved'' to, but your new argument does go at the end of the history
483 list in its own right.
485 For many minibuffer arguments there is a ``default'' value. In some
486 cases, the minibuffer history commands know the default value. Then you
487 can insert the default value into the minibuffer as text by using
488 @kbd{M-n} to move ``into the future'' in the history. Eventually we
489 hope to make this feature available whenever the minibuffer has a
492 @findex previous-matching-history-element
493 @findex next-matching-history-element
494 @kindex M-r @r{(minibuffer history)}
495 @kindex M-s @r{(minibuffer history)}
496 There are also commands to search forward or backward through the
497 history; they search for history elements that match a regular
498 expression that you specify with the minibuffer. @kbd{M-r}
499 (@code{previous-matching-history-element}) searches older elements in
500 the history, while @kbd{M-s} (@code{next-matching-history-element})
501 searches newer elements. By special dispensation, these commands can
502 use the minibuffer to read their arguments even though you are already
503 in the minibuffer when you issue them. As with incremental searching,
504 an upper-case letter in the regular expression makes the search
505 case-sensitive (@pxref{Search Case}).
508 We may change the precise way these commands read their arguments.
509 Perhaps they will search for a match for the string given so far in the
510 minibuffer; perhaps they will search for a literal match rather than a
511 regular expression match; perhaps they will only accept matches at the
512 beginning of a history element; perhaps they will read the string to
513 search for incrementally like @kbd{C-s}. To find out what interface is
514 actually available, type @kbd{C-h f previous-matching-history-element}.
517 All uses of the minibuffer record your input on a history list, but
518 there are separate history lists for different kinds of arguments. For
519 example, there is a list for file names, used by all the commands that
520 read file names. (As a special feature, this history list records
521 the absolute file name, no more and no less, even if that is not how
522 you entered the file name.)
524 There are several other very specific history lists, including one for
525 command names read by @kbd{M-x}, one for buffer names, one for arguments
526 of commands like @code{query-replace}, and one for compilation commands
527 read by @code{compile}. Finally, there is one ``miscellaneous'' history
528 list that most minibuffer arguments use.
530 @vindex history-length
531 The variable @code{history-length} specifies the maximum length of a
532 minibuffer history list; once a list gets that long, the oldest element
533 is deleted each time an element is added. If the value of
534 @code{history-length} is @code{t}, though, there is no maximum length
535 and elements are never deleted.
537 @vindex history-delete-duplicates
538 The variable @code{history-delete-duplicates} specifies whether to
539 delete duplicates in history. If the value of @code{history-delete-duplicates}
540 is @code{t}, that means when adding a new history element, all
541 previous identical elements are deleted.
544 @section Repeating Minibuffer Commands
545 @cindex command history
546 @cindex history of commands
548 Every command that uses the minibuffer at least once is recorded on a
549 special history list, together with the values of its arguments, so that
550 you can repeat the entire command. In particular, every use of
551 @kbd{M-x} is recorded there, since @kbd{M-x} uses the minibuffer to read
554 @findex list-command-history
556 @item C-x @key{ESC} @key{ESC}
557 Re-execute a recent minibuffer command (@code{repeat-complex-command}).
558 @item M-x list-command-history
559 Display the entire command history, showing all the commands
560 @kbd{C-x @key{ESC} @key{ESC}} can repeat, most recent first.
564 @findex repeat-complex-command
565 @kbd{C-x @key{ESC} @key{ESC}} is used to re-execute a recent
566 minibuffer-using command. With no argument, it repeats the last such
567 command. A numeric argument specifies which command to repeat; one
568 means the last one, and larger numbers specify earlier ones.
570 @kbd{C-x @key{ESC} @key{ESC}} works by turning the previous command
571 into a Lisp expression and then entering a minibuffer initialized with
572 the text for that expression. If you type just @key{RET}, the command
573 is repeated as before. You can also change the command by editing the
574 Lisp expression. Whatever expression you finally submit is what will be
575 executed. The repeated command is added to the front of the command
576 history unless it is identical to the most recently executed command
579 Even if you don't understand Lisp syntax, it will probably be obvious
580 which command is displayed for repetition. If you do not change the
581 text, it will repeat exactly as before.
583 Once inside the minibuffer for @kbd{C-x @key{ESC} @key{ESC}}, you can
584 use the minibuffer history commands (@kbd{M-p}, @kbd{M-n}, @kbd{M-r},
585 @kbd{M-s}; @pxref{Minibuffer History}) to move through the history list
586 of saved entire commands. After finding the desired previous command,
587 you can edit its expression as usual and then resubmit it by typing
590 @vindex isearch-resume-in-command-history
591 Incremental search does not, strictly speaking, use the minibuffer,
592 but it does something similar. Although it behaves like a complex command,
593 it normally does not appear in the history list for @kbd{C-x
594 @key{ESC} @key{ESC}}. You can make it appear in the history by
595 setting @code{isearch-resume-in-command-history} to a non-@code{nil}
596 value. @xref{Incremental Search}.
598 @vindex command-history
599 The list of previous minibuffer-using commands is stored as a Lisp
600 list in the variable @code{command-history}. Each element is a Lisp
601 expression which describes one command and its arguments. Lisp programs
602 can re-execute a command by calling @code{eval} with the
603 @code{command-history} element.
606 arch-tag: ba913cfd-b70e-400f-b663-22b2c309227f