1@c This is part of the Emacs manual.
2@c Copyright (C) 1985--1987, 1993--1995, 1997, 2000--2021 Free Software
3@c Foundation, Inc.
4@c See file emacs.texi for copying conditions.
5@node Buffers
6@chapter Using Multiple Buffers
7
8@cindex buffers
9  The text you are editing in Emacs resides in an object called a
10@dfn{buffer}.  Each time you visit a file, a buffer is used to hold
11the file's text.  Each time you invoke Dired, a buffer is used to hold
12the directory listing.  If you send a message with @kbd{C-x m}, a
13buffer is used to hold the text of the message.  When you ask for a
14command's documentation, that appears in a buffer named @file{*Help*}.
15
16  Buffers exist as long as they are in use, and are deleted
17(``killed'') when no longer needed, either by you (@pxref{Kill
18Buffer}) or by Emacs (e.g., when you exit Emacs, @pxref{Exiting}).
19
20  Each buffer has a unique name, which can be of any length.  When a
21buffer is displayed in a window, its name is shown in the mode line
22(@pxref{Mode Line}).  The distinction between upper and lower case
23matters in buffer names.  Most buffers are made by visiting files, and
24their names are derived from the files' names; however, you can also
25create an empty buffer with any name you want.  A newly started Emacs
26has several buffers, including one named @file{*scratch*}, which can
27be used for evaluating Lisp expressions and is not associated with any
28file (@pxref{Lisp Interaction}).
29
30@cindex selected buffer
31@cindex current buffer
32  At any time, one and only one buffer is @dfn{selected}; we call it
33the @dfn{current buffer}.  We sometimes say that a command operates on
34``the buffer''; this really means that it operates on the current
35buffer.  When there is only one Emacs window, the buffer displayed in
36that window is current.  When there are multiple windows, the buffer
37displayed in the @dfn{selected window} is current.  @xref{Windows}.
38
39@cindex buffer contents
40@cindex contents of a buffer
41  A buffer's @dfn{contents} consist of a series of characters, each of
42which optionally carries a set of text properties
43(@pxref{International Chars, Text properties}) that can specify more
44information about that character.
45
46  Aside from its textual contents, each buffer records several pieces
47of information, such as what file it is visiting (if any), whether it
48is modified, and what major mode and minor modes are in effect
49(@pxref{Modes}).  These are stored in @dfn{buffer-local
50variables}---variables that can have a different value in each buffer.
51@xref{Locals}.
52
53@cindex buffer size, maximum
54  A buffer's size cannot be larger than some maximum, which is defined
55by the largest buffer position representable by @dfn{Emacs integers}.
56This is because Emacs tracks buffer positions using that data type.
57For typical 64-bit machines, this maximum buffer size is @math{2^{61} - 2}
58bytes, or about 2 EiB@.  For typical 32-bit machines, the maximum is
59usually @math{2^{29} - 2} bytes, or about 512 MiB@.  Buffer sizes are
60also limited by the amount of memory in the system.
61
62@menu
63* Select Buffer::       Creating a new buffer or reselecting an old one.
64* List Buffers::        Getting a list of buffers that exist.
65* Misc Buffer::         Renaming; changing read-only status; copying text.
66* Kill Buffer::         Killing buffers you no longer need.
67* Several Buffers::     How to go through the list of all buffers
68                          and operate variously on several of them.
69* Indirect Buffers::    An indirect buffer shares the text of another buffer.
70* Buffer Convenience::  Convenience and customization features for
71                          buffer handling.
72@end menu
73
74@node Select Buffer
75@section Creating and Selecting Buffers
76@cindex change buffers
77@cindex switch buffers
78
79@table @kbd
80@item C-x b @var{buffer} @key{RET}
81Select or create a buffer named @var{buffer} (@code{switch-to-buffer}).
82@item C-x 4 b @var{buffer} @key{RET}
83Similar, but select @var{buffer} in another window
84(@code{switch-to-buffer-other-window}).
85@item C-x 5 b @var{buffer} @key{RET}
86Similar, but select @var{buffer} in a separate frame
87(@code{switch-to-buffer-other-frame}).
88@item C-x @key{LEFT}
89Select the previous buffer in the buffer list (@code{previous-buffer}).
90@item C-x @key{RIGHT}
91Select the next buffer in the buffer list (@code{next-buffer}).
92@item C-u M-g M-g
93@itemx C-u M-g g
94Read a number @var{n} and move to line @var{n} in the most recently
95selected buffer other than the current buffer, in another window.
96@end table
97
98@kindex C-x b
99@findex switch-to-buffer
100  The @kbd{C-x b} (@code{switch-to-buffer}) command reads a buffer
101name using the minibuffer.  Then it makes that buffer current, and
102displays it in the currently-selected window.  An empty input
103specifies the buffer that was current most recently among those not
104now displayed in any window.
105
106  While entering the buffer name, you can use the usual completion and
107history commands (@pxref{Minibuffer}).  Note that @kbd{C-x b}, and
108related commands, use @dfn{permissive completion with confirmation}
109for minibuffer completion: if you type @key{RET} when the minibuffer
110text names a nonexistent buffer, Emacs prints @samp{[Confirm]} and you
111must type a second @key{RET} to submit that buffer name.
112@xref{Completion Exit}, for details.  For other completion options and
113features, see @ref{Completion Options}.
114
115  If you specify a buffer that does not exist, @kbd{C-x b} creates a
116new, empty buffer that is not visiting any file, and selects it for
117editing.  The default value of the variable @code{major-mode}
118determines the new buffer's major mode; the default value is
119Fundamental mode.  @xref{Major Modes}.  One reason to create a new
120buffer is to use it for making temporary notes.  If you try to save
121it, Emacs asks for the file name to use, and the buffer's major mode
122is re-established taking that file name into account (@pxref{Choosing
123Modes}).
124
125@kindex C-x LEFT
126@kindex C-x RIGHT
127@findex next-buffer
128@findex previous-buffer
129  For conveniently switching between a few buffers, use the commands
130@kbd{C-x @key{LEFT}} and @kbd{C-x @key{RIGHT}}.  @kbd{C-x @key{LEFT}}
131(@code{previous-buffer}) selects the previous buffer (following the
132order of most recent selection in the current frame), while @kbd{C-x
133@key{RIGHT}} (@code{next-buffer}) moves through buffers in the reverse
134direction.  Both commands support a numeric prefix argument that
135serves as a repeat count.
136
137@kindex C-x 4 b
138@findex switch-to-buffer-other-window
139  To select a buffer in a window other than the current one
140(@pxref{Windows}), type @kbd{C-x 4 b}
141(@code{switch-to-buffer-other-window}).  This prompts for a buffer
142name using the minibuffer, displays that buffer in another window, and
143selects that window.
144
145@kindex C-x 5 b
146@findex switch-to-buffer-other-frame
147  Similarly, @kbd{C-x 5 b} (@code{switch-to-buffer-other-frame})
148prompts for a buffer name, displays that buffer in another frame
149(@pxref{Frames}), and selects that frame.  If the buffer is already
150being shown in a window on another frame, Emacs selects that window
151and frame instead of creating a new frame.
152
153  @xref{Displaying Buffers}, for how the @kbd{C-x 4 b} and @kbd{C-x 5
154b} commands get the window and/or frame to display in.
155
156  In addition, @kbd{C-x C-f}, and any other command for visiting a
157file, can also be used to switch to an existing file-visiting buffer.
158@xref{Visiting}.
159
160@findex goto-line@r{, with an argument}
161  @kbd{C-u M-g M-g}, that is @code{goto-line} with a plain prefix
162argument, reads a number @var{n} using the minibuffer, selects the
163most recently selected buffer other than the current buffer in another
164window, and then moves point to the beginning of line number @var{n}
165in that buffer.  This is mainly useful in a buffer that refers to line
166numbers in another buffer: if point is on or just after a number,
167@code{goto-line} uses that number as the default for @var{n}.  Note
168that prefix arguments other than just @kbd{C-u} behave differently.
169@kbd{C-u 4 M-g M-g} goes to line 4 in the @emph{current} buffer,
170without reading a number from the minibuffer.  (Remember that @kbd{M-g
171M-g} without prefix argument reads a number @var{n} and then moves to
172line number @var{n} in the current buffer.  @xref{Moving Point}.)
173
174  Emacs uses buffer names that start with a space for internal purposes.
175It treats these buffers specially in minor ways---for example, by
176default they do not record undo information.  It is best to avoid using
177such buffer names yourself.
178
179@node List Buffers
180@section Listing Existing Buffers
181
182@table @kbd
183@item C-x C-b
184List the existing buffers (@code{list-buffers}).
185@end table
186
187@cindex listing current buffers
188@kindex C-x C-b
189@findex list-buffers
190  To display a list of existing buffers, type @kbd{C-x C-b}.  This
191pops up a buffer menu in a buffer named @file{*Buffer List*}.  Each
192line in the list shows one buffer's name, size, major mode and visited file.
193The buffers are listed in the order that they were current; the
194buffers that were current most recently come first.  This section
195describes how the list of buffers is displayed and how to interpret
196the various indications in the list; see @ref{Several Buffers}, for
197description of the special mode in the @file{*Buffer List*} buffer and
198the commands available there.
199
200  @samp{.} in the first field of a line indicates that the buffer is
201current.  @samp{%} indicates a read-only buffer.  @samp{*} indicates
202that the buffer is modified.  If several buffers are modified, it
203may be time to save some with @kbd{C-x s} (@pxref{Save Commands}).
204Here is an example of a buffer list:
205
206@smallexample
207CRM Buffer                Size  Mode              File
208. * .emacs                3294  Emacs-Lisp        ~/.emacs
209 %  *Help*                 101  Help
210    search.c             86055  C                 ~/cvs/emacs/src/search.c
211 %  src                  20959  Dired by name     ~/cvs/emacs/src/
212  * *mail*                  42  Mail
213 %  HELLO                 1607  Fundamental       ~/cvs/emacs/etc/HELLO
214 %  NEWS                481184  Outline           ~/cvs/emacs/etc/NEWS
215    *scratch*              191  Lisp Interaction
216  * *Messages*            1554  Messages
217@end smallexample
218
219@noindent
220The buffer @file{*Help*} was made by a help request (@pxref{Help}); it
221is not visiting any file.  The buffer @code{src} was made by Dired on
222the directory @file{~/cvs/emacs/src/}.  You can list only buffers that
223are visiting files by giving the command a prefix argument, as in
224@kbd{C-u C-x C-b}.
225
226  @code{list-buffers} omits buffers whose names begin with a space,
227unless they visit files: such buffers are used internally by Emacs.
228
229@node Misc Buffer
230@section Miscellaneous Buffer Operations
231
232@table @kbd
233@item C-x C-q
234Toggle read-only status of buffer (@code{read-only-mode}).
235@item M-x rename-buffer @key{RET} @var{buffer} @key{RET}
236Change the name of the current buffer.
237@item M-x rename-uniquely
238Rename the current buffer by adding @samp{<@var{number}>} to the end.
239@item M-x view-buffer @key{RET} @var{buffer} @key{RET}
240Scroll through buffer @var{buffer}.  @xref{View Mode}.
241@end table
242
243@kindex C-x C-q
244@vindex buffer-read-only
245@cindex read-only buffer
246  A buffer can be @dfn{read-only}, which means that commands to insert
247or delete its text are not allowed.  (However, other commands, like
248@kbd{C-x @key{RET} f}, can still mark it as modified, @pxref{Text
249Coding}).  The mode line indicates read-only buffers with @samp{%%} or
250@samp{%*} near the left margin.  @xref{Mode Line}.  Read-only buffers
251are usually made by subsystems such as Dired and Rmail that have
252special commands to operate on the text.  Visiting a file whose access
253control says you cannot write it also makes the buffer read-only.
254
255@findex read-only-mode
256@vindex view-read-only
257 The command @kbd{C-x C-q} (@code{read-only-mode}) makes a read-only
258buffer writable, and makes a writable buffer read-only.  This works by
259setting the variable @code{buffer-read-only}, which has a local value
260in each buffer and makes the buffer read-only if its value is
261non-@code{nil}.  If you change the option @code{view-read-only} to a
262non-@code{nil} value, making the buffer read-only with @kbd{C-x C-q}
263also enables View mode in the buffer (@pxref{View Mode}).
264
265@findex rename-buffer
266  @kbd{M-x rename-buffer} changes the name of the current buffer.  You
267specify the new name as a minibuffer argument; there is no default.
268If you specify a name that is in use for some other buffer, an error
269happens and no renaming is done.
270
271@findex rename-uniquely
272  @kbd{M-x rename-uniquely} renames the current buffer to a similar
273name with a numeric suffix added to make it both different and unique.
274This command does not need an argument.  It is useful for creating
275multiple shell buffers: if you rename the @file{*shell*} buffer, then
276do @kbd{M-x shell} again, it makes a new shell buffer named
277@file{*shell*}; meanwhile, the old shell buffer continues to exist
278under its new name.  This method is also good for mail buffers,
279compilation buffers, and most Emacs features that create special
280buffers with particular names.  (With some of these features, such as
281@kbd{M-x compile}, @kbd{M-x grep}, you need to switch to some other
282buffer before using the command again, otherwise it will reuse the
283current buffer despite the name change.)
284
285  The commands @kbd{M-x append-to-buffer} and @kbd{M-x insert-buffer}
286can also be used to copy text from one buffer to another.
287@xref{Accumulating Text}.
288
289@node Kill Buffer
290@section Killing Buffers
291
292@cindex killing buffers
293@cindex close buffer
294@cindex close file
295  If you continue an Emacs session for a while, you may accumulate a
296large number of buffers.  You may then find it convenient to @dfn{kill}
297the buffers you no longer need.  (Some other editors call this
298operation @dfn{close}, and talk about ``closing the buffer'' or
299``closing the file'' visited in the buffer.)  On most operating
300systems, killing a buffer releases the memory Emacs used for the buffer
301back to the operating system so that other programs can use it.  Here
302are some commands for killing buffers:
303
304@table @kbd
305@item C-x k @var{buffer} @key{RET}
306Kill buffer @var{buffer} (@code{kill-buffer}).
307@item M-x kill-some-buffers
308Offer to kill each buffer, one by one.
309@item M-x kill-matching-buffers
310Offer to kill all buffers matching a regular expression.
311@end table
312
313@findex kill-buffer
314@kindex C-x k
315@cindex killing unsaved buffers
316@cindex unsaved buffers, killing
317  @kbd{C-x k} (@code{kill-buffer}) kills one buffer, whose name you
318specify in the minibuffer.  The default, used if you type just
319@key{RET} in the minibuffer, is to kill the current buffer.  If you
320kill the current buffer, another buffer becomes current: one that was
321current in the recent past but is not displayed in any window now.  If
322you ask to kill a file-visiting buffer that is modified, then you must
323confirm with @kbd{yes} before the buffer is killed.
324
325@findex kill-some-buffers
326  The command @kbd{M-x kill-some-buffers} asks about each buffer, one
327by one.  An answer of @kbd{yes} means to kill the buffer, just like
328@code{kill-buffer}.  This command ignores buffers whose names begin
329with a space, which are used internally by Emacs.
330
331@findex kill-matching-buffers
332  The command @kbd{M-x kill-matching-buffers} prompts for a regular
333expression and kills all buffers whose names match that expression.
334@xref{Regexps}.  Like @code{kill-some-buffers}, it asks for
335confirmation before each kill.  This command normally ignores buffers
336whose names begin with a space, which are used internally by Emacs.
337To kill internal buffers as well, call @code{kill-matching-buffers}
338with a prefix argument.
339
340  The Buffer Menu feature is also convenient for killing various
341buffers.  @xref{Several Buffers}.
342
343@vindex kill-buffer-hook
344  If you want to do something special every time a buffer is killed, you
345can add hook functions to the hook @code{kill-buffer-hook} (@pxref{Hooks}).
346
347@findex clean-buffer-list
348  If you run one Emacs session for a period of days, as many people do,
349it can fill up with buffers that you used several days ago.  The command
350@kbd{M-x clean-buffer-list} is a convenient way to purge them; it kills
351all the unmodified buffers that you have not used for a long time.  An
352ordinary buffer is killed if it has not been displayed for three days;
353however, you can specify certain buffers that should never be killed
354automatically, and others that should be killed if they have been unused
355for a mere hour.  These defaults, and other aspects of this command's
356behavior, can be controlled by customizing several options described
357in the doc string of @code{clean-buffer-list}.
358
359@cindex Midnight mode
360@vindex midnight-mode
361@vindex midnight-hook
362  You can also have this buffer purging done for you, once a day,
363by enabling Midnight mode.  Midnight mode operates each day
364at midnight; at that time, it runs @code{clean-buffer-list}, or
365whichever functions you have placed in the normal hook
366@code{midnight-hook} (@pxref{Hooks}).  To enable Midnight mode, use
367the Customization buffer to set the variable @code{midnight-mode} to
368@code{t}.  @xref{Easy Customization}.
369
370@node Several Buffers
371@section Operating on Several Buffers
372@cindex Buffer Menu
373
374@table @kbd
375@item M-x buffer-menu
376Begin editing a buffer listing all Emacs buffers.
377@item M-x buffer-menu-other-window
378Similar, but do it in another window.
379@end table
380
381  The @dfn{Buffer Menu} opened by @kbd{C-x C-b} (@pxref{List Buffers})
382does not merely list buffers.  It also allows you to perform various
383operations on buffers, through an interface similar to Dired
384(@pxref{Dired}).  You can save buffers, kill them (here called
385@dfn{deleting} them, for consistency with Dired), or display them.
386
387@findex buffer-menu
388@findex buffer-menu-other-window
389  To use the Buffer Menu, type @kbd{C-x C-b} and switch to the window
390displaying the @file{*Buffer List*} buffer.  You can also type
391@kbd{M-x buffer-menu} to open the Buffer Menu in the selected window.
392Alternatively, the command @kbd{M-x buffer-menu-other-window} opens
393the Buffer Menu in another window, and selects that window.
394
395  The Buffer Menu is a read-only buffer, and can be changed only
396through the special commands described in this section.  The usual
397cursor motion commands can be used in this buffer.  The following
398commands apply to the buffer described on the current line:
399
400@table @kbd
401@item d
402@findex Buffer-menu-delete
403@kindex d @r{(Buffer Menu)}
404Flag the buffer for deletion (killing), then move point to the next
405line (@code{Buffer-menu-delete}).  The deletion flag is indicated by
406the character @samp{D} on the line, before the buffer name.  The
407deletion occurs only when you type the @kbd{x} command (see below).
408
409@item C-d
410@findex Buffer-menu-delete-backwards
411@kindex C-d @r{(Buffer Menu)}
412Like @kbd{d}, but move point up instead of down
413(@code{Buffer-menu-delete-backwards}).
414
415@item s
416@findex Buffer-menu-save
417@kindex s @r{(Buffer Menu)}
418Flag the buffer for saving (@code{Buffer-menu-save}).  The save flag
419is indicated by the character @samp{S} on the line, before the buffer
420name.  The saving occurs only when you type @kbd{x}.  You may request
421both saving and deletion for the same buffer.
422
423@item x
424@findex Buffer-menu-execute
425@kindex x @r{(Buffer Menu)}
426Perform all flagged deletions and saves (@code{Buffer-menu-execute}).
427
428@item u
429@findex Buffer-menu-unmark
430@kindex u @r{(Buffer Menu)}
431Remove all flags from the current line, and move down
432(@code{Buffer-menu-unmark}).  With a prefix argument, moves up after
433removing the flags.
434
435@item @key{DEL}
436@findex Buffer-menu-backup-unmark
437@kindex DEL @r{(Buffer Menu)}
438Move to the previous line and remove all flags on that line
439(@code{Buffer-menu-backup-unmark}).
440
441@item M-@key{DEL}
442@findex Buffer-menu-unmark-all-buffers
443@kindex M-DEL @r{(Buffer Menu)}
444Remove a particular flag from all lines
445(@code{Buffer-menu-unmark-all-buffers}).  This asks for a single
446character, and unmarks buffers marked with that character; typing
447@key{RET} removes all marks.
448
449@item U
450@findex Buffer-menu-unmark-all
451@kindex U @r{(Buffer Menu)}
452Remove all flags from all the lines
453(@code{Buffer-menu-unmark-all}).
454@end table
455
456@noindent
457The commands for removing flags, @kbd{d} and @kbd{C-d}, accept a
458numeric argument as a repeat count.
459
460  The following commands operate immediately on the buffer listed on
461the current line.  They also accept a numeric argument as a repeat
462count.
463
464@table @kbd
465@item ~
466@findex Buffer-menu-not-modified
467@kindex ~ @r{(Buffer Menu)}
468Mark the buffer as unmodified (@code{Buffer-menu-not-modified}).
469@xref{Save Commands}.
470
471@item %
472@findex Buffer-menu-toggle-read-only
473@kindex % @r{(Buffer Menu)}
474Toggle the buffer's read-only status
475(@code{Buffer-menu-toggle-read-only}).  @xref{Misc Buffer}.
476
477@item t
478@findex Buffer-menu-visit-tags-table
479@kindex t @r{(Buffer Menu)}
480Visit the buffer as a tags table
481(@code{Buffer-menu-visit-tags-table}).  @xref{Select Tags Table}.
482@end table
483
484  The following commands are used to select another buffer or buffers:
485
486@table @kbd
487@item q
488@findex quit-window
489@kindex q @r{(Buffer Menu)}
490Quit the Buffer Menu (@code{quit-window}).  The most recent formerly
491visible buffer is displayed in its place.
492
493@item @key{RET}
494@itemx f
495@findex Buffer-menu-this-window
496@kindex f @r{(Buffer Menu)}
497@kindex RET @r{(Buffer Menu)}
498Select this line's buffer, replacing the @file{*Buffer List*} buffer
499in its window (@code{Buffer-menu-this-window}).
500
501@item o
502@findex Buffer-menu-other-window
503@kindex o @r{(Buffer Menu)}
504Select this line's buffer in another window, as if by @kbd{C-x 4 b},
505leaving @file{*Buffer List*} visible
506(@code{Buffer-menu-other-window}).
507
508@item C-o
509@findex Buffer-menu-switch-other-window
510@kindex C-o @r{(Buffer Menu)}
511Display this line's buffer in another window, without selecting it
512(@code{Buffer-menu-switch-other-window}).
513
514@item 1
515@findex Buffer-menu-1-window
516@kindex 1 @r{(Buffer Menu)}
517Select this line's buffer in a full-frame window
518(@code{Buffer-menu-1-window}).
519
520@item 2
521@findex Buffer-menu-2-window
522@kindex 2 @r{(Buffer Menu)}
523Set up two windows on the current frame, with this line's buffer
524selected in one, and a previously current buffer (aside from
525@file{*Buffer List*}) in the other (@code{Buffer-menu-2-window}).
526
527@item b
528@findex Buffer-menu-bury
529@kindex b @r{(Buffer Menu)}
530Bury this line's buffer (@code{Buffer-menu-bury}) (i.e., move it to
531the end of the buffer list).
532
533@item m
534@findex Buffer-menu-mark
535@kindex m @r{(Buffer Menu)}
536Mark this line's buffer to be displayed in another window if you exit
537with the @kbd{v} command (@code{Buffer-menu-mark}).  The display flag
538is indicated by the character @samp{>} at the beginning of the line.
539(A single buffer may not have both deletion and display flags.)
540
541@item v
542@findex Buffer-menu-select
543@kindex v @r{(Buffer Menu)}
544Select this line's buffer, and also display in other windows any
545buffers flagged with the @kbd{m} command (@code{Buffer-menu-select}).
546If you have not flagged any buffers, this command is equivalent to
547@kbd{1}.
548@end table
549
550  The following commands affect the entire buffer list:
551
552@table @kbd
553@item S
554@findex tabulated-list-sort
555@kindex S @r{(Buffer Menu)}
556Sort the Buffer Menu entries according to their values in the column
557at point.  With a numeric prefix argument @var{n}, sort according to
558the @var{n}-th column (@code{tabulated-list-sort}).
559
560@item @}
561@kindex @} @r{(Buffer Menu)}
562@findex tabulated-list-widen-current-column
563Widen the current column width by @var{n} (the prefix numeric
564argument) characters.
565
566@item @{
567@kindex @{ @r{(Buffer Menu)}
568@findex tabulated-list-narrow-current-column
569Narrow the current column width by @var{n} (the prefix numeric
570argument) characters.
571
572@item T
573@findex Buffer-menu-toggle-files-only
574@kindex T @r{(Buffer Menu)}
575Delete, or reinsert, lines for non-file buffers
576(@code{Buffer-menu-toggle-files-only}).  This command toggles the
577inclusion of such buffers in the buffer list.
578@end table
579
580  Normally, the buffer @file{*Buffer List*} is not updated
581automatically when buffers are created and killed; its contents are
582just text.  If you have created, deleted or renamed buffers, the way
583to update @file{*Buffer List*} to show what you have done is to type
584@kbd{g} (@code{revert-buffer}).  You can make this happen regularly
585every @code{auto-revert-interval} seconds if you enable Auto Revert
586mode in this buffer, as long as it is not marked modified.  Global
587Auto Revert mode applies to the @file{*Buffer List*} buffer only if
588@code{global-auto-revert-non-file-buffers} is non-@code{nil}.
589@iftex
590@inforef{Auto Reverting the Buffer Menu,, emacs-xtra}, for details.
591@end iftex
592@ifnottex
593@xref{Auto Reverting the Buffer Menu, global-auto-revert-non-file-buffers}, for details.
594@end ifnottex
595
596@node Indirect Buffers
597@section Indirect Buffers
598@cindex indirect buffer
599@cindex base buffer
600
601  An @dfn{indirect buffer} shares the text of some other buffer, which
602is called the @dfn{base buffer} of the indirect buffer.  In some ways it
603is a buffer analogue of a symbolic link between files.
604
605@table @kbd
606@findex make-indirect-buffer
607@item M-x make-indirect-buffer @key{RET} @var{base-buffer} @key{RET} @var{indirect-name} @key{RET}
608Create an indirect buffer named @var{indirect-name} with base buffer
609@var{base-buffer}.
610@findex clone-indirect-buffer
611@item M-x clone-indirect-buffer @key{RET}
612Create an indirect buffer that is a twin copy of the current buffer.
613@item C-x 4 c
614@kindex C-x 4 c
615@findex clone-indirect-buffer-other-window
616Create an indirect buffer that is a twin copy of the current buffer, and
617select it in another window (@code{clone-indirect-buffer-other-window}).
618@end table
619
620  The text of the indirect buffer is always identical to the text of its
621base buffer; changes made by editing either one are visible immediately
622in the other.  But in all other respects, the indirect buffer and its
623base buffer are completely separate.  They can have different names,
624different values of point, different narrowing, different markers,
625different major modes, and different local variables.
626
627  An indirect buffer cannot visit a file, but its base buffer can.  If
628you try to save the indirect buffer, that actually works by saving the
629base buffer.  Killing the base buffer effectively kills the indirect
630buffer, but killing an indirect buffer has no effect on its base buffer.
631
632  One way to use indirect buffers is to display multiple views of an
633outline.  @xref{Outline Views}.
634
635@vindex clone-indirect-buffer-hook
636  A quick and handy way to make an indirect buffer is with the command
637@kbd{M-x clone-indirect-buffer}.  It creates and selects an indirect
638buffer whose base buffer is the current buffer.  With a numeric
639argument, it prompts for the name of the indirect buffer; otherwise it
640uses the name of the current buffer, with a @samp{<@var{n}>} suffix
641added.  @kbd{C-x 4 c} (@code{clone-indirect-buffer-other-window})
642works like @kbd{M-x clone-indirect-buffer}, but it selects the new
643buffer in another window.  These functions run the hook
644@code{clone-indirect-buffer-hook} after creating the indirect buffer.
645
646  The more general way to make an indirect buffer is with the command
647@kbd{M-x make-indirect-buffer}.  It creates an indirect buffer
648named @var{indirect-name} from a buffer @var{base-buffer}, prompting for
649both using the minibuffer.
650
651@node Buffer Convenience
652@section Convenience Features and Customization of Buffer Handling
653
654   This section describes several modes and features that make it more
655convenient to switch between buffers.
656
657@menu
658* Uniquify::               Making buffer names unique with directory parts.
659* Icomplete::              Fast minibuffer selection.
660* Buffer Menus::           Configurable buffer menu.
661@end menu
662
663@node Uniquify
664@subsection Making Buffer Names Unique
665
666@cindex unique buffer names
667@cindex directories in buffer names
668  When several buffers visit identically-named files, Emacs must give
669the buffers distinct names.  The default method adds a suffix based on
670the names of the directories that contain the files.  For example, if
671you visit files @file{/foo/bar/mumble/name} and
672@file{/baz/quux/mumble/name} at the same time, their buffers will be
673named @samp{name<bar/mumble>} and @samp{name<quux/mumble>}, respectively.
674Emacs adds as many directory parts as are needed to make a unique name.
675
676@vindex uniquify-buffer-name-style
677  You can choose from several different styles for constructing unique
678buffer names, by customizing the option @code{uniquify-buffer-name-style}.
679
680  The @code{forward} naming method includes part of the file's
681directory name at the beginning of the buffer name; using this method,
682buffers visiting the files @file{/u/rms/tmp/Makefile} and
683@file{/usr/projects/zaphod/Makefile} would be named
684@samp{tmp/Makefile} and @samp{zaphod/Makefile}.
685
686  In contrast, the @code{post-forward} naming method would call the
687buffers @samp{Makefile|tmp} and @samp{Makefile|zaphod}.  The default
688method @code{post-forward-angle-brackets} is like @code{post-forward},
689except that it encloses the unique path in angle brackets.  The
690@code{reverse} naming method would call them @samp{Makefile\tmp} and
691@samp{Makefile\zaphod}.  The nontrivial difference between
692@code{post-forward} and @code{reverse} occurs when just one directory
693name is not enough to distinguish two files; then @code{reverse} puts
694the directory names in reverse order, so that @file{/top/middle/file}
695becomes @samp{file\middle\top}, while @code{post-forward} puts them in
696forward order after the file name, as in @samp{file|top/middle}.  If
697@code{uniquify-buffer-name-style} is set to @code{nil}, the buffer
698names simply get @samp{<2>}, @samp{<3>}, etc.@: appended.
699
700  Which rule to follow for putting the directory names in the buffer
701name is not very important if you are going to @emph{look} at the
702buffer names before you type one.  But as an experienced user, if you
703know the rule, you won't have to look.  And then you may find that one
704rule or another is easier for you to remember and apply quickly.
705
706@node Icomplete
707@subsection Fast minibuffer selection
708
709@findex icomplete-mode
710@cindex Icomplete mode
711
712  Icomplete global minor mode provides a convenient way to quickly select an
713element among the possible completions in a minibuffer.  When enabled, typing
714in the minibuffer continuously displays a list of possible completions that
715match the string you have typed.
716
717  At any time, you can type @kbd{C-j} to select the first completion in
718the list.  So the way to select a particular completion is to make it the
719first in the list.  There are two ways to do this.  You can type more
720of the completion name and thus narrow down the list, excluding unwanted
721completions above the desired one.  Alternatively, you can use @kbd{C-.}
722and @kbd{C-,} to rotate the list until the desired buffer is first.
723
724  @kbd{M-@key{TAB}} will select the first completion in the list, like
725@kbd{C-j} but without exiting the minibuffer, so you can edit it
726further.  This is typically used when entering a file name, where
727@kbd{M-@key{TAB}} can be used a few times to descend in the hierarchy
728of directories.
729
730  To enable Icomplete mode, type @kbd{M-x icomplete-mode}, or customize
731the variable @code{icomplete-mode} to @code{t} (@pxref{Easy
732Customization}).
733
734@findex fido-mode
735@cindex fido mode
736
737  An alternative to Icomplete mode is Fido mode.  This is very similar
738to Icomplete mode, but retains some functionality from a popular
739extension called Ido mode (in fact the name is derived from ``Fake
740Ido'').  Among other things, in Fido mode, @kbd{C-s} and @kbd{C-r} are
741also used to rotate the completions list, @kbd{C-k} can be used to
742delete files and kill buffers in-list.  Another noteworthy aspect is
743that @code{flex} is used as the default completion style
744(@pxref{Completion Styles}).  To change this, add the following to
745your initialization file (@pxref{Init File}):
746
747@example
748(defun my-icomplete-styles ()
749  (setq-local completion-styles '(initials flex)))
750(add-hook 'icomplete-minibuffer-setup-hook 'my-icomplete-styles)
751@end example
752
753  To enable Fido mode, type @kbd{M-x fido-mode}, or customize
754the variable @code{fido-mode} to @code{t} (@pxref{Easy
755Customization}).
756
757@node Buffer Menus
758@subsection Customizing Buffer Menus
759
760@findex bs-show
761@cindex buffer list, customizable
762@table @kbd
763@item M-x bs-show
764Make a list of buffers similarly to @kbd{M-x list-buffers} but
765customizable.
766@item M-x ibuffer
767Make a list of buffers and operate on them in Dired-like fashion.
768@end table
769
770@findex bs-customize
771  @kbd{M-x bs-show} pops up a buffer list similar to the one normally
772displayed by @kbd{C-x C-b}, but whose display you can customize in a
773more flexible fashion.  For example, you can specify the list of
774buffer attributes to show, the minimum and maximum width of buffer
775name column, a regexp for names of buffers that will never be shown
776and those which will always be shown, etc.  If you prefer
777this to the usual buffer list, you can bind this command to @kbd{C-x
778C-b}.  To customize this buffer list, use the @code{bs} Custom group
779(@pxref{Easy Customization}), or invoke @kbd{bs-customize}.
780
781@findex msb-mode
782@cindex mode, MSB
783@cindex MSB mode
784@findex mouse-buffer-menu
785@kindex C-Down-mouse-1
786  MSB global minor mode (``MSB'' stands for ``mouse select buffer'')
787provides a different and customizable mouse buffer menu which you may
788prefer.  It replaces the @code{mouse-buffer-menu} commands, normally
789bound to @kbd{C-Down-mouse-1} and @kbd{C-@key{F10}}, with its own
790commands, and also modifies the menu-bar buffer menu.  You can
791customize the menu in the @code{msb} Custom group.
792
793@findex ibuffer
794   IBuffer is a major mode for viewing a list of buffers and operating
795on them in a way analogous to that of Dired (@pxref{Dired}), including
796filtering, marking, sorting in various ways, and acting on buffers.
797