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