mini.texi 28.6 KB
Newer Older
Glenn Morris's avatar
Glenn Morris committed
1 2
@c This is part of the Emacs manual.
@c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001,
3
@c   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4
@c   Free Software Foundation, Inc.
Glenn Morris's avatar
Glenn Morris committed
5 6 7 8 9 10
@c See file emacs.texi for copying conditions.
@node Minibuffer, M-x, Basic, Top
@chapter The Minibuffer
@cindex minibuffer

  The @dfn{minibuffer} is where Emacs commands read complicated
11 12 13 14 15
arguments, such as file names, buffer names, Emacs command names, or
Lisp expressions.  We call it the ``minibuffer'' because it's a
special-purpose buffer with a small amount of screen space.  You can
use the usual Emacs editing commands in the minibuffer to edit the
argument text.
Glenn Morris's avatar
Glenn Morris committed
16 17 18 19

@cindex prompt
  When the minibuffer is in use, it appears in the echo area, with a
cursor.  The minibuffer display starts with a @dfn{prompt} in a
20 21 22 23 24 25 26
distinct color, usually ending with a colon.  The prompt states what
kind of input is expected, and how it will be used.

  The simplest way to enter a minibuffer argument is to type the text,
then @key{RET} to submit the argument and exit the minibuffer.  You
can cancel the minibuffer, and the command that wants the argument, by
typing @kbd{C-g}.
Glenn Morris's avatar
Glenn Morris committed
27 28

@cindex default argument
29
  Sometimes, a @dfn{default argument} appears in the prompt, inside
Glenn Morris's avatar
Glenn Morris committed
30 31
parentheses before the colon.  The default will be used as the
argument value if you just type @key{RET}.  For example, commands that
32 33
read buffer names usually show a buffer name as the default; you can
type @key{RET} to operate on that default buffer.
Glenn Morris's avatar
Glenn Morris committed
34 35

  Since the minibuffer appears in the echo area, it can conflict with
36 37 38 39 40 41 42
other uses of the echo area.  If an error occurs while the minibuffer
is active, the error message hides the minibuffer for a few seconds,
or until you type something; then the minibuffer comes back.  If a
command such as @kbd{C-x =} needs to display a message in the echo
area, the message hides the minibuffer for a few seconds, or until you
type something; then the minibuffer comes back.  While the minibuffer
is in use, keystrokes do not echo.
Glenn Morris's avatar
Glenn Morris committed
43 44

@menu
45 46
* Minibuffer File::       Entering file names with the minibuffer.
* Minibuffer Edit::       How to edit in the minibuffer.
47
* Completion::            An abbreviation facility for minibuffer input.
Glenn Morris's avatar
Glenn Morris committed
48
* Minibuffer History::    Reusing recent minibuffer arguments.
49
* Repetition::            Re-executing commands that used the minibuffer.
Chong Yidong's avatar
Chong Yidong committed
50
* Passwords::             Entering passwords in the echo area.
Glenn Morris's avatar
Glenn Morris committed
51 52 53 54 55
@end menu

@node Minibuffer File
@section Minibuffers for File Names

56 57 58
  Commands such as @kbd{C-x C-f} (@code{find-file}) use the minibuffer
to read a file name argument (@pxref{Basic Files}).  When the
minibuffer is used to read a file name, it typically starts out with
59 60
some initial text ending in a slash.  This is the @dfn{default
directory}.  For example, it may start out like this:
Glenn Morris's avatar
Glenn Morris committed
61 62 63 64 65 66

@example
Find File: /u2/emacs/src/
@end example

@noindent
67 68
Here, @samp{Find File:@: } is the prompt and @samp{/u2/emacs/src/} is
the default directory.  If you now type @kbd{buffer.c} as input, that
69 70
specifies the file @file{/u2/emacs/src/buffer.c}.  @xref{File Names},
for information about the default directory.
71 72 73 74 75 76 77 78 79 80 81

  You can specify the parent directory by adding @file{..}: for
