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