buffers.texi 29 KB

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