Mention remote file name completion in Emacs manual
[emacs.git] / doc / emacs / mini.texi
blob35cffc1db923080b099b58e7a9fd69b89c7ffc21
1 @c -*- coding: utf-8 -*-
2 @c This is part of the Emacs manual.
3 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2018 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-arg}]}
61 instead of @samp{(default @var{default-arg})}, saving some screen
62 space.  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   Alternative defaults for the file name you may want are available by
93 typing @kbd{M-n}, see @ref{Minibuffer History}.
95   You can specify a file in the parent directory with @file{..}:
96 @file{/a/b/../foo.el} is equivalent to @file{/a/foo.el}.
97 Alternatively, you can use @kbd{M-@key{DEL}} to kill directory names
98 backwards (@pxref{Words}).
100   To specify a file in a completely different directory, you can kill
101 the entire default with @kbd{C-a C-k} (@pxref{Minibuffer Edit}).
102 Alternatively, you can ignore the default, and enter an absolute file
103 name starting with a slash or a tilde after the default directory.
104 For example, you can specify @file{/etc/termcap} as follows:
106 @example
107 Find file: /u2/emacs/src//etc/termcap
108 @end example
110 @noindent
111 @cindex // in file name
112 @cindex double slash in file name
113 @cindex slashes repeated in file name
114 @findex file-name-shadow-mode
115 A double slash causes Emacs to ignore everything before the
116 second slash in the pair.  In the example above,
117 @file{/u2/emacs/src/} is ignored, so the argument you supplied is
118 @file{/etc/termcap}.  The ignored part of the file name is dimmed if
119 the terminal allows it.  (To disable this dimming, turn off File Name
120 Shadow mode with the command @kbd{M-x file-name-shadow-mode}.)
122   When completing remote file names (@pxref{Remote Files}), a double
123 slash behaves slightly differently: it causes Emacs to ignore only the
124 file-name part, leaving the rest (method, host and username, etc.)
125 intact.  Typing three slashes in a row ignores everything in remote
126 file names.  @xref{File name completion,,, tramp, The Tramp Manual}.
128 @cindex home directory shorthand
129   Emacs interprets @file{~/} as your home directory.  Thus,
130 @file{~/foo/bar.txt} specifies a file named @file{bar.txt}, inside a
131 directory named @file{foo}, which is in turn located in your home
132 directory.  In addition, @file{~@var{user-id}/} means the home
133 directory of a user whose login name is @var{user-id}.  Any leading
134 directory name in front of the @file{~} is ignored: thus,
135 @file{/u2/emacs/~/foo/bar.txt} is equivalent to @file{~/foo/bar.txt}.
137   On MS-Windows and MS-DOS systems, where a user doesn't always have a
138 home directory, Emacs uses several alternatives.  For MS-Windows, see
139 @ref{Windows HOME}; for MS-DOS, see
140 @ifnottex
141 @ref{MS-DOS File Names}.
142 @end ifnottex
143 @iftex
144 @ref{MS-DOS File Names, HOME on MS-DOS,, emacs, the digital version of
145 the Emacs Manual}.
146 @end iftex
147 On these systems, the @file{~@var{user-id}/} construct is supported
148 only for the current user, i.e., only if @var{user-id} is the current
149 user's login name.
151 @vindex insert-default-directory
152   To prevent Emacs from inserting the default directory when reading
153 file names, change the variable @code{insert-default-directory} to
154 @code{nil}.  In that case, the minibuffer starts out empty.
155 Nonetheless, relative file name arguments are still interpreted based
156 on the same default directory.
158   You can also enter remote file names in the minibuffer.
159 @xref{Remote Files}.
161 @node Minibuffer Edit
162 @section Editing in the Minibuffer
164   The minibuffer is an Emacs buffer, albeit a peculiar one, and the
165 usual Emacs commands are available for editing the argument text.
166 (The prompt, however, is @dfn{read-only}, and cannot be changed.)
168   Since @key{RET} in the minibuffer submits the argument, you can't
169 use it to insert a newline.  You can do that with @kbd{C-q C-j}, which
170 inserts a @kbd{C-j} control character, which is formally equivalent to
171 a newline character (@pxref{Inserting Text}).  Alternatively, you can
172 use the @kbd{C-o} (@code{open-line}) command (@pxref{Blank Lines}).
174   Inside a minibuffer, the keys @key{TAB}, @key{SPC}, and @kbd{?} are
175 often bound to @dfn{completion commands}, which allow you to easily
176 fill in the desired text without typing all of it.  @xref{Completion}.
177 As with @key{RET}, you can use @kbd{C-q} to insert a @key{TAB},
178 @key{SPC}, or @samp{?}  character.
180   For convenience, @kbd{C-a} (@code{move-beginning-of-line}) in a
181 minibuffer moves point to the beginning of the argument text, not the
182 beginning of the prompt.  For example, this allows you to erase the
183 entire argument with @kbd{C-a C-k}.
185 @cindex height of minibuffer
186 @cindex size of minibuffer
187 @cindex growing minibuffer
188 @cindex resizing minibuffer
189   When the minibuffer is active, the echo area is treated much like an
190 ordinary Emacs window.  For instance, you can switch to another window
191 (with @kbd{C-x o}), edit text there, then return to the minibuffer
192 window to finish the argument.  You can even kill text in another
193 window, return to the minibuffer window, and yank the text into the
194 argument.  There are some restrictions on the minibuffer window,
195 however: for instance, you cannot split it.  @xref{Windows}.
197 @vindex resize-mini-windows
198   Normally, the minibuffer window occupies a single screen line.
199 However, if you add two or more lines' worth of text into the
200 minibuffer, it expands automatically to accommodate the text.  The
201 variable @code{resize-mini-windows} controls the resizing of the
202 minibuffer.  The default value is @code{grow-only}, which means the
203 behavior we have just described.  If the value is @code{t}, the
204 minibuffer window will also shrink automatically if you remove some
205 lines of text from the minibuffer, down to a minimum of one screen
206 line.  If the value is @code{nil}, the minibuffer window never changes
207 size automatically, but you can use the usual window-resizing commands
208 on it (@pxref{Windows}).
210 @vindex max-mini-window-height
211   The variable @code{max-mini-window-height} controls the maximum
212 height for resizing the minibuffer window.  A floating-point number
213 specifies a fraction of the frame's height; an integer specifies the
214 maximum number of lines; @code{nil} means do not resize the minibuffer
215 window automatically.  The default value is 0.25.
217   The @kbd{C-M-v} command in the minibuffer scrolls the help text from
218 commands that display help text of any sort in another window.  You
219 can also scroll the help text with @kbd{M-@key{prior}} and
220 @kbd{M-@key{next}} (or, equivalently, @kbd{M-@key{PageUp}} and
221 @kbd{M-@key{PageDown}}).  This is especially useful with long lists of
222 possible completions.  @xref{Other Window}.
224 @vindex enable-recursive-minibuffers
225   Emacs normally disallows most commands that use the minibuffer while
226 the minibuffer is active.  To allow such commands in the minibuffer,
227 set the variable @code{enable-recursive-minibuffers} to @code{t}.
229 @findex minibuffer-inactive-mode
230   When not active, the minibuffer is in @code{minibuffer-inactive-mode},
231 and clicking @kbd{mouse-1} there shows the @file{*Messages*} buffer.
232 If you use a dedicated frame for minibuffers, Emacs also recognizes
233 certain keys there, for example, @kbd{n} to make a new frame.
235 @node Completion
236 @section Completion
237 @c This node is referenced in the tutorial.  When renaming or deleting
238 @c it, the tutorial needs to be adjusted.
239 @cindex completion
241   You can often use a feature called @dfn{completion} to help enter
242 arguments.  This means that after you type part of the argument, Emacs
243 can fill in the rest, or some of it, based on what was typed so far.
245 @cindex completion alternative
246   When completion is available, certain keys (usually @key{TAB},
247 @key{RET}, and @key{SPC}) are rebound in the minibuffer to special
248 completion commands (@pxref{Completion Commands}).  These commands
249 attempt to complete the text in the minibuffer, based on a set of
250 @dfn{completion alternatives} provided by the command that requested
251 the argument.  You can usually type @kbd{?} to see a list of
252 completion alternatives.
254   Although completion is usually done in the minibuffer, the feature
255 is sometimes available in ordinary buffers too.  @xref{Symbol
256 Completion}.
258 @menu
259 * Completion Example::       Examples of using completion.
260 * Completion Commands::      A list of completion commands.
261 * Completion Exit::          Completion and minibuffer text submission.
262 * Completion Styles::        How completion matches are chosen.
263 * Completion Options::       Options for completion.
264 @end menu
266 @node Completion Example
267 @subsection Completion Example
269 @kindex TAB @r{(completion example)}
270   A simple example may help here.  @kbd{M-x} uses the minibuffer to
271 read the name of a command, so completion works by matching the
272 minibuffer text against the names of existing Emacs commands.  Suppose
273 you wish to run the command @code{auto-fill-mode}.  You can do that by
274 typing @kbd{M-x auto-fill-mode @key{RET}}, but it is easier to use
275 completion.
277   If you type @kbd{M-x a u @key{TAB}}, the @key{TAB} looks for
278 completion alternatives (in this case, command names) that start with
279 @samp{au}.  There are several, including @code{auto-fill-mode} and
280 @code{autoconf-mode}, but they all begin with @code{auto}, so the
281 @samp{au} in the minibuffer completes to @samp{auto}.  (More commands
282 may be defined in your Emacs session.  For example, if a command
283 called @code{authorize-me} was defined, Emacs could only complete
284 as far as @samp{aut}.)
286   If you type @key{TAB} again immediately, it cannot determine the
287 next character; it could be @samp{-}, @samp{a}, or @samp{c}.  So it
288 does not add any characters; instead, @key{TAB} displays a list of all
289 possible completions in another window.
291   Next, type @kbd{-f}.  The minibuffer now contains @samp{auto-f}, and
292 the only command name that starts with this is @code{auto-fill-mode}.
293 If you now type @key{TAB}, completion fills in the rest of the
294 argument @samp{auto-fill-mode} into the minibuffer.
296   Hence, typing just @kbd{a u @key{TAB} - f @key{TAB}} allows you to
297 enter @samp{auto-fill-mode}.
299 @node Completion Commands
300 @subsection Completion Commands
302   Here is a list of the completion commands defined in the minibuffer
303 when completion is allowed.
305 @table @kbd
306 @item @key{TAB}
307 Complete the text in the minibuffer as much as possible; if unable to
308 complete, display a list of possible completions
309 (@code{minibuffer-complete}).
310 @item @key{SPC}
311 Complete up to one word from the minibuffer text before point
312 (@code{minibuffer-complete-word}).  This command is not available for
313 arguments that often include spaces, such as file names.
314 @item @key{RET}
315 Submit the text in the minibuffer as the argument, possibly completing
316 first (@code{minibuffer-complete-and-exit}).  @xref{Completion Exit}.
317 @item ?
318 Display a list of completions (@code{minibuffer-completion-help}).
319 @end table
321 @kindex TAB @r{(completion)}
322 @findex minibuffer-complete
323   @key{TAB} (@code{minibuffer-complete}) is the most fundamental
324 completion command.  It searches for all possible completions that
325 match the existing minibuffer text, and attempts to complete as much
326 as it can.  @xref{Completion Styles}, for how completion alternatives
327 are chosen.
329 @kindex SPC @r{(completion)}
330 @findex minibuffer-complete-word
331   @key{SPC} (@code{minibuffer-complete-word}) completes like
332 @key{TAB}, but only up to the next hyphen or space.  If you have
333 @samp{auto-f} in the minibuffer and type @key{SPC}, it finds that the
334 completion is @samp{auto-fill-mode}, but it only inserts @samp{ill-},
335 giving @samp{auto-fill-}.  Another @key{SPC} at this point completes
336 all the way to @samp{auto-fill-mode}.
338 @kindex ? @r{(completion)}
339 @cindex completion list
340   If @key{TAB} or @key{SPC} is unable to complete, it displays a list
341 of matching completion alternatives (if there are any) in another
342 window.  You can display the same list with @kbd{?}
343 (@code{minibuffer-completion-help}).  The following commands can be
344 used with the completion list:
346 @table @kbd
347 @findex mouse-choose-completion
348 @item mouse-1
349 @itemx mouse-2
350 Clicking mouse button 1 or 2 on a completion alternative chooses it
351 (@code{mouse-choose-completion}).
353 @findex switch-to-completions
354 @item M-v
355 @itemx @key{PageUp}
356 @itemx @key{prior}
357 Typing @kbd{M-v}, while in the minibuffer, selects the window showing
358 the completion list (@code{switch-to-completions}).  This paves the
359 way for using the commands below.  @key{PageUp} or @key{prior} does
360 the same.  You can also select the window in other ways
361 (@pxref{Windows}).
363 @findex choose-completion
364 @item @key{RET}
365 While in the completion list buffer, this chooses the completion at
366 point (@code{choose-completion}).
368 @findex next-completion
369 @item @key{RIGHT}
370 While in the completion list buffer, this moves point to the following
371 completion alternative (@code{next-completion}).
373 @findex previous-completion
374 @item @key{LEFT}
375 While in the completion list buffer, this moves point to the previous
376 completion alternative (@code{previous-completion}).
377 @end table
379 @node Completion Exit
380 @subsection Completion Exit
382 @kindex RET @r{(completion in minibuffer)}
383 @findex minibuffer-complete-and-exit
384   When a command reads an argument using the minibuffer with
385 completion, it also controls what happens when you type @key{RET}
386 (@code{minibuffer-complete-and-exit}) to submit the argument.  There
387 are four types of behavior:
389 @itemize @bullet
390 @item
391 @dfn{Strict completion} accepts only exact completion matches.  Typing
392 @key{RET} exits the minibuffer only if the minibuffer text is an exact
393 match, or completes to one.  Otherwise, Emacs refuses to exit the
394 minibuffer; instead it tries to complete, and if no completion can be
395 done it momentarily displays @samp{[No match]} after the minibuffer
396 text.  (You can still leave the minibuffer by typing @kbd{C-g} to
397 cancel the command.)
399 An example of a command that uses this behavior is @kbd{M-x}, since it
400 is meaningless for it to accept a non-existent command name.
402 @item
403 @dfn{Cautious completion} is like strict completion, except @key{RET}
404 exits only if the text is already an exact match.  If the text
405 completes to an exact match, @key{RET} performs that completion but
406 does not exit yet; you must type a second @key{RET} to exit.
408 Cautious completion is used for reading file names for files that must
409 already exist, for example.
411 @item
412 @dfn{Permissive completion} allows any input; the completion
413 candidates are just suggestions.  Typing @key{RET} does not complete,
414 it just submits the argument as you have entered it.
416 @cindex minibuffer confirmation
417 @cindex confirming in the minibuffer
418 @item
419 @dfn{Permissive completion with confirmation} is like permissive
420 completion, with an exception: if you typed @key{TAB} and this
421 completed the text up to some intermediate state (i.e., one that is not
422 yet an exact completion match), typing @key{RET} right afterward does
423 not submit the argument.  Instead, Emacs asks for confirmation by
424 momentarily displaying @samp{[Confirm]} after the text; type @key{RET}
425 again to confirm and submit the text.  This catches a common mistake,
426 in which one types @key{RET} before realizing that @key{TAB} did not
427 complete as far as desired.
429 @vindex confirm-nonexistent-file-or-buffer
430 You can tweak the confirmation behavior by customizing the variable
431 @code{confirm-nonexistent-file-or-buffer}.  The default value,
432 @code{after-completion}, gives the behavior we have just described.
433 If you change it to @code{nil}, Emacs does not ask for confirmation,
434 falling back on permissive completion.  If you change it to any other
435 non-@code{nil} value, Emacs asks for confirmation whether or not the
436 preceding command was @key{TAB}.
438 This behavior is used by most commands that read file names, like
439 @kbd{C-x C-f}, and commands that read buffer names, like @kbd{C-x b}.
440 @end itemize
442 @node Completion Styles
443 @subsection How Completion Alternatives Are Chosen
444 @cindex completion style
446   Completion commands work by narrowing a large list of possible
447 completion alternatives to a smaller subset that matches what you
448 have typed in the minibuffer.  In @ref{Completion Example}, we gave a
449 simple example of such matching.  The procedure of determining what
450 constitutes a match is quite intricate.  Emacs attempts to offer
451 plausible completions under most circumstances.
453   Emacs performs completion using one or more @dfn{completion
454 styles}---sets of criteria for matching minibuffer text to completion
455 alternatives.  During completion, Emacs tries each completion style in
456 turn.  If a style yields one or more matches, that is used as the list
457 of completion alternatives.  If a style produces no matches, Emacs
458 falls back on the next style.
460 @vindex completion-styles
461   The list variable @code{completion-styles} specifies the completion
462 styles to use.  Each list element is the name of a completion style (a
463 Lisp symbol).  The default completion styles are (in order):
465 @table @code
466 @item basic
467 A matching completion alternative must have the same beginning as the
468 text in the minibuffer before point.  Furthermore, if there is any
469 text in the minibuffer after point, the rest of the completion
470 alternative must contain that text as a substring.
472 @findex partial completion
473 @item partial-completion
474 This aggressive completion style divides the minibuffer text into
475 words separated by hyphens or spaces, and completes each word
476 separately.  (For example, when completing command names,
477 @samp{em-l-m} completes to @samp{emacs-lisp-mode}.)
479 Furthermore, a @samp{*} in the minibuffer text is treated as a
480 @dfn{wildcard}---it matches any string of characters at the
481 corresponding position in the completion alternative.
483 @item emacs22
484 This completion style is similar to @code{basic}, except that it
485 ignores the text in the minibuffer after point.  It is so-named
486 because it corresponds to the completion behavior in Emacs 22.
487 @end table
489 @noindent
490 The following additional completion styles are also defined, and you
491 can add them to @code{completion-styles} if you wish
492 (@pxref{Customization}):
494 @table @code
495 @item substring
496 A matching completion alternative must contain the text in the
497 minibuffer before point, and the text in the minibuffer after point,
498 as substrings (in that same order).
500 Thus, if the text in the minibuffer is @samp{foobar}, with point
501 between @samp{foo} and @samp{bar}, that matches
502 @samp{@var{a}foo@var{b}bar@var{c}}, where @var{a}, @var{b}, and
503 @var{c} can be any string including the empty string.
505 @item initials
506 This very aggressive completion style attempts to complete acronyms
507 and initialisms.  For example, when completing command names, it
508 matches @samp{lch} to @samp{list-command-history}.
509 @end table
511 @noindent
512 There is also a very simple completion style called @code{emacs21}.
513 In this style, if the text in the minibuffer is @samp{foobar},
514 only matches starting with @samp{foobar} are considered.
516 @vindex completion-category-overrides
517 You can use different completion styles in different situations,
518 by setting the variable @code{completion-category-overrides}.
519 For example, the default setting says to use only @code{basic}
520 and @code{substring} completion for buffer names.
523 @node Completion Options
524 @subsection Completion Options
526 @cindex case-sensitivity and completion
527 @cindex case in completion
528   Case is significant when completing case-sensitive arguments, such
529 as command names.  For example, when completing command names,
530 @samp{AU} does not complete to @samp{auto-fill-mode}.  Case
531 differences are ignored when completing arguments in which case does
532 not matter.
534 @vindex read-file-name-completion-ignore-case
535 @vindex read-buffer-completion-ignore-case
536   When completing file names, case differences are ignored if the
537 variable @code{read-file-name-completion-ignore-case} is
538 non-@code{nil}.  The default value is @code{nil} on systems that have
539 case-sensitive file-names, such as GNU/Linux; it is non-@code{nil} on
540 systems that have case-insensitive file-names, such as Microsoft
541 Windows.  When completing buffer names, case differences are ignored
542 if the variable @code{read-buffer-completion-ignore-case} is
543 non-@code{nil}; the default is @code{nil}.
545 @vindex completion-ignored-extensions
546 @cindex ignored file names, in completion
547   When completing file names, Emacs usually omits certain alternatives
548 that are considered unlikely to be chosen, as determined by the list
549 variable @code{completion-ignored-extensions}.  Each element in the
550 list should be a string; any file name ending in such a string is
551 ignored as a completion alternative.  Any element ending in a slash
552 (@file{/}) represents a subdirectory name.  The standard value of
553 @code{completion-ignored-extensions} has several elements including
554 @code{".o"}, @code{".elc"}, and @code{"~"}.  For example, if a
555 directory contains @samp{foo.c} and @samp{foo.elc}, @samp{foo}
556 completes to @samp{foo.c}.  However, if @emph{all} possible
557 completions end in otherwise-ignored strings, they are not ignored: in the
558 previous example, @samp{foo.e} completes to @samp{foo.elc}.  Emacs
559 disregards @code{completion-ignored-extensions} when showing
560 completion alternatives in the completion list.
562   Shell completion is an extended version of filename completion,
563 @pxref{Shell Options}.
565 @vindex completion-auto-help
566   If @code{completion-auto-help} is set to @code{nil}, the completion
567 commands never display the completion list buffer; you must type
568 @kbd{?}  to display the list.  If the value is @code{lazy}, Emacs only
569 shows the completion list buffer on the second attempt to complete.
570 In other words, if there is nothing to complete, the first @key{TAB}
571 echoes @samp{Next char not unique}; the second @key{TAB} shows the
572 completion list buffer.
574 @vindex completion-cycle-threshold
575   If @code{completion-cycle-threshold} is non-@code{nil}, completion
576 commands can cycle through completion alternatives.  Normally, if
577 there is more than one completion alternative for the text in the
578 minibuffer, a completion command completes up to the longest common
579 substring.  If you change @code{completion-cycle-threshold} to
580 @code{t}, the completion command instead completes to the first of
581 those completion alternatives; each subsequent invocation of the
582 completion command replaces that with the next completion alternative,
583 in a cyclic manner.  If you give @code{completion-cycle-threshold} a
584 numeric value @var{n}, completion commands switch to this cycling
585 behavior only when there are @var{n} or fewer alternatives.
587 @node Minibuffer History
588 @section Minibuffer History
589 @cindex minibuffer history
590 @cindex history of minibuffer input
592   Every argument that you enter with the minibuffer is saved in a
593 @dfn{minibuffer history list} so you can easily use it again later.
594 You can use the following arguments to quickly fetch an earlier
595 argument into the minibuffer:
597 @table @kbd
598 @item M-p
599 Move to the previous item in the minibuffer history, an earlier
600 argument (@code{previous-history-element}).
601 @item M-n
602 Move to the next item in the minibuffer history
603 (@code{next-history-element}).
604 @item @key{UP}
605 @itemx @key{DOWN}
606 Like @kbd{M-p} and @kbd{M-n}, but move to the previous or next line of
607 a multi-line item before going to the previous history item
608 (@code{previous-line-or-history-element} and
609 @code{next-line-or-history-element}) .
610 @item M-r @var{regexp} @key{RET}
611 Move to an earlier item in the minibuffer history that
612 matches @var{regexp} (@code{previous-matching-history-element}).
613 @item M-s @var{regexp} @key{RET}
614 Move to a later item in the minibuffer history that matches
615 @var{regexp} (@code{next-matching-history-element}).
616 @end table
618 @kindex M-p @r{(minibuffer history)}
619 @kindex M-n @r{(minibuffer history)}
620 @findex next-history-element
621 @findex previous-history-element
622   While in the minibuffer, @kbd{M-p} (@code{previous-history-element})
623 moves through the minibuffer history list, one item at a time.  Each
624 @kbd{M-p} fetches an earlier item from the history list into the
625 minibuffer, replacing its existing contents.  Typing @kbd{M-n}
626 (@code{next-history-element}) moves through the minibuffer history
627 list in the opposite direction, fetching later entries into the
628 minibuffer.
630   If you type @kbd{M-n} in the minibuffer when there are no later
631 entries in the minibuffer history (e.g., if you haven't previously
632 typed @kbd{M-p}), Emacs tries fetching from a list of default
633 arguments: values that you are likely to enter.  You can think of this
634 as moving through the ``future history''.
636 @cindex future history for file names
637 @cindex minibuffer defaults for file names
638 @vindex file-name-at-point-functions
639   The ``future history'' for file names includes several possible
640 alternatives you may find useful, such as the file name or the URL at
641 point in the current buffer.  The defaults put into the ``future
642 history'' in this case are controlled by the functions mentioned in
643 the value of the option @code{file-name-at-point-functions}.  By
644 default, its value invokes the @code{ffap} package (@pxref{FFAP}),
645 which tries to guess the default file or URL from the text around
646 point.  To disable this guessing, customize the option to a @code{nil}
647 value, then the ``future history'' of file names will include only the
648 file, if any, visited by the current buffer, and the default
649 directory.
651 @findex previous-line-or-history-element
652 @findex next-line-or-history-element
653 @kindex UP @r{(minibuffer history)}
654 @kindex DOWN @r{(minibuffer history)}
655   The arrow keys @kbd{@key{UP}} and @kbd{@key{DOWN}} work like
656 @kbd{M-p} and @kbd{M-n}, but if the current history item is longer
657 than a single line, they allow you to move to the previous or next
658 line of the current history item before going to the previous or next
659 history item.
661   If you edit the text inserted by the @kbd{M-p} or @kbd{M-n}
662 minibuffer history commands, this does not change its entry in the
663 history list.  However, the edited argument does go at the end of the
664 history list when you submit it.
666 @findex previous-matching-history-element
667 @findex next-matching-history-element
668 @kindex M-r @r{(minibuffer history)}
669 @kindex M-s @r{(minibuffer history)}
670   You can use @kbd{M-r} (@code{previous-matching-history-element}) to
671 search through older elements in the history list, and @kbd{M-s}
672 (@code{next-matching-history-element}) to search through newer
673 entries.  Each of these commands asks for a @dfn{regular expression}
674 as an argument, and fetches the first matching entry into the
675 minibuffer.  @xref{Regexps}, for an explanation of regular
676 expressions.  A numeric prefix argument @var{n} means to fetch the
677 @var{n}th matching entry.  These commands are unusual, in that they
678 use the minibuffer to read the regular expression argument, even
679 though they are invoked from the minibuffer.  An upper-case letter in
680 the regular expression makes the search case-sensitive (@pxref{Lax
681 Search}).
683   You can also search through the history using an incremental search.
684 @xref{Isearch Minibuffer}.
686   Emacs keeps separate history lists for several different kinds of
687 arguments.  For example, there is a list for file names, used by all
688 the commands that read file names.  Other history lists include buffer
689 names, command names (used by @kbd{M-x}), and command arguments (used
690 by commands like @code{query-replace}).
692 @vindex history-length
693   The variable @code{history-length} specifies the maximum length of a
694 minibuffer history list; adding a new element deletes the oldest
695 element if the list gets too long.  If the value is @code{t}, there is
696 no maximum length.
698 @vindex history-delete-duplicates
699   The variable @code{history-delete-duplicates} specifies whether to
700 delete duplicates in history.  If it is non-@code{nil}, adding a new
701 element deletes from the list all other elements that are equal to it.
702 The default is @code{nil}.
704 @node Repetition
705 @section Repeating Minibuffer Commands
706 @cindex command history
707 @cindex history of commands
709   Every command that uses the minibuffer once is recorded on a special
710 history list, the @dfn{command history}, together with the values of
711 its arguments, so that you can repeat the entire command.  In
712 particular, every use of @kbd{M-x} is recorded there, since @kbd{M-x}
713 uses the minibuffer to read the command name.
715 @findex list-command-history
716 @table @kbd
717 @item C-x @key{ESC} @key{ESC}
718 Re-execute a recent minibuffer command from the command history
719  (@code{repeat-complex-command}).
720 @item M-x list-command-history
721 Display the entire command history, showing all the commands
722 @kbd{C-x @key{ESC} @key{ESC}} can repeat, most recent first.
723 @end table
725 @kindex C-x ESC ESC
726 @findex repeat-complex-command
727   @kbd{C-x @key{ESC} @key{ESC}} re-executes a recent command that used
728 the minibuffer.  With no argument, it repeats the last such command.
729 A numeric argument specifies which command to repeat; 1 means the last
730 one, 2 the previous, and so on.
732   @kbd{C-x @key{ESC} @key{ESC}} works by turning the previous command
733 into a Lisp expression and then entering a minibuffer initialized with
734 the text for that expression.  Even if you don't know Lisp, it will
735 probably be obvious which command is displayed for repetition.  If you
736 type just @key{RET}, that repeats the command unchanged.  You can also
737 change the command by editing the Lisp expression before you execute
738 it.  The executed command is added to the front of the command history
739 unless it is identical to the most recent item.
741   Once inside the minibuffer for @kbd{C-x @key{ESC} @key{ESC}}, you
742 can use the usual minibuffer history commands (@pxref{Minibuffer
743 History}) to move through the history list.  After finding the desired
744 previous command, you can edit its expression as usual and then execute
745 it by typing @key{RET}.
747 @vindex isearch-resume-in-command-history
748   Incremental search does not, strictly speaking, use the minibuffer.
749 Therefore, although it behaves like a complex command, it normally
750 does not appear in the history list for @kbd{C-x @key{ESC} @key{ESC}}.
751 You can make incremental search commands appear in the history by
752 setting @code{isearch-resume-in-command-history} to a non-@code{nil}
753 value.  @xref{Incremental Search}.
755 @vindex command-history
756   The list of previous minibuffer-using commands is stored as a Lisp
757 list in the variable @code{command-history}.  Each element is a Lisp
758 expression that describes one command and its arguments.  Lisp programs
759 can re-execute a command by calling @code{eval} with the
760 @code{command-history} element.
762 @node Passwords
763 @section Entering passwords
765 Sometimes, you may need to enter a password into Emacs.  For instance,
766 when you tell Emacs to visit a file on another machine via a network
767 protocol such as FTP, you often need to supply a password to gain
768 access to the machine (@pxref{Remote Files}).
770   Entering a password is similar to using a minibuffer.  Emacs
771 displays a prompt in the echo area (such as @samp{Password: }); after
772 you type the required password, press @key{RET} to submit it.  To
773 prevent others from seeing your password, every character you type is
774 displayed as a dot (@samp{.}) instead of its usual form.
776   Most of the features and commands associated with the minibuffer can
777 @emph{not} be used when entering a password.  There is no history or
778 completion, and you cannot change windows or perform any other action
779 with Emacs until you have submitted the password.
781   While you are typing the password, you may press @key{DEL} to delete
782 backwards, removing the last character entered.  @kbd{C-u} deletes
783 everything you have typed so far.  @kbd{C-g} quits the password prompt
784 (@pxref{Quitting}).  @kbd{C-y} inserts the current kill into the
785 password (@pxref{Killing}).  You may type either @key{RET} or
786 @key{ESC} to submit the password.  Any other self-inserting character
787 key inserts the associated character into the password, and all other
788 input is ignored.
790 @node Yes or No Prompts
791 @section Yes or No Prompts
793   An Emacs command may require you to answer a yes-or-no question
794 during the course of its execution.  Such queries come in two main
795 varieties.
797 @cindex y or n prompt
798   For the first type of yes-or-no query, the prompt ends with
799 @samp{(y or n)}.  Such a query does not actually use the minibuffer;
800 the prompt appears in the echo area, and you answer by typing either
801 @samp{y} or @samp{n}, which immediately delivers the response.  For
802 example, if you type @kbd{C-x C-w} (@kbd{write-file}) to save a
803 buffer, and enter the name of an existing file, Emacs issues a prompt
804 like this:
806 @smallexample
807 File ‘foo.el’ exists; overwrite? (y or n)
808 @end smallexample
810 @noindent
811 Because this query does not actually use the minibuffer, the usual
812 minibuffer editing commands cannot be used.  However, you can perform
813 some window scrolling operations while the query is active: @kbd{C-l}
814 recenters the selected window; @kbd{C-v} (or @key{PageDown} or
815 @key{next}) scrolls forward; @kbd{M-v} (or @key{PageUp}, or
816 @key{prior}) scrolls backward; @kbd{C-M-v} scrolls forward in the next
817 window; and @kbd{C-M-S-v} scrolls backward in the next window.  Typing
818 @kbd{C-g} dismisses the query, and quits the command that issued it
819 (@pxref{Quitting}).
821 @cindex yes or no prompt
822   The second type of yes-or-no query is typically employed if
823 giving the wrong answer would have serious consequences; it uses the
824 minibuffer, and features a prompt ending with @samp{(yes or no)}.  For
825 example, if you invoke @kbd{C-x k} (@code{kill-buffer}) on a
826 file-visiting buffer with unsaved changes, Emacs activates the
827 minibuffer with a prompt like this:
829 @smallexample
830 Buffer foo.el modified; kill anyway? (yes or no)
831 @end smallexample
833 @noindent
834 To answer, you must type @samp{yes} or @samp{no} into the minibuffer,
835 followed by @key{RET}.  The minibuffer behaves as described in the
836 previous sections; you can switch to another window with @kbd{C-x o},
837 use the history commands @kbd{M-p} and @kbd{M-n}, etc.  Type @kbd{C-g}
838 to quit the minibuffer and the querying command.