example, @file{/u2/emacs/src/../lisp/simple.el} is equivalent to
@file{/u2/emacs/lisp/simple.el}.  Alternatively, you can use
@kbd{M-@key{DEL}} to kill directory names backwards (@pxref{Words}).

  To specify a file in a completely different directory, you can kill
the entire default with @kbd{C-a C-k} (@pxref{Minibuffer Edit}).
Alternatively, you can ignore the default, and enter an absolute file
name starting with a slash or a tilde after the default directory.
For example, you can specify @file{/etc/termcap} as follows:
Glenn Morris's avatar
Glenn Morris committed
82 83 84 85 86 87 88 89 90 91

@example
Find File: /u2/emacs/src//etc/termcap
@end example

@noindent
@cindex // in file name
@cindex double slash in file name
@cindex slashes repeated in file name
@findex file-name-shadow-mode
92 93
Emacs interprets a double slash as ``ignore everything before the
second slash in the pair.''  In the example above,
94
@file{/u2/emacs/src/} is ignored, so the argument you supplied is
95 96 97 98 99
@file{/etc/termcap}.  The ignored part of the file name is dimmed if
the terminal allows it (to disable this dimming, turn off File Name
Shadow mode with the command @kbd{M-x file-name-shadow-mode}.)

@cindex home directory shorthand
100 101 102
  Emacs interprets @file{~/} as your home directory.  Thus,
@file{~/foo/bar.txt} specifies a file named @file{bar.txt}, inside a
directory named @file{foo}, which is in turn located in your home
103
directory.  In addition, @file{~@var{user-id}/} means the home
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
directory of a user whose login name is @var{user-id}.  Any leading
directory name in front of the @file{~} is ignored: thus,
@file{/u2/emacs/~/foo/bar.txt} is equivalent to @file{~/foo/bar.txt}.

  On MS-Windows and MS-DOS systems, where a user doesn't always have a
home directory, Emacs uses several alternatives.  For MS-Windows, see
@ref{Windows HOME}; for MS-DOS, see
@ifnottex
@ref{MS-DOS File Names, HOME on MS-DOS}.
@end ifnottex
@iftex
@ref{MS-DOS File Names, HOME on MS-DOS,, emacs, the Emacs Manual}, in
the main Emacs manual.
@end iftex
On these systems, the @file{~@var{user-id}/} construct is supported
only for the current user, i.e., only if @var{user-id} is the current
user's login name.
121 122

@vindex insert-default-directory
123 124 125 126 127
  To prevent Emacs from inserting the default directory when reading
file names, change the variable @code{insert-default-directory} to
@code{nil}.  In that case, the minibuffer starts out empty.
Nonetheless, relative file name arguments are still interpreted based
on the same default directory.
Glenn Morris's avatar
Glenn Morris committed
128 129 130 131

@node Minibuffer Edit
@section Editing in the Minibuffer

132
  The minibuffer is an Emacs buffer, albeit a peculiar one, and the
Glenn Morris's avatar
Glenn Morris committed
133
usual Emacs commands are available for editing the argument text.
134
(The prompt, however, is @dfn{read-only}, and cannot be changed.)
Glenn Morris's avatar
Glenn Morris committed
135 136 137 138 139 140

  Since @key{RET} in the minibuffer is defined to exit the minibuffer,
you can't use it to insert a newline in the minibuffer.  To do that,
type @kbd{C-o} or @kbd{C-q C-j}.  (The newline character is really the
@acronym{ASCII} character control-J.)

141 142 143 144 145 146 147 148 149 150 151
  Inside a minibuffer, the keys @kbd{@key{TAB}}, @kbd{@key{SPC}}, and
@kbd{@key{?}} are often bound to commands that perform
@dfn{completion}.  @xref{Completion}.  You can use @kbd{C-q}
(@code{quoted-insert}) to insert a @key{TAB}, @key{SPC}, or @key{?}
character.  For example, @kbd{C-q @key{TAB}} inserts a @key{TAB}
character.  @xref{Inserting Text}.

  For convenience, @kbd{C-a} (@code{move-beginning-of-line}) in a
