@c This is part of the Emacs manual.@c Copyright (C) 1985, 86, 87, 93, 94, 95, 97, 00, 2001@c Free Software Foundation, Inc.@c See file emacs.texi for copying conditions.@node Minibuffer, M-x, Basic, Top@chapter The Minibuffer@cindex minibuffer The @dfn{minibuffer} is the facility used by Emacs commands to readarguments more complicated than a single number. Minibuffer argumentscan be file names, buffer names, Lisp function names, Emacs commandnames, Lisp expressions, and many other things, depending on the commandreading the argument. You can use the usual Emacs editing commands inthe minibuffer to edit the argument text.@cindex prompt When the minibuffer is in use, it appears in the echo area, and theterminal's cursor moves there. The beginning of the minibuffer linedisplays a @dfn{prompt} which says what kind of input you should supply andhow it will be used. Often this prompt is derived from the name of thecommand that the argument is for. The prompt normally ends with a colon.@cindex default argument Sometimes a @dfn{default argument} appears in parentheses after thecolon; it too is part of the prompt. The default will be used as theargument value if you enter an empty argument (that is, just type@key{RET}). For example, commands that read buffer names always show adefault, which is the name of the buffer that will be used if you typejust @key{RET}. The simplest way to enter a minibuffer argument is to type the textyou want, terminated by @key{RET} which exits the minibuffer. You cancancel the command that wants the argument, and get out of theminibuffer, by typing @kbd{C-g}. Since the minibuffer uses the screen space of the echo area, it canconflict with other ways Emacs customarily uses the echo area. Here is howEmacs handles such conflicts:@itemize @bullet@itemIf a command gets an error while you are in the minibuffer, this doesnot cancel the minibuffer. However, the echo area is needed for theerror message and therefore the minibuffer itself is hidden for awhile. It comes back after a few seconds, or as soon as you typeanything.@itemIf in the minibuffer you use a command whose purpose is to display amessage in the echo area, such as @kbd{C-x =}, the message hides theminibuffer for a while. The minibuffer contents come back after a fewseconds, or as soon as you type anything.@itemEchoing of keystrokes does not take place while the minibuffer is inuse.@end itemize@menu* File: Minibuffer File. Entering file names with the minibuffer.* Edit: Minibuffer Edit. How to edit in the minibuffer.* Completion:: An abbreviation facility for minibuffer input.* Minibuffer History:: Reusing recent minibuffer arguments.* Repetition:: Re-executing commands that used the minibuffer.@end menu@node Minibuffer File@section Minibuffers for File Names Sometimes the minibuffer starts out with text in it. For example, whenyou are supposed to give a file name, the minibuffer starts out containingthe @dfn{default directory}, which ends with a slash. This is to informyou which directory the file will be found in if you do not specify adirectory.@c Separate paragraph to clean up ugly page break--rms@need 1500 For example, the minibuffer might start out with these contents:@exampleFind File: /u2/emacs/src/@end example@noindentwhere @samp{Find File:@: } is the prompt. Typing @kbd{buffer.c}specifies the file @file{/u2/emacs/src/buffer.c}. To find files innearby directories, use @kbd{..}; thus, if you type@kbd{../lisp/simple.el}, you will get the file named@file{/u2/emacs/lisp/simple.el}. Alternatively, you can kill with@kbd{M-@key{DEL}} the directory names you don't want (@pxref{Words}). If you don't want any of the default, you can kill it with @kbd{C-aC-k}. But you don't need to kill the default; you can simply ignore it.Insert an absolute file name, one starting with a slash or a tilde,after the default directory. For example, to specify the file@file{/etc/termcap}, just insert that name, giving these minibuffercontents:@exampleFind File: /u2/emacs/src//etc/termcap@end example@noindent@cindex // in file name@cindex double slash in file name@cindex slashes repeated in file nameGNU Emacs gives a special meaning to a double slash (which is notnormally a useful thing to write): it means, ``ignore everything beforethe second slash in the pair.'' Thus, @samp{/u2/emacs/src/} is ignoredin the example above, and you get the file @file{/etc/termcap}. If you set @code{insert-default-directory} to @code{nil}, the defaultdirectory is not inserted in the minibuffer. This way, the minibufferstarts out empty. But the name you type, if relative, is stillinterpreted with respect to the same default directory.@node Minibuffer Edit@section Editing in the Minibuffer The minibuffer is an Emacs buffer (albeit a peculiar one), and the usualEmacs commands are available for editing the text of an argument you areentering. Since @key{RET} in the minibuffer is defined to exit the minibuffer,you can't use it to insert a newline in the minibuffer. To do that,type @kbd{C-o} or @kbd{C-q C-j}. (Recall that a newline is really thecharacter control-J.) The minibuffer has its own window which always has space on the screenbut acts as if it were not there when the minibuffer is not in use. Whenthe minibuffer is in use, its window is just like the others; you canswitch to another window with @kbd{C-x o}, edit text in other windows andperhaps even visit more files, before returning to the minibuffer to submitthe argument. You can kill text in another window, return to theminibuffer window, and then yank the text to use it in the argument.@xref{Windows}.@cindex height of minibuffer@cindex size of minibuffer@cindex growing minibuffer@cindex resizing minibuffer There are some restrictions on the use of the minibuffer window,however. You cannot switch buffers in it---the minibuffer and itswindow are permanently attached. Also, you cannot split or kill theminibuffer window. But you can make it taller in the normal fashionwith @kbd{C-x ^}.@vindex resize-mini-windows The minibuffer window expands vertically as necessary to hold thetext that you put in the minibuffer, if @code{resize-mini-windows} isnon-@code{nil}. If @code{resize-mini-windows} is @code{t}, the windowis always resized to fit the size of the text it displays. If@code{resize-mini-windows} is the symbol @code{grow-only}, the windowgrows when the size of displayed text increases, but shrinks (back tothe normal size) only when the minibuffer becomes inactive.@vindex max-mini-window-height The variable @code{max-mini-window-height} controls the maximumheight for resizing the minibuffer window: a floating-point numberspecifies a fraction of the frame's height; an integer specifies themaximum number of lines; @code{nil} means do not resize the minibufferwindow automatically. The default value is 0.25. If while in the minibuffer you issue a command that displays help textof any sort in another window, you can use the @kbd{C-M-v} command whilein the minibuffer to scroll the help text. This lasts until you exitthe minibuffer. This feature is especially useful when you displaya buffer listing possible completions. @xref{Other Window}.@vindex enable-recursive-minibuffers Emacs normally disallows most commands that use the minibuffer whilethe minibuffer is active. This rule is to prevent recursive minibuffersfrom confusing novice users. If you want to be able to use suchcommands in the minibuffer, set the variable@code{enable-recursive-minibuffers} to a non-@code{nil} value.@node Completion@section Completion@cindex completion For certain kinds of arguments, you can use @dfn{completion} to enterthe argument value. Completion means that you type part of theargument, then Emacs visibly fills in the rest, or as much ascan be determined from the part you have typed. When completion is available, certain keys---@key{TAB}, @key{RET}, and@key{SPC}---are rebound to complete the text present in the minibufferinto a longer string that it stands for, by matching it against a set of@dfn{completion alternatives} provided by the command reading theargument. @kbd{?} is defined to display a list of possible completionsof what you have inserted. For example, when @kbd{M-x} uses the minibuffer to read the name of acommand, it provides a list of all available Emacs command names tocomplete against. The completion keys match the text in the minibufferagainst all the command names, find any additional name charactersimplied by the ones already present in the minibuffer, and add thosecharacters to the ones you have given. This is what makes it possibleto type @kbd{M-x ins @key{SPC} b @key{RET}} instead of @kbd{M-xinsert-buffer @key{RET}} (for example). Case is normally significant in completion, because it is significantin most of the names that you can complete (buffer names, file names andcommand names). Thus, @samp{fo} does not complete to @samp{Foo}.Completion does ignore case distinctions for certain arguments in whichcase does not matter.@menu* Example: Completion Example.* Commands: Completion Commands.* Strict Completion::* Options: Completion Options.@end menu@node Completion Example@subsection Completion Example@kindex TAB @r{(completion)}@findex minibuffer-complete A concrete example may help here. If you type @kbd{M-x au @key{TAB}},the @key{TAB} looks for alternatives (in this case, command names) thatstart with @samp{au}. There are several, including@code{auto-fill-mode} and @code{auto-save-mode}---but they are all thesame as far as @code{auto-}, so the @samp{au} in the minibuffer changesto @samp{auto-}.@refill If you type @key{TAB} again immediately, there are multiplepossibilities for the very next character---it could be any of@samp{cfilrs}---so no more characters are added; instead, @key{TAB}displays a list of all possible completions in another window. If you go on to type @kbd{f @key{TAB}}, this @key{TAB} sees@samp{auto-f}. The only command name starting this way is@code{auto-fill-mode}, so completion fills in the rest of that. You nowhave @samp{auto-fill-mode} in the minibuffer after typing just @kbd{au@key{TAB} f @key{TAB}}. Note that @key{TAB} has this effect because inthe minibuffer it is bound to the command @code{minibuffer-complete}when completion is available.@node Completion Commands@subsection Completion Commands Here is a list of the completion commands defined in the minibufferwhen completion is available.@table @kbd@item @key{TAB}Complete the text in the minibuffer as much as possible(@code{minibuffer-complete}).@item @key{SPC}Complete the minibuffer text, but don't go beyond one word(@code{minibuffer-complete-word}).@item @key{RET}Submit the text in the minibuffer as the argument, possibly completingfirst as described below (@code{minibuffer-complete-and-exit}).@item ?Display a list of all possible completions of the text in the minibuffer(@code{minibuffer-list-completions}).@end table@kindex SPC@findex minibuffer-complete-word @key{SPC} completes much like @key{TAB}, but never goes beyond thenext hyphen or space. If you have @samp{auto-f} in the minibuffer andtype @key{SPC}, it finds that the completion is @samp{auto-fill-mode},but it stops completing after @samp{fill-}. This gives@samp{auto-fill-}. Another @key{SPC} at this point completes all theway to @samp{auto-fill-mode}. The command that implements thisbehavior is called @code{minibuffer-complete-word}. Here are some commands you can use to choose a completion from awindow that displays a list of completions:@table @kbd@findex mouse-choose-completion@item Mouse-2Clicking mouse button 2 on a completion in the list of possiblecompletions chooses that completion (@code{mouse-choose-completion}).You normally use this command while point is in the minibuffer, but youmust click in the list of completions, not in the minibuffer itself.@findex switch-to-completions@item @key{PRIOR}@itemx M-vTyping @key{PRIOR} or @key{PAGE-UP}, or @kbd{M-v}, while in theminibuffer, selects the window showing the completion list buffer(@code{switch-to-completions}). This paves the way for using thecommands below. (Selecting that window in the usual ways has the sameeffect, but this way is more convenient.)@findex choose-completion@item @key{RET}Typing @key{RET} @emph{in the completion list buffer} chooses thecompletion that point is in or next to (@code{choose-completion}). Touse this command, you must first switch windows to the window that showsthe list of completions.@findex next-completion@item @key{RIGHT}Typing the right-arrow key @key{RIGHT} @emph{in the completion listbuffer} moves point to the following completion (@code{next-completion}).@findex previous-completion@item @key{LEFT}Typing the left-arrow key @key{LEFT} @emph{in the completion listbuffer} moves point toward the beginning of the buffer, to the previouscompletion (@code{previous-completion}).@end table@node Strict Completion@subsection Strict Completion There are three different ways that @key{RET} can work in completingminibuffers, depending on how the argument will be used.@itemize @bullet@item@dfn{Strict} completion is used when it is meaningless to give anyargument except one of the known alternatives. For example, when@kbd{C-x k} reads the name of a buffer to kill, it is meaningless togive anything but the name of an existing buffer. In strictcompletion, @key{RET} refuses to exit if the text in the minibufferdoes not complete to an exact match.@item@dfn{Cautious} completion is similar to strict completion, except that@key{RET} exits only if the text was an exact match already, notneeding completion. If the text is not an exact match, @key{RET} doesnot exit, but it does complete the text. If it completes to an exactmatch, a second @key{RET} will exit.Cautious completion is used for reading file names for files that mustalready exist.@item@dfn{Permissive} completion is used when any string whatever ismeaningful, and the list of completion alternatives is just a guide.For example, when @kbd{C-x C-f} reads the name of a file to visit, anyfile name is allowed, in case you want to create a file. Inpermissive completion, @key{RET} takes the text in the minibufferexactly as given, without completing it.@end itemize The completion commands display a list of all possible completions ina window whenever there is more than one possibility for the very nextcharacter. Also, typing @kbd{?} explicitly requests such a list. Ifthe list of completions is long, you can scroll it with @kbd{C-M-v}(@pxref{Other Window}).@node Completion Options@subsection Completion Options@vindex completion-ignored-extensions@cindex ignored file names, in completion When completion is done on file names, certain file names are usuallyignored. The variable @code{completion-ignored-extensions} contains alist of strings; a file whose name ends in any of those strings isignored as a possible completion. The standard value of this variablehas several elements including @code{".o"}, @code{".elc"}, @code{".dvi"}and @code{"~"}. The effect is that, for example, @samp{foo} cancomplete to @samp{foo.c} even though @samp{foo.o} exists as well.However, if @emph{all} the possible completions end in ``ignored''strings, then they are not ignored. Ignored extensions do not apply tolists of completions---those always mention all possible completions.@vindex completion-auto-help Normally, a completion command that cannot determine even oneadditional character automatically displays a list of all possiblecompletions. If the variable @code{completion-auto-help} is set to@code{nil}, this automatic display is disabled, so you must type@kbd{?} to display the list of completions.@cindex Partial Completion mode@vindex partial-completion-mode@findex partial-completion-mode Partial Completion mode implements a more powerful kind ofcompletion that can complete multiple words in parallel. For example,it can complete the command name abbreviation @code{p-b} into@code{print-buffer}, because no other command starts with two wordswhose initials are @samp{p} and @samp{b}. Partial completion of directories in file names uses @samp{*} toindicate the places for completion; thus, @file{/u*/b*/f*} mightcomplete to @file{/usr/bin/foo}. To enable this mode, use the command @kbd{M-xpartial-completion-mode}, or customize the option@code{partial-completion-mode}. This binds the partial completioncommands to @key{TAB}, @key{SPC}, @key{RET}, and @kbd{?}. The usualcompletion commands are available on @kbd{M-@key{TAB}},@kbd{M-@key{SPC}}, @kbd{M-@key{RET}} and @kbd{M-?}.@vindex PC-include-file-path@vindex PC-disable-includes Another feature of Partial Completion mode is to extend@code{find-file} so that the @samp{<@var{include}>} stands for thefile named @var{include} in some directory in the path@code{PC-include-file-path}. If you set @code{PC-disable-includes} tonon-@code{nil}, this feature is disabled.@cindex Icomplete mode@findex icomplete-mode Icomplete mode presents a constantly-updated display that tells youwhat completions are available for the text you've entered so far. Thecommand to enable or disable this minor mode is @kbd{M-xicomplete-mode}.@node Minibuffer History@section Minibuffer History@cindex minibuffer history@cindex history of minibuffer input Every argument that you enter with the minibuffer is saved on a@dfn{minibuffer history list} so that you can use it again later inanother argument. Special commands load the text of an earlier argumentin the minibuffer. They discard the old minibuffer contents, so you canthink of them as moving through the history of previous arguments.@table @kbd@item @key{UP}@itemx M-pMove to the next earlier argument string saved in the minibuffer history(@code{previous-history-element}).@item @key{DOWN}@itemx M-nMove to the next later argument string saved in the minibuffer history(@code{next-history-element}).@item M-r @var{regexp} @key{RET}Move to an earlier saved argument in the minibuffer history that has amatch for @var{regexp} (@code{previous-matching-history-element}).@item M-s @var{regexp} @key{RET}Move to a later saved argument in the minibuffer history that has amatch for @var{regexp} (@code{next-matching-history-element}).@end table@kindex M-p @r{(minibuffer history)}@kindex M-n @r{(minibuffer history)}@findex next-history-element@findex previous-history-element The simplest way to reuse the saved arguments in the history list isto move through the history list one element at a time. While in theminibuffer, use @kbd{M-p} or up-arrow (@code{previous-history-element})to ``move to'' the next earlier minibuffer input, and use @kbd{M-n} ordown-arrow (@code{next-history-element}) to ``move to'' the next laterinput. The previous input that you fetch from the history entirely replacesthe contents of the minibuffer. To use it as the argument, exit theminibuffer as usual with @key{RET}. You can also edit the text beforeyou reuse it; this does not change the history element that you``moved'' to, but your new argument does go at the end of the historylist in its own right. For many minibuffer arguments there is a ``default'' value. In somecases, the minibuffer history commands know the default value. Then youcan insert the default value into the minibuffer as text by using@kbd{M-n} to move ``into the future'' in the history. Eventually wehope to make this feature available whenever the minibuffer has adefault value.@findex previous-matching-history-element@findex next-matching-history-element@kindex M-r @r{(minibuffer history)}@kindex M-s @r{(minibuffer history)} There are also commands to search forward or backward through thehistory; they search for history elements that match a regularexpression that you specify with the minibuffer. @kbd{M-r}(@code{previous-matching-history-element}) searches older elements inthe history, while @kbd{M-s} (@code{next-matching-history-element})searches newer elements. By special dispensation, these commands canuse the minibuffer to read their arguments even though you are alreadyin the minibuffer when you issue them. As with incremental searching,an upper-case letter in the regular expression makes the searchcase-sensitive (@pxref{Search Case}).@ignore We may change the precise way these commands read their arguments.Perhaps they will search for a match for the string given so far in theminibuffer; perhaps they will search for a literal match rather than aregular expression match; perhaps they will only accept matches at thebeginning of a history element; perhaps they will read the string tosearch for incrementally like @kbd{C-s}. To find out what interface isactually available, type @kbd{C-h f previous-matching-history-element}.@end ignore All uses of the minibuffer record your input on a history list, butthere are separate history lists for different kinds of arguments. Forexample, there is a list for file names, used by all the commands thatread file names. (As a special feature, this history list recordsthe absolute file name, no more and no less, even if that is not howyou entered the file name.) There are several other very specific history lists, including one forcommand names read by @kbd{M-x}, one for buffer names, one for argumentsof commands like @code{query-replace}, and one for compilation commandsread by @code{compile}. Finally, there is one ``miscellaneous'' historylist that most minibuffer arguments use.@vindex history-length The variable @code{history-length} specifies the maximum length of aminibuffer history list; once a list gets that long, the oldest elementis deleted each time an element is added. If the value of@code{history-length} is @code{t}, though, there is no maximum lengthand elements are never deleted.@node Repetition@section Repeating Minibuffer Commands@cindex command history@cindex history of commands Every command that uses the minibuffer at least once is recorded on aspecial history list, together with the values of its arguments, so thatyou can repeat the entire command. In particular, every use of@kbd{M-x} is recorded there, since @kbd{M-x} uses the minibuffer to readthe command name.@findex list-command-history@table @kbd@item C-x @key{ESC} @key{ESC}Re-execute a recent minibuffer command (@code{repeat-complex-command}).@item M-x list-command-historyDisplay the entire command history, showing all the commands@kbd{C-x @key{ESC} @key{ESC}} can repeat, most recent first.@end table@kindex C-x ESC ESC@findex repeat-complex-command @kbd{C-x @key{ESC} @key{ESC}} is used to re-execute a recentminibuffer-using command. With no argument, it repeats the last suchcommand. A numeric argument specifies which command to repeat; onemeans the last one, and larger numbers specify earlier ones. @kbd{C-x @key{ESC} @key{ESC}} works by turning the previous commandinto a Lisp expression and then entering a minibuffer initialized withthe text for that expression. If you type just @key{RET}, the commandis repeated as before. You can also change the command by editing theLisp expression. Whatever expression you finally submit is what will beexecuted. The repeated command is added to the front of the commandhistory unless it is identical to the most recently executed commandalready there. Even if you don't understand Lisp syntax, it will probably be obviouswhich command is displayed for repetition. If you do not change thetext, it will repeat exactly as before. Once inside the minibuffer for @kbd{C-x @key{ESC} @key{ESC}}, you canuse the minibuffer history commands (@kbd{M-p}, @kbd{M-n}, @kbd{M-r},@kbd{M-s}; @pxref{Minibuffer History}) to move through the history listof saved entire commands. After finding the desired previous command,you can edit its expression as usual and then resubmit it by typing@key{RET} as usual.@vindex command-history The list of previous minibuffer-using commands is stored as a Lisplist in the variable @code{command-history}. Each element is a Lispexpression which describes one command and its arguments. Lisp programscan re-execute a command by calling @code{eval} with the@code{command-history} element.