]> code.delx.au - gnu-emacs/blob - doc/emacs/mini.texi
Add 2012 to FSF copyright years for Emacs files
[gnu-emacs] / doc / emacs / mini.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2012
3 @c Free Software Foundation, Inc.
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 where Emacs commands read complicated
10 arguments, such as file names, buffer names, Emacs command names, or
11 Lisp expressions. We call it the ``minibuffer'' because it's a
12 special-purpose buffer with a small amount of screen space. You can
13 use the usual Emacs editing commands in the minibuffer to edit the
14 argument text.
15
16 @cindex prompt
17 When the minibuffer is in use, it appears in the echo area, with a
18 cursor. The minibuffer starts with a @dfn{prompt} in a distinct
19 color, usually ending with a colon. The prompt states what kind of
20 input is expected, and how it will be used.
21
22 The simplest way to enter a minibuffer argument is to type the text,
23 then @key{RET} to submit the argument and exit the minibuffer. You
24 can cancel the minibuffer, and the command that wants the argument, by
25 typing @kbd{C-g}.
26
27 @cindex default argument
28 Sometimes, a @dfn{default argument} appears in the prompt, inside
29 parentheses before the colon. This default will be used as the
30 argument if you just type @key{RET}. For example, commands that read
31 buffer names usually show a buffer name as the default; you can type
32 @key{RET} to operate on that default buffer.
33
34 Since the minibuffer appears in the echo area, it can conflict with
35 other uses of the echo area. If an error message or an informative
36 message is emitted while the minibuffer is active, the message hides
37 the minibuffer for a few seconds, or until you type something; then
38 the minibuffer comes back. While the minibuffer is in use, keystrokes
39 do not echo.
40
41 @menu
42 * Minibuffer File:: Entering file names with the minibuffer.
43 * Minibuffer Edit:: How to edit in the minibuffer.
44 * Completion:: An abbreviation facility for minibuffer input.
45 * Minibuffer History:: Reusing recent minibuffer arguments.
46 * Repetition:: Re-executing commands that used the minibuffer.
47 * Passwords:: Entering passwords in the echo area.
48 @end menu
49
50 @node Minibuffer File
51 @section Minibuffers for File Names
52
53 @cindex default directory
54 Commands such as @kbd{C-x C-f} (@code{find-file}) use the minibuffer
55 to read a file name argument (@pxref{Basic Files}). When the
56 minibuffer is used to read a file name, it typically starts out with
57 some initial text ending in a slash. This is the @dfn{default
58 directory}. For example, it may start out like this:
59
60 @example
61 Find File: /u2/emacs/src/
62 @end example
63
64 @noindent
65 Here, @samp{Find File:@: } is the prompt and @samp{/u2/emacs/src/} is
66 the default directory. If you now type @kbd{buffer.c} as input, that
67 specifies the file @file{/u2/emacs/src/buffer.c}. @xref{File Names},
68 for information about the default directory.
69
70 You can specify the parent directory with @file{..}:
71 @file{/a/b/../foo.el} is equivalent to @file{/a/foo.el}.
72 Alternatively, you can use @kbd{M-@key{DEL}} to kill directory names
73 backwards (@pxref{Words}).
74
75 To specify a file in a completely different directory, you can kill
76 the entire default with @kbd{C-a C-k} (@pxref{Minibuffer Edit}).
77 Alternatively, you can ignore the default, and enter an absolute file
78 name starting with a slash or a tilde after the default directory.
79 For example, you can specify @file{/etc/termcap} as follows:
80
81 @example
82 Find File: /u2/emacs/src//etc/termcap
83 @end example
84
85 @noindent
86 @cindex // in file name
87 @cindex double slash in file name
88 @cindex slashes repeated in file name
89 @findex file-name-shadow-mode
90 Emacs interprets a double slash as ``ignore everything before the
91 second slash in the pair.'' In the example above,
92 @file{/u2/emacs/src/} is ignored, so the argument you supplied is
93 @file{/etc/termcap}. The ignored part of the file name is dimmed if
94 the terminal allows it. (To disable this dimming, turn off File Name
95 Shadow mode with the command @kbd{M-x file-name-shadow-mode}.)
96
97 @cindex home directory shorthand
98 Emacs interprets @file{~/} as your home directory. Thus,
99 @file{~/foo/bar.txt} specifies a file named @file{bar.txt}, inside a
100 directory named @file{foo}, which is in turn located in your home
101 directory. In addition, @file{~@var{user-id}/} means the home
102 directory of a user whose login name is @var{user-id}. Any leading
103 directory name in front of the @file{~} is ignored: thus,
104 @file{/u2/emacs/~/foo/bar.txt} is equivalent to @file{~/foo/bar.txt}.
105
106 On MS-Windows and MS-DOS systems, where a user doesn't always have a
107 home directory, Emacs uses several alternatives. For MS-Windows, see
108 @ref{Windows HOME}; for MS-DOS, see
109 @ifnottex
110 @ref{MS-DOS File Names}.
111 @end ifnottex
112 @iftex
113 @ref{MS-DOS File Names, HOME on MS-DOS,, emacs, the digital version of
114 the Emacs Manual}.
115 @end iftex
116 On these systems, the @file{~@var{user-id}/} construct is supported
117 only for the current user, i.e., only if @var{user-id} is the current
118 user's login name.
119
120 @vindex insert-default-directory
121 To prevent Emacs from inserting the default directory when reading
122 file names, change the variable @code{insert-default-directory} to
123 @code{nil}. In that case, the minibuffer starts out empty.
124 Nonetheless, relative file name arguments are still interpreted based
125 on the same default directory.
126
127 You can also enter remote file names in the minibuffer.
128 @xref{Remote Files}.
129
130 @node Minibuffer Edit
131 @section Editing in the Minibuffer
132
133 The minibuffer is an Emacs buffer, albeit a peculiar one, and the
134 usual Emacs commands are available for editing the argument text.
135 (The prompt, however, is @dfn{read-only}, and cannot be changed.)
136
137 Since @key{RET} in the minibuffer submits the argument, you can't
138 use it to insert a newline. You can do that with @kbd{C-q C-j}, which
139 inserts a @kbd{C-j} control character, which is formally equivalent to
140 a newline character (@pxref{Inserting Text}). Alternatively, you can
141 use the @kbd{C-o} (@code{open-line}) command (@pxref{Blank Lines}).
142
143 Inside a minibuffer, the keys @key{TAB}, @key{SPC}, and @kbd{?} are
144 often bound to @dfn{completion commands}, which allow you to easily
145 fill in the desired text without typing all of it. @xref{Completion}.
146 As with @key{RET}, you can use @kbd{C-q} to insert a @key{TAB},
147 @key{SPC}, or @samp{?} character.
148
149 For convenience, @kbd{C-a} (@code{move-beginning-of-line}) in a
150 minibuffer moves point to the beginning of the argument text, not the
151 beginning of the prompt. For example, this allows you to erase the
152 entire argument with @kbd{C-a C-k}.
153
154 @cindex height of minibuffer
155 @cindex size of minibuffer
156 @cindex growing minibuffer
157 @cindex resizing minibuffer
158 When the minibuffer is active, the echo area is treated much like an
159 ordinary Emacs window. For instance, you can switch to another window
160 (with @kbd{C-x o}), edit text there, then return to the minibuffer
161 window to finish the argument. You can even kill text in another
162 window, return to the minibuffer window, and yank the text into the
163 argument. There are some restrictions on the minibuffer window,
164 however: for instance, you cannot split it. @xref{Windows}.
165
166 @vindex resize-mini-windows
167 Normally, the minibuffer window occupies a single screen line.
168 However, if you add two or more lines' worth of text into the
169 minibuffer, it expands automatically to accommodate the text. The
170 variable @code{resize-mini-windows} controls the resizing of the
171 minibuffer. The default value is @code{grow-only}, which means the
172 behavior we have just described. If the value is @code{t}, the
173 minibuffer window will also shrink automatically if you remove some
174 lines of text from the minibuffer, down to a minimum of one screen
175 line. If the value is @code{nil}, the minibuffer window never changes
176 size automatically, but you can use the usual window-resizing commands
177 on it (@pxref{Windows}).
178
179 @vindex max-mini-window-height
180 The variable @code{max-mini-window-height} controls the maximum
181 height for resizing the minibuffer window. A floating-point number
182 specifies a fraction of the frame's height; an integer specifies the
183 maximum number of lines; @code{nil} means do not resize the minibuffer
184 window automatically. The default value is 0.25.
185
186 The @kbd{C-M-v} command in the minibuffer scrolls the help text from
187 commands that display help text of any sort in another window. You
188 can also scroll the help text with @kbd{M-@key{prior}} and
189 @kbd{M-@key{next}} (or, equivalently, @kbd{M-@key{PageUp}} and
190 @kbd{M-@key{PageDown}}). This is especially useful with long lists of
191 possible completions. @xref{Other Window}.
192
193 @vindex enable-recursive-minibuffers
194 Emacs normally disallows most commands that use the minibuffer while
195 the minibuffer is active. To allow such commands in the minibuffer,
196 set the variable @code{enable-recursive-minibuffers} to @code{t}.
197
198 @node Completion
199 @section Completion
200 @c This node is referenced in the tutorial. When renaming or deleting
201 @c it, the tutorial needs to be adjusted.
202 @cindex completion
203
204 You can often use a feature called @dfn{completion} to help enter
205 arguments. This means that after you type part of the argument, Emacs
206 can fill in the rest, or some of it, based on what was typed so far.
207
208 @cindex completion alternative
209 When completion is available, certain keys (usually @key{TAB},
210 @key{RET}, and @key{SPC}) are rebound in the minibuffer to special
211 completion commands (@pxref{Completion Commands}). These commands
212 attempt to complete the text in the minibuffer, based on a set of
213 @dfn{completion alternatives} provided by the command that requested
214 the argument. You can usually type @kbd{?} to see a list of
215 completion alternatives.
216
217 Although completion is usually done in the minibuffer, the feature
218 is sometimes available in ordinary buffers too. @xref{Symbol
219 Completion}.
220
221 @menu
222 * Completion Example:: Examples of using completion.
223 * Completion Commands:: A list of completion commands.
224 * Completion Exit:: Completion and minibuffer text submission.
225 * Completion Styles:: How completion matches are chosen.
226 * Completion Options:: Options for completion.
227 @end menu
228
229 @node Completion Example
230 @subsection Completion Example
231
232 @kindex TAB @r{(completion)}
233 A simple example may help here. @kbd{M-x} uses the minibuffer to
234 read the name of a command, so completion works by matching the
235 minibuffer text against the names of existing Emacs commands. Suppose
236 you wish to run the command @code{auto-fill-mode}. You can do that by
237 typing @kbd{M-x auto-fill-mode @key{RET}}, but it is easier to use
238 completion.
239
240 If you type @kbd{M-x a u @key{TAB}}, the @key{TAB} looks for
241 completion alternatives (in this case, command names) that start with
242 @samp{au}. There are several, including @code{auto-fill-mode} and
243 @code{autoconf-mode}, but they all begin with @code{auto}, so the
244 @samp{au} in the minibuffer completes to @samp{auto}.
245
246 If you type @key{TAB} again immediately, it cannot determine the
247 next character; it could be @samp{-}, @samp{a}, or @samp{c}. So it
248 does not add any characters; instead, @key{TAB} displays a list of all
249 possible completions in another window.
250
251 Next, type @kbd{-f}. The minibuffer now contains @samp{auto-f}, and
252 the only command name that starts with this is @code{auto-fill-mode}.
253 If you now type @key{TAB}, completion fills in the rest of the
254 argument @samp{auto-fill-mode} into the minibuffer.
255
256 Hence, typing just @kbd{a u @key{TAB} - f @key{TAB}} allows you to
257 enter @samp{auto-fill-mode}.
258
259 @node Completion Commands
260 @subsection Completion Commands
261
262 Here is a list of the completion commands defined in the minibuffer
263 when completion is allowed.
264
265 @table @kbd
266 @item @key{TAB}
267 @findex minibuffer-complete
268 Complete the text in the minibuffer as much as possible; if unable to
269 complete, display a list of possible completions
270 (@code{minibuffer-complete}).
271 @item @key{SPC}
272 Complete up to one word from the minibuffer text before point
273 (@code{minibuffer-complete-word}). This command is not available for
274 arguments that often include spaces, such as file names.
275 @item @key{RET}
276 Submit the text in the minibuffer as the argument, possibly completing
277 first (@code{minibuffer-complete-and-exit}). @xref{Completion Exit}.
278 @item ?
279 Display a list of completions (@code{minibuffer-completion-help}).
280 @end table
281
282 @kindex TAB @r{(completion)}
283 @findex minibuffer-complete
284 @key{TAB} (@code{minibuffer-complete}) is the most fundamental
285 completion command. It searches for all possible completions that
286 match the existing minibuffer text, and attempts to complete as much
287 as it can. @xref{Completion Styles}, for how completion alternatives
288 are chosen.
289
290 @kindex SPC @r{(completion)}
291 @findex minibuffer-complete-word
292 @key{SPC} (@code{minibuffer-complete-word}) completes like
293 @key{TAB}, but only up to the next hyphen or space. If you have
294 @samp{auto-f} in the minibuffer and type @key{SPC}, it finds that the
295 completion is @samp{auto-fill-mode}, but it only inserts @samp{ill-},
296 giving @samp{auto-fill-}. Another @key{SPC} at this point completes
297 all the way to @samp{auto-fill-mode}.
298
299 @kindex ? @r{(completion)}
300 @cindex completion list
301 If @key{TAB} or @key{SPC} is unable to complete, it displays a list
302 of matching completion alternatives (if there are any) in another
303 window. You can display the same list with @kbd{?}
304 (@code{minibuffer-completion-help}). The following commands can be
305 used with the completion list:
306
307 @table @kbd
308 @findex mouse-choose-completion
309 @item Mouse-1
310 @itemx Mouse-2
311 Clicking mouse button 1 or 2 on a completion alternative chooses it
312 (@code{mouse-choose-completion}).
313
314 @findex switch-to-completions
315 @item M-v
316 @itemx @key{PageUp}
317 @itemx @key{prior}
318 Typing @kbd{M-v}, while in the minibuffer, selects the window showing
319 the completion list (@code{switch-to-completions}). This paves the
320 way for using the commands below. @key{PageUp} or @key{prior} does
321 the same. You can also select the window in other ways
322 (@pxref{Windows}).
323
324 @findex choose-completion
325 @item @key{RET}
326 While in the completion list buffer, this chooses the completion at
327 point (@code{choose-completion}).
328
329 @findex next-completion
330 @item @key{Right}
331 While in the completion list buffer, this moves point to the following
332 completion alternative (@code{next-completion}).
333
334 @findex previous-completion
335 @item @key{Left}
336 While in the completion list buffer, this moves point to the previous
337 completion alternative (@code{previous-completion}).
338 @end table
339
340 @node Completion Exit
341 @subsection Completion Exit
342
343 @kindex RET @r{(completion in minibuffer)}
344 @findex minibuffer-complete-and-exit
345 When a command reads an argument using the minibuffer with
346 completion, it also controls what happens when you type @key{RET}
347 (@code{minibuffer-complete-and-exit}) to submit the argument. There
348 are four types of behavior:
349
350 @itemize @bullet
351 @item
352 @dfn{Strict completion} accepts only exact completion matches. Typing
353 @key{RET} exits the minibuffer only if the minibuffer text is an exact
354 match, or completes to one. Otherwise, Emacs refuses to exit the
355 minibuffer; instead it tries to complete, and if no completion can be
356 done it momentarily displays @samp{[No match]} after the minibuffer
357 text. (You can still leave the minibuffer by typing @kbd{C-g} to
358 cancel the command.)
359
360 An example of a command that uses this behavior is @kbd{M-x}, since it
361 is meaningless for it to accept a non-existent command name.
362
363 @item
364 @dfn{Cautious completion} is like strict completion, except @key{RET}
365 exits only if the text is already an exact match. If the text
366 completes to an exact match, @key{RET} performs that completion but
367 does not exit yet; you must type a second @key{RET} to exit.
368
369 Cautious completion is used for reading file names for files that must
370 already exist, for example.
371
372 @item
373 @dfn{Permissive completion} allows any input; the completion
374 candidates are just suggestions. Typing @key{RET} does not complete,
375 it just submits the argument as you have entered it.
376
377 @cindex minibuffer confirmation
378 @cindex confirming in the minibuffer
379 @item
380 @dfn{Permissive completion with confirmation} is like permissive
381 completion, with an exception: if you typed @key{TAB} and this
382 completed the text up to some intermediate state (i.e. one that is not
383 yet an exact completion match), typing @key{RET} right afterward does
384 not submit the argument. Instead, Emacs asks for confirmation by
385 momentarily displaying @samp{[Confirm]} after the text; type @key{RET}
386 again to confirm and submit the text. This catches a common mistake,
387 in which one types @key{RET} before realizing that @key{TAB} did not
388 complete as far as desired.
389
390 @vindex confirm-nonexistent-file-or-buffer
391 You can tweak the confirmation behavior by customizing the variable
392 @code{confirm-nonexistent-file-or-buffer}. The default value,
393 @code{after-completion}, gives the behavior we have just described.
394 If you change it to @code{nil}, Emacs does not ask for confirmation,
395 falling back on permissive completion. If you change it to any other
396 non-@code{nil} value, Emacs asks for confirmation whether or not the
397 preceding command was @key{TAB}.
398
399 This behavior is used by most commands that read file names, like
400 @kbd{C-x C-f}, and commands that read buffer names, like @kbd{C-x b}.
401 @end itemize
402
403 @node Completion Styles
404 @subsection How Completion Alternatives Are Chosen
405 @cindex completion style
406
407 Completion commands work by narrowing a large list of possible
408 completion alternatives to a smaller subset that ``matches'' what you
409 have typed in the minibuffer. In @ref{Completion Example}, we gave a
410 simple example of such matching. The procedure of determining what
411 constitutes a ``match'' is quite intricate. Emacs attempts to offer
412 plausible completions under most circumstances.
413
414 Emacs performs completion using one or more @dfn{completion
415 styles}---sets of criteria for matching minibuffer text to completion
416 alternatives. During completion, Emacs tries each completion style in
417 turn. If a style yields one or more matches, that is used as the list
418 of completion alternatives. If a style produces no matches, Emacs
419 falls back on the next style.
420
421 @vindex completion-styles
422 The list variable @code{completion-styles} specifies the completion
423 styles to use. Each list element is the name of a completion style (a
424 Lisp symbol). The default completion styles are (in order):
425
426 @table @code
427 @item basic
428 A matching completion alternative must have the same beginning as the
429 text in the minibuffer before point. Furthermore, if there is any
430 text in the minibuffer after point, the rest of the completion
431 alternative must contain that text as a substring.
432
433 @findex partial completion
434 @item partial-completion
435 This aggressive completion style divides the minibuffer text into
436 words separated by hyphens or spaces, and completes each word
437 separately. (For example, when completing command names,
438 @samp{em-l-m} completes to @samp{emacs-lisp-mode}.)
439
440 Furthermore, a @samp{*} in the minibuffer text is treated as a
441 @dfn{wildcard}---it matches any character at the corresponding
442 position in the completion alternative.
443
444 @item emacs22
445 This completion style is similar to @code{basic}, except that it
446 ignores the text in the minibuffer after point. It is so-named
447 because it corresponds to the completion behavior in Emacs 22 and
448 earlier.
449 @end table
450
451 @noindent
452 The following additional completion styles are also defined, and you
453 can add them to @code{completion-styles} if you wish
454 (@pxref{Customization}):
455
456 @table @code
457 @item substring
458 A matching completion alternative must contain the text in the
459 minibuffer before point, and the text in the minibuffer after point,
460 as substrings (in that same order).
461
462 Thus, if the text in the minibuffer is @samp{foobar}, with point
463 between @samp{foo} and @samp{bar}, that matches
464 @samp{@var{a}foo@var{b}bar@var{c}}, where @var{a}, @var{b}, and
465 @var{c} can be any string including the empty string.
466
467 @item initials
468 This very aggressive completion style attempts to complete acronyms
469 and initialisms. For example, when completing command names, it
470 matches @samp{lch} to @samp{list-command-history}.
471 @end table
472
473 @node Completion Options
474 @subsection Completion Options
475
476 @cindex case-sensitivity and completion
477 @cindex case in completion
478 Case is significant when completing case-sensitive arguments, such
479 as command names. For example, when completing command names,
480 @samp{AU} does not complete to @samp{auto-fill-mode}. Case
481 differences are ignored when completing arguments in which case does
482 not matter.
483
484 @vindex read-file-name-completion-ignore-case
485 @vindex read-buffer-completion-ignore-case
486 When completing file names, case differences are ignored if the
487 variable @code{read-file-name-completion-ignore-case} is
488 non-@code{nil}. The default value is @code{nil} on systems that have
489 case-sensitive file-names, such as GNU/Linux; it is non-@code{nil} on
490 systems that have case-insensitive file-names, such as Microsoft
491 Windows. When completing buffer names, case differences are ignored
492 if the variable @code{read-buffer-completion-ignore-case} is
493 non-@code{nil}; the default is @code{nil}.
494
495 @vindex completion-ignored-extensions
496 @cindex ignored file names, in completion
497 When completing file names, Emacs usually omits certain alternatives
498 that are considered unlikely to be chosen, as determined by the list
499 variable @code{completion-ignored-extensions}. Each element in the
500 list should be a string; any file name ending in such a string is
501 ignored as a completion alternative. Any element ending in a slash
502 (@file{/}) represents a subdirectory name. The standard value of
503 @code{completion-ignored-extensions} has several elements including
504 @code{".o"}, @code{".elc"}, and @code{"~"}. For example, if a
505 directory contains @samp{foo.c} and @samp{foo.elc}, @samp{foo}
506 completes to @samp{foo.c}. However, if @emph{all} possible
507 completions end in ``ignored'' strings, they are not ignored: in the
508 previous example, @samp{foo.e} completes to @samp{foo.elc}. Emacs
509 disregards @code{completion-ignored-extensions} when showing
510 completion alternatives in the completion list.
511
512 @vindex completion-auto-help
513 If @code{completion-auto-help} is set to @code{nil}, the completion
514 commands never display the completion list buffer; you must type
515 @kbd{?} to display the list. If the value is @code{lazy}, Emacs only
516 shows the completion list buffer on the second attempt to complete.
517 In other words, if there is nothing to complete, the first @key{TAB}
518 echoes @samp{Next char not unique}; the second @key{TAB} does the
519 completion list buffer.
520
521 @vindex completion-cycle-threshold
522 If @code{completion-cycle-threshold} is non-@code{nil}, completion
523 commands can ``cycle'' through completion alternatives. Normally, if
524 there is more than one completion alternative for the text in the
525 minibuffer, a completion command completes up to the longest common
526 substring. If you change @code{completion-cycle-threshold} to
527 @code{t}, the completion command instead completes to the first of
528 those completion alternatives; each subsequent invocation of the
529 completion command replaces that with the next completion alternative,
530 in a cyclic manner. If you give @code{completion-cycle-threshold} a
531 numeric value @var{n}, completion commands switch to this cycling
532 behavior only when there are fewer than @var{n} alternatives.
533
534 @cindex Icomplete mode
535 @findex icomplete-mode
536 Icomplete mode presents a constantly-updated display that tells you
537 what completions are available for the text you've entered so far. The
538 command to enable or disable this minor mode is @kbd{M-x
539 icomplete-mode}.
540
541 @node Minibuffer History
542 @section Minibuffer History
543 @cindex minibuffer history
544 @cindex history of minibuffer input
545
546 Every argument that you enter with the minibuffer is saved in a
547 @dfn{minibuffer history list} so you can easily use it again later.
548 You can use the following arguments to quickly fetch an earlier
549 argument into the minibuffer:
550
551 @table @kbd
552 @item M-p
553 @itemx @key{Up}
554 Move to the previous item in the minibuffer history, an earlier
555 argument (@code{previous-history-element}).
556 @item M-n
557 @itemx @key{Down}
558 Move to the next item in the minibuffer history
559 (@code{next-history-element}).
560 @item M-r @var{regexp} @key{RET}
561 Move to an earlier item in the minibuffer history that
562 matches @var{regexp} (@code{previous-matching-history-element}).
563 @item M-s @var{regexp} @key{RET}
564 Move to a later item in the minibuffer history that matches
565 @var{regexp} (@code{next-matching-history-element}).
566 @end table
567
568 @kindex M-p @r{(minibuffer history)}
569 @kindex M-n @r{(minibuffer history)}
570 @kindex UP @r{(minibuffer history)}
571 @kindex DOWN @r{(minibuffer history)}
572 @findex next-history-element
573 @findex previous-history-element
574 While in the minibuffer, @kbd{M-p} or @key{Up}
575 (@code{previous-history-element}) moves through the minibuffer history
576 list, one item at a time. Each @kbd{M-p} fetches an earlier item from
577 the history list into the minibuffer, replacing its existing contents.
578 Typing @kbd{M-n} or @key{Down} (@code{next-history-element}) moves
579 through the minibuffer history list in the opposite direction,
580 fetching later entries into the minibuffer.
581
582 If you type @kbd{M-n} in the minibuffer when there are no later
583 entries in the minibuffer history (e.g., if you haven't previously
584 typed @kbd{M-p}), Emacs tries fetching from a list of default
585 arguments: values that you are likely to enter. You can think of this
586 as moving through the ``future history'' list.
587
588 If you edit the text inserted by the @kbd{M-p} or @key{M-n}
589 minibuffer history commands, this does not change its entry in the
590 history list. However, the edited argument does go at the end of the
591 history list when you submit it.
592
593 @findex previous-matching-history-element
594 @findex next-matching-history-element
595 @kindex M-r @r{(minibuffer history)}
596 @kindex M-s @r{(minibuffer history)}
597 You can use @kbd{M-r} (@code{previous-matching-history-element}) to
598 search through older elements in the history list, and @kbd{M-s}
599 (@code{next-matching-history-element}) to search through newer
600 entries. Each of these commands asks for a @dfn{regular expression}
601 as an argument, and fetches the first matching entry into the
602 minibuffer. @xref{Regexps}, for an explanation of regular
603 expressions. A numeric prefix argument @var{n} means to fetch the
604 @var{n}th matching entry. These commands are unusual, in that they
605 use the minibuffer to read the regular expression argument, even
606 though they are invoked from the minibuffer. An upper-case letter in
607 the regular expression makes the search case-sensitive (@pxref{Search
608 Case}).
609
610 You can also search through the history using an incremental search.
611 @xref{Isearch Minibuffer}.
612
613 Emacs keeps separate history lists for several different kinds of
614 arguments. For example, there is a list for file names, used by all
615 the commands that read file names. Other history lists include buffer
616 names, command names (used by @kbd{M-x}), and command arguments (used
617 by commands like @code{query-replace}).
618
619 @vindex history-length
620 The variable @code{history-length} specifies the maximum length of a
621 minibuffer history list; adding a new element deletes the oldest
622 element if the list gets too long. If the value is @code{t}, there is
623 no maximum length.
624
625 @vindex history-delete-duplicates
626 The variable @code{history-delete-duplicates} specifies whether to
627 delete duplicates in history. If it is non-@code{nil}, adding a new
628 element deletes from the list all other elements that are equal to it.
629 The default is @code{nil}.
630
631 @node Repetition
632 @section Repeating Minibuffer Commands
633 @cindex command history
634 @cindex history of commands
635
636 Every command that uses the minibuffer once is recorded on a special
637 history list, the @dfn{command history}, together with the values of
638 its arguments, so that you can repeat the entire command. In
639 particular, every use of @kbd{M-x} is recorded there, since @kbd{M-x}
640 uses the minibuffer to read the command name.
641
642 @findex list-command-history
643 @table @kbd
644 @item C-x @key{ESC} @key{ESC}
645 Re-execute a recent minibuffer command from the command history
646 (@code{repeat-complex-command}).
647 @item M-x list-command-history
648 Display the entire command history, showing all the commands
649 @kbd{C-x @key{ESC} @key{ESC}} can repeat, most recent first.
650 @end table
651
652 @kindex C-x ESC ESC
653 @findex repeat-complex-command
654 @kbd{C-x @key{ESC} @key{ESC}} re-executes a recent command that used
655 the minibuffer. With no argument, it repeats the last such command.
656 A numeric argument specifies which command to repeat; 1 means the last
657 one, 2 the previous, and so on.
658
659 @kbd{C-x @key{ESC} @key{ESC}} works by turning the previous command
660 into a Lisp expression and then entering a minibuffer initialized with
661 the text for that expression. Even if you don't know Lisp, it will
662 probably be obvious which command is displayed for repetition. If you
663 type just @key{RET}, that repeats the command unchanged. You can also
664 change the command by editing the Lisp expression before you execute
665 it. The repeated command is added to the front of the command history
666 unless it is identical to the most recent item.
667
668 Once inside the minibuffer for @kbd{C-x @key{ESC} @key{ESC}}, you
669 can use the usual minibuffer history commands (@pxref{Minibuffer
670 History}) to move through the history list. After finding the desired
671 previous command, you can edit its expression as usual and then repeat
672 it by typing @key{RET}.
673
674 @vindex isearch-resume-in-command-history
675 Incremental search does not, strictly speaking, use the minibuffer.
676 Therefore, although it behaves like a complex command, it normally
677 does not appear in the history list for @kbd{C-x @key{ESC} @key{ESC}}.
678 You can make incremental search commands appear in the history by
679 setting @code{isearch-resume-in-command-history} to a non-@code{nil}
680 value. @xref{Incremental Search}.
681
682 @vindex command-history
683 The list of previous minibuffer-using commands is stored as a Lisp
684 list in the variable @code{command-history}. Each element is a Lisp
685 expression which describes one command and its arguments. Lisp programs
686 can re-execute a command by calling @code{eval} with the
687 @code{command-history} element.
688
689 @node Passwords
690 @section Entering passwords
691
692 Sometimes, you may need to enter a password into Emacs. For instance,
693 when you tell Emacs to visit a file on another machine via a network
694 protocol such as FTP, you often need to supply a password to gain
695 access to the machine (@pxref{Remote Files}).
696
697 Entering a password is similar to using a minibuffer. Emacs
698 displays a prompt in the echo area (such as @samp{Password: }); after
699 you type the required password, press @key{RET} to submit it. To
700 prevent others from seeing your password, every character you type is
701 displayed as a dot (@samp{.}) instead of its usual form.
702
703 Most of the features and commands associated with the minibuffer can
704 @emph{not} be used when entering a password. There is no history or
705 completion, and you cannot change windows or perform any other action
706 with Emacs until you have submitted the password.
707
708 While you are typing the password, you may press @key{DEL} to delete
709 backwards, removing the last character entered. @key{C-u} deletes
710 everything you have typed so far. @kbd{C-g} quits the password prompt
711 (@pxref{Quitting}). @kbd{C-y} inserts the current kill into the
712 password (@pxref{Killing}). You may type either @key{RET} or
713 @key{ESC} to submit the password. Any other self-inserting character
714 key inserts the associated character into the password, and all other
715 input is ignored.