minibuffer moves point to the beginning of the argument text, not the
beginning of the prompt.  For example, this allows you to erase the
entire argument with @kbd{C-a C-k}.
Glenn Morris's avatar
Glenn Morris committed
152 153 154 155 156

@cindex height of minibuffer
@cindex size of minibuffer
@cindex growing minibuffer
@cindex resizing minibuffer
157 158 159 160 161 162 163
  When the minibuffer is active, the echo area is treated much like an
ordinary Emacs window.  For instance, you can switch to another window
(with @kbd{C-x o}), edit text there, then return to the minibuffer
window to finish the argument.  You can even kill text in another
window, return to the minibuffer window, and yank the text into the
argument.  There are some restrictions on the minibuffer window,
however: for instance, you cannot split it.  @xref{Windows}.
Glenn Morris's avatar
Glenn Morris committed
164 165

@vindex resize-mini-windows
166 167
  Normally, the minibuffer window occupies a single screen line.
However, if you add two or more lines' worth of text into the
Juanma Barranquero's avatar
Juanma Barranquero committed
168
minibuffer, it expands automatically to accommodate the text.  The
169 170 171 172 173 174 175 176
variable @code{resize-mini-windows} controls the resizing of the
minibuffer.  The default value is @code{grow-only}, which means the
behavior we have just described.  If the value is @code{t}, the
minibuffer window will also shrink automatically if you remove some
lines of text from the minibuffer, down to a minimum of one screen
line.  If the value is @code{nil}, the minibuffer window never changes
size automatically, but you can use the usual window-resizing commands
on it (@pxref{Windows}).
Glenn Morris's avatar
Glenn Morris committed
177 178 179

@vindex max-mini-window-height
  The variable @code{max-mini-window-height} controls the maximum
180
height for resizing the minibuffer window.  A floating-point number
Glenn Morris's avatar
Glenn Morris committed
181 182 183 184 185
specifies a fraction of the frame's height; an integer specifies the
maximum number of lines; @code{nil} means do not resize the minibuffer
window automatically.  The default value is 0.25.

  The @kbd{C-M-v} command in the minibuffer scrolls the help text from
186 187 188 189 190
commands that display help text of any sort in another window.  You
can also scroll the help text with @kbd{M-@key{prior}} and
@kbd{M-@key{next}} (or, equivalently, @kbd{M-@key{PageUp}} and
@kbd{M-@key{PageDown}}).  This is especially useful with long lists of
possible completions.  @xref{Other Window}.
Glenn Morris's avatar
Glenn Morris committed
191 192 193

@vindex enable-recursive-minibuffers
  Emacs normally disallows most commands that use the minibuffer while
194 195
the minibuffer is active.  To allow such commands in the minibuffer,
set the variable @code{enable-recursive-minibuffers} to @code{t}.
Glenn Morris's avatar
Glenn Morris committed
196 197 198

@node Completion
@section Completion
199 200
@c This node is referenced in the tutorial.  When renaming or deleting
@c it, the tutorial needs to be adjusted.
Glenn Morris's avatar
Glenn Morris committed
201
@cindex completion
202 203 204 205 206 207 208 209 210 211 212 213 214

  Sometimes, you can use a feature called @dfn{completion} to help you
enter arguments.  This means that after you type part of the argument,
Emacs can fill in the rest, or some of it, based on what you have
typed so far.

  When completion is available, certain keys (usually @key{TAB},
@key{RET}, and @key{SPC}) are rebound to complete the text in the
minibuffer into a longer string chosen from a set of @dfn{completion
alternatives}.  The set of completion alternatives depends on the
command that requested the argument, and on what you have typed so
far.  In addition, you can usually type @kbd{?} to display a list of
possible completions.
Glenn Morris's avatar
Glenn Morris committed
215 216

  For example, @kbd{M-x} uses the minibuffer to read the name of a
217 218 219 220
command, so completion works by matching the minibuffer text against
the names of existing Emacs commands.  So, to run the command
@code{insert-buffer}, you can type @kbd{M-x ins @key{SPC} b @key{RET}}
instead of the full @kbd{M-x insert-buffer @key{RET}}.
Glenn Morris's avatar
Glenn Morris committed
221 222

  Case is significant in completion when it is significant in the
223 224
argument you are entering, such as command names.  Thus,
@samp{insert-buffer} is not a valid completion for @samp{IN}.
Glenn Morris's avatar
Glenn Morris committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238
Completion ignores case distinctions for certain arguments in which
case does not matter.

@menu
* Example: Completion Example.    Examples of using completion.
* Commands: Completion Commands.  A list of completion commands.
* Strict Completion::             Different types of completion.
* Options: Completion Options.    Options for completion.
@end menu

@node Completion Example
@subsection Completion Example

@kindex TAB @r{(completion)}
239
  A concrete example may help here.  If you type @kbd{M-x a u
Glenn Morris's avatar
Glenn Morris committed
240 241
@key{TAB}}, the @key{TAB} looks for alternatives (in this case,
command names) that start with @samp{au}.  There are several,
242 243 244
including @code{auto-fill-mode} and @code{autoconf-mode}, but they all
begin with @code{auto}, so the @samp{au} in the minibuffer completes
to @samp{auto}.
Glenn Morris's avatar
Glenn Morris committed
245 246

  If you type @key{TAB} again immediately, it cannot determine the
247 248 249
next character; it could be @samp{-}, @samp{a}, or @samp{c}.  So it
does not add any characters; instead, @key{TAB} displays a list of all
possible completions in another window.
Glenn Morris's avatar
Glenn Morris committed
250

251 252 253 254 255 256
  Next, type @kbd{- f}.  The minibuffer now contains @samp{auto-f},
and the only command name that starts with this is
@code{auto-fill-mode}.  If you now type @key{TAB}, completion fills in
the rest of the argument @samp{auto-fill-mode} into the minibuffer.
You have been able to enter @samp{auto-fill-mode} by typing just
@kbd{a u @key{TAB} - f @key{TAB}}.
Glenn Morris's avatar
Glenn Morris committed
257 258 259 260 261 262 263 264 265 266

@node Completion Commands
@subsection Completion Commands

  Here is a list of the completion commands defined in the minibuffer
when completion is allowed.

@table @kbd
@item @key{TAB}
@findex minibuffer-complete
267 268
Complete the text in the minibuffer as much as possible; if unable to
complete, display a list of possible completions
Glenn Morris's avatar
Glenn Morris committed
269 270 271 272 273 274 275 276
(@code{minibuffer-complete}).
@item @key{SPC}
Complete up to one word from the minibuffer text before point
(@code{minibuffer-complete-word}).  @key{SPC} for completion is not
available when entering a file name, since file names often include
spaces.
@item @key{RET}
Submit the text in the minibuffer as the argument, possibly completing
277
first as described in the next
Glenn Morris's avatar
Glenn Morris committed
278
@iftex
279
subsection (@code{minibuffer-complete-and-exit}).
Glenn Morris's avatar
Glenn Morris committed
280 281
@end iftex
@ifnottex
282
node (@code{minibuffer-complete-and-exit}).  @xref{Strict Completion}.
Glenn Morris's avatar
Glenn Morris committed
283 284 285 286 287 288
@end ifnottex
@item ?
Display a list of possible completions of the text before point
(@code{minibuffer-completion-help}).
@end table

289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
@kindex TAB
@findex minibuffer-complete
  @key{TAB} (@code{minibuffer-complete}) is the most fundamental
completion command.  It searches for all possible completion
alternatives that match the existing minibuffer text, and attempts to
complete as much as it can.  The matching of completion alternatives
to the minibuffer text is performed according to somewhat intricate
rules, which are designed so that plausible completions are offered
under most circumstances.  A valid completion alternative must satisfy
the following criteria:

@itemize @bullet
@item
The minibuffer text before point must be the same as the beginning of
the completion alternative.  If there is any minibuffer text after
point, it must be a substring of the remainder of the completion
alternative.

@item
If no completion alternative satisfies the above rules, try using
@dfn{partial completion} rules: divide the minibuffer text into words
separated by hyphens or spaces, and complete each word separately.
Thus, when completing command names, @samp{em-l-m} completes to
@samp{emacs-lisp-mode}.

@item
If there is still no completion alternative, try the first rule again,
but ignore the minibuffer text after point (i.e., don't try matching
it).
@end itemize

@noindent
When performing these comparisons, a @samp{*} in the minibuffer text
acts as a @dfn{wildcard}---it matches any character at the
corresponding position in the completion alternative.

Glenn Morris's avatar
Glenn Morris committed
325 326
@kindex SPC
@findex minibuffer-complete-word
327 328 329 330 331 332
  @key{SPC} (@code{minibuffer-complete-word}) completes like
@key{TAB}, but only up to the next hyphen or space.  If you have
@samp{auto-f} in the minibuffer and type @key{SPC}, it finds that the
completion is @samp{auto-fill-mode}, but it only inserts @samp{ill-},
giving @samp{auto-fill-}.  Another @key{SPC} at this point completes
all the way to @samp{auto-fill-mode}.
Glenn Morris's avatar
Glenn Morris committed
333

334 335 336
  If @key{TAB} or @key{SPC} is unable to complete, it displays a list
of possible completions (if there are any) in a separate window.  You
can choose a completion from this list using the following commands:
Glenn Morris's avatar
Glenn Morris committed
337 338 339 340 341 342

@table @kbd
@findex mouse-choose-completion
@item Mouse-1
@itemx Mouse-2
Clicking mouse button 1 or 2 on a completion possibility chooses that
343
completion (@code{mouse-choose-completion}).
Glenn Morris's avatar
Glenn Morris committed
344 345

@findex switch-to-completions
346 347
@item M-v
@itemx @key{PageUp}
348
@itemx @key{prior}
349 350 351
Typing @kbd{M-v}, while in the minibuffer, selects the window showing
the completion list buffer (@code{switch-to-completions}).  This paves
the way for using the commands below.  Typing @key{PageUp} or
352
@key{prior} does the same, as does selecting that window in other
353
ways.
Glenn Morris's avatar
Glenn Morris committed
354 355 356

@findex choose-completion
@item @key{RET}
357
Typing @key{RET}, while in the completion list buffer, chooses the
Glenn Morris's avatar
Glenn Morris committed
358 359 360 361
completion that point is in or next to (@code{choose-completion}).  To
use this command, you must first switch to the completion list window.

@findex next-completion
362 363 364
@item @key{Right}
Typing the right-arrow key @key{Right}, while in the completion list
buffer, moves point to the following completion possibility
Glenn Morris's avatar
Glenn Morris committed
365 366 367
(@code{next-completion}).

@findex previous-completion
368 369 370
@item @key{Left}
Typing the left-arrow key @key{Left}, while in the completion list
buffer, moves point to the previous completion possibility
Glenn Morris's avatar
Glenn Morris committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
(@code{previous-completion}).
@end table

@node Strict Completion
@subsection Strict Completion

  There are three different ways that @key{RET} can do completion,
depending on how the argument will be used.

@itemize @bullet
@item
@dfn{Strict} completion accepts only known completion candidates.  For
example, when @kbd{C-x k} reads the name of a buffer to kill, only the
name of an existing buffer makes sense.  In strict completion,
@key{RET} refuses to exit if the text in the minibuffer does not
complete to an exact match.

@item
@dfn{Cautious} completion is similar to strict completion, except that
@key{RET} exits only if the text is an already exact match.
Otherwise, @key{RET} does not exit, but it does complete the text.  If
that completes to an exact match, a second @key{RET} will exit.

Cautious completion is used for reading file names for files that must
already exist, for example.

@item
@dfn{Permissive} completion allows any input; the completion
candidates are just suggestions.  For example, when @kbd{C-x C-f}
reads the name of a file to visit, any file name is allowed, including
nonexistent file (in case you want to create a file).  In permissive
completion, @key{RET} does not complete, it just submits the argument
as you have entered it.
@end itemize

  The completion commands display a list of all possible completions
whenever they can't determine even one more character by completion.
Also, typing @kbd{?} explicitly requests such a list.  You can scroll
the list with @kbd{C-M-v} (@pxref{Other Window}).

@node Completion Options
@subsection Completion Options

414 415 416 417 418 419 420
@vindex completion-auto-help
  If @code{completion-auto-help} is set to @code{nil}, the completion
commands never display the completion list buffer; you must type
@kbd{?}  to display the list.  If the value is @code{lazy}, Emacs only
shows the completion list buffer on the second attempt to complete.
In other words, if there is nothing to complete, the first @key{TAB}
echoes @samp{Next char not unique}; the second @key{TAB} does the
Juanma Barranquero's avatar
Juanma Barranquero committed
421
completion list buffer.
422

Glenn Morris's avatar
Glenn Morris committed
423 424 425 426 427 428
@vindex completion-ignored-extensions
@cindex ignored file names, in completion
  When completing file names, certain file names are usually ignored.
The variable @code{completion-ignored-extensions} contains a list of
strings; a file name ending in any of those strings is ignored as a
completion candidate.  The standard value of this variable has several
429 430 431 432 433 434 435
elements including @code{".o"}, @code{".elc"}, and @code{"~"}.  For
example, if a directory contains @samp{foo.c} and @samp{foo.elc},
@samp{foo} completes to @samp{foo.c}.  However, if @emph{all} possible
completions end in ``ignored'' strings, they are not ignored: in the
previous example, @samp{foo.e} completes to @samp{foo.elc}.
Displaying a list of possible completions disregards
@code{completion-ignored-extensions}; it shows them all.
Glenn Morris's avatar
Glenn Morris committed
436 437

  If an element of @code{completion-ignored-extensions} ends in a
438 439 440 441
slash (@file{/}), it's a subdirectory name; that directory and its
contents are ignored.  Elements of
@code{completion-ignored-extensions} that do not end in a slash are
ordinary file names.
Glenn Morris's avatar
Glenn Morris committed
442

443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
@cindex case-sensitivity and completion
@vindex read-file-name-completion-ignore-case
@vindex read-buffer-completion-ignore-case
  When completing file names, Emacs ignores case differences if the
variable @code{read-file-name-completion-ignore-case} is
non-@code{nil}.  The default value is @code{nil} on systems that have
case-sensitive file-names, such as GNU/Linux; it is non-@code{nil} on
systems that have case-insensitive file-names, such as Microsoft
Windows.  When completing buffer names, Emacs ignores case differences
if @code{read-buffer-completion-ignore-case} is non-@code{nil} (the
default value is @code{nil}).

@vindex completion-styles
  You can customize the matching rules for completion alternatives
using the variable @code{completion-styles}.  Its value should be a
list of symbols, each representing a @dfn{completion style}; valid
style symbols are @code{basic}, @code{partial-completion},
460 461 462 463 464 465 466
@code{emacs22}, @code{emacs21}, and @code{initials}.  When completing,
Emacs attempts to use the first completion style in the list; if this
does not return any completion alternatives, it tries the next
completion style in the list, and so on.  The completion rules
described in @ref{Completion Commands} correspond to the default value
of @code{completion-styles}, which is @code{(basic partial-completion
emacs22)}.
Glenn Morris's avatar
Glenn Morris committed
467 468 469 470 471 472 473 474 475 476 477 478 479

@cindex Icomplete mode
@findex icomplete-mode
  Icomplete mode presents a constantly-updated display that tells you
what completions are available for the text you've entered so far.  The
command to enable or disable this minor mode is @kbd{M-x
icomplete-mode}.

@node Minibuffer History
@section Minibuffer History
@cindex minibuffer history
@cindex history of minibuffer input

480
  Every argument that you enter with the minibuffer is saved in a
Glenn Morris's avatar
Glenn Morris committed
481
@dfn{minibuffer history list} so you can easily use it again later.
482 483
You can use the following arguments to quickly fetch an earlier
argument into the minibuffer:
Glenn Morris's avatar
Glenn Morris committed
484 485

@table @kbd
486 487 488 489 490 491
@item M-p
@itemx @key{Up}
Move to the previous item in the minibuffer history, an earlier
argument (@code{previous-history-element}).
@item M-n
@itemx @key{Down}
Glenn Morris's avatar
Glenn Morris committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505
Move to the next item in the minibuffer history
(@code{next-history-element}).
@item M-r @var{regexp} @key{RET}
Move to an earlier item in the minibuffer history that 
matches @var{regexp} (@code{previous-matching-history-element}).
@item M-s @var{regexp} @key{RET}
Move to a later item in the minibuffer history that matches
@var{regexp} (@code{next-matching-history-element}).
@end table

@kindex M-p @r{(minibuffer history)}
@kindex M-n @r{(minibuffer history)}
@findex next-history-element
@findex previous-history-element
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
  While in the minibuffer, typing @kbd{M-p} or @key{Up}
(@code{previous-history-element}) moves up through the minibuffer
history list, one item at a time.  Each @kbd{M-p} fetches an earlier
item from the history list into the minibuffer, replacing its existing
contents.  Similarly, typing @kbd{M-n} or @key{Down}
(@code{next-history-element}) moves back down the history list,
fetching later entries into the minibuffer.  You can think of these
commands as ``backwards'' and ``forwards'' through the history list.

  If you type @kbd{M-n} in the minibuffer when there are no later
entries in the minibuffer history (e.g., if you haven't previously
typed @kbd{M-p}), Emacs tries fetching from a list of default
argument: values that you are likely to enter.  You can think of this
as moving through the ``future list'' instead of the ``history list''.

  The input that @kbd{M-p} or @kbd{M-n} fetches into the minibuffer
entirely replaces the existing contents of the minibuffer, so you can
simply type @key{RET} to use it as an argument.  You can also edit the
text before you reuse it; this does not change the history element
that you ``moved'' to, but your new argument does go at the end of the
history list in its own right.
Glenn Morris's avatar
Glenn Morris committed
527 528 529 530 531 532 533 534 535 536

@findex previous-matching-history-element
@findex next-matching-history-element
@kindex M-r @r{(minibuffer history)}
@kindex M-s @r{(minibuffer history)}
  There are also commands to search forward or backward through the
history; they search for history elements that match a regular
expression.  @kbd{M-r} (@code{previous-matching-history-element})
searches older elements in the history, while @kbd{M-s}
(@code{next-matching-history-element}) searches newer elements.  These
537
commands are unusual: they use the minibuffer to read the regular
Glenn Morris's avatar
Glenn Morris committed
538 539
expression even though they are invoked from the minibuffer.  As with
incremental searching, an upper-case letter in the regular expression
540 541 542
makes the search case-sensitive (@pxref{Search Case}).  You can also
search through the history using an incremental search (@pxref{Isearch
Minibuffer}).
Glenn Morris's avatar
Glenn Morris committed
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560

  All uses of the minibuffer record your input on a history list, but
there are separate history lists for different kinds of arguments.
For example, there is a list for file names, used by all the commands
that read file names.  (As a special feature, this history list
records the absolute file name, even if the name you entered was not
absolute.)

  There are several other specific history lists, including one for
buffer names, one for arguments of commands like @code{query-replace},
one used by @kbd{M-x} for command names, and one used by
@code{compile} for compilation commands.  Finally, there is one
``miscellaneous'' history list that most minibuffer arguments use.

@vindex history-length
  The variable @code{history-length} specifies the maximum length of a
minibuffer history list; adding a new element deletes the oldest
element if the list gets too long.  If the value of
561
@code{history-length} is @code{t}, there is no maximum length.
Glenn Morris's avatar
Glenn Morris committed
562 563 564

@vindex history-delete-duplicates
  The variable @code{history-delete-duplicates} specifies whether to
565 566 567
delete duplicates in history.  If it is non-@code{nil}, adding a new
element deletes from the list all other elements that are equal to it.
The default is @code{nil}.
Glenn Morris's avatar
Glenn Morris committed
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604

@node Repetition
@section Repeating Minibuffer Commands
@cindex command history
@cindex history of commands

  Every command that uses the minibuffer once is recorded on a special
history list, the @dfn{command history}, together with the values of
its arguments, so that you can repeat the entire command.  In
particular, every use of @kbd{M-x} is recorded there, since @kbd{M-x}
uses the minibuffer to read the command name.

@findex list-command-history
@table @kbd
@item C-x @key{ESC} @key{ESC}
Re-execute a recent minibuffer command from the command history
 (@code{repeat-complex-command}).
@item M-x list-command-history
Display the entire command history, showing all the commands
@kbd{C-x @key{ESC} @key{ESC}} can repeat, most recent first.
@end table

@kindex C-x ESC ESC
@findex repeat-complex-command
  @kbd{C-x @key{ESC} @key{ESC}} is used to re-execute a recent command
that used the minibuffer.  With no argument, it repeats the last such
command.  A numeric argument specifies which command to repeat; 1
means the last one, 2 the previous, and so on.

  @kbd{C-x @key{ESC} @key{ESC}} works by turning the previous command
into a Lisp expression and then entering a minibuffer initialized with
the text for that expression.  Even if you don't understand Lisp
syntax, it will probably be obvious which command is displayed for
repetition.  If you type just @key{RET}, that repeats the command
unchanged.  You can also change the command by editing the Lisp
expression before you execute it.  The repeated command is added to
the front of the command history unless it is identical to the most
605
recent item.
Glenn Morris's avatar
Glenn Morris committed
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628

  Once inside the minibuffer for @kbd{C-x @key{ESC} @key{ESC}}, you can
use the minibuffer history commands (@kbd{M-p}, @kbd{M-n}, @kbd{M-r},
@kbd{M-s}; @pxref{Minibuffer History}) to move through the history list
of saved entire commands.  After finding the desired previous command,
you can edit its expression as usual and then repeat it by typing
@key{RET}.

@vindex isearch-resume-in-command-history
  Incremental search does not, strictly speaking, use the minibuffer.
Therefore, although it behaves like a complex command, it normally
does not appear in the history list for @kbd{C-x @key{ESC} @key{ESC}}.
You can make incremental search commands appear in the history by
setting @code{isearch-resume-in-command-history} to a non-@code{nil}
value.  @xref{Incremental Search}.

@vindex command-history
  The list of previous minibuffer-using commands is stored as a Lisp
list in the variable @code{command-history}.  Each element is a Lisp
expression which describes one command and its arguments.  Lisp programs
can re-execute a command by calling @code{eval} with the
@code{command-history} element.

Chong Yidong's avatar
Chong Yidong committed
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
@node Passwords
@section Entering passwords

Sometimes, you may need to enter a password into Emacs.  For instance,
when you tell Emacs to visit a file on another machine via a network
protocol such as FTP, you often need to supply a password to gain
access to the machine (@pxref{Remote Files}).

  Entering a password is, in a basic sense, similar to using a
minibuffer.  Emacs displays a prompt in the echo area (such as
@samp{Password: }); after you type the required password, press
@key{RET} to submit it.  To prevent others from seeing your password,
every character you type is displayed as a dot (@samp{.}) instead of
its usual form.

  Most of the features and commands associated with the minibuffer can
@emph{not} be used when entering a password.  There is no history or
completion, and you cannot change windows or perform any other action
with Emacs until you have submitted the password.

  While you are typing the password, you may press @key{DEL} to delete
backwards, removing the last character entered.  @key{C-u} deletes
everything you have typed so far.  @kbd{C-g} quits the password prompt
(@pxref{Quitting}).  @kbd{C-y} inserts the current kill into the
password (@pxref{Killing}).  You may type either @key{RET} or
@key{ESC} to submit the password.  Any other self-inserting character
key inserts the associated character into the password, and all other
input is ignored.

Glenn Morris's avatar
Glenn Morris committed
658 659 660
@ignore
   arch-tag: ba913cfd-b70e-400f-b663-22b2c309227f
@end ignore