4.5.5 Working with the Buffer List
4.5.5 Working with the Buffer List
The buffer list is more than a display. From the buffer list, you can display, delete, and save buffers. To move to the buffer list window, type C-x o. Emacs puts the cursor in the first column. For a particular buffer, press n or C-n to move down a line or p or C-p to move up a line. You can also press Space to move down to the next line and Del to move up. (The up and down arrow keys work, too.) This array of up and down choices may seem confusing, but multiple bindings are given to make it easy to move up and down without consulting a book like this one.
You use a set of one-character commands to work with the buffers that are listed. To delete a buffer, go to the line for the buffer you want to delete and type d or k. The letter
D appears in the first column. You can mark as many buffers for deletion as you want to. The buffers aren't deleted immediately; when you're finished marking buffers, press x (which stands for "execute") to delete them. If any of the buffers you want to delete are connected with files, Emacs asks if you want to save the changes before doing anything. (Note that it does not ask you about buffers that aren't connected with files, so be sure to save any that you want before deleting them.)
If you change your mind about deleting a buffer before typing x, you can unmark the buffer by going to the appropriate line and typing u. As a convenience, the Del key also unmarks the previous buffer in the list. Why would you do this? Simple: d automatically moves you down one line. If you mark a file for deletion and immediately change your mind, you can press a single Del rather than moving to the previous line and typing u for unmark).
To save a buffer, go to the line for the buffer you want to save and press s. The letter S appears in the first column. Press x when you really want to save the buffer. Therefore, you can look at the buffer list, choose which buffers you want to delete and which you want to save, and then type x to do everything at once. Again, you can press u or Del to cancel saves if you change your mind.
One command that affects a buffer immediately when you type it is tilde (~). Typing ~ marks a buffer as unmodified. In effect, this symbol tells Emacs not to save changes automatically (since the buffer is unmodified, Emacs has no reason to save changes with its auto-save feature). Of course, if you have made changes, the changes are still in the buffer; it's just that you're in essence "lying" to Emacs to say that no changes have been made. Also, if you change the buffer again after marking it unmodified, Emacs once again knows it has been modified and saves it automatically in a backup file. The backup filename (not coincidentally) has the format filename~.
You can change a buffer's status from read-write to read-only and back again by pressing %. Pressing % changes the buffer's status immediately. Percentage signs appear on the mode line when a buffer is read-only. When you are editing, you can toggle a buffer between read-write and read-only by pressing C-x C-q, as we discussed earlier.
You can also use the buffer list to display multiple buffers in windows. To display one of the buffers in a full screen, move the cursor into the buffer list's window; use C-n and C-p to move to the line for the buffer that you want, and press 1 (the number one). Emacs displays the buffer in a full-screen window.
If you want to display one of the buffers in place of the buffer list, you can press f. To put a buffer in another window (i.e., one not occupied by the buffer list), type o. Emacs displays the buffer in the other window and puts the cursor there. Pressing C-o has a slightly different result; Emacs displays the buffer in another window but doesn't put the cursor there.
One final buffer display command remains. You can ask Emacs to display multiple buffers and have Emacs create windows for them dynamically. To select buffers to be displayed in windows, press m (for mark) next to the buffers you want. Emacs displays a > next to the buffers you mark with m. To tell Emacs to display the buffers you've marked, press v. Emacs makes horizontal windows to display the buffers you've chosen.
To get rid of the
*Buffer List* window, type C-x 0 if you are in the buffer list window or C-x 1 (the number one) if you are in another window. Table 4-2 shows a summary of buffer manipulation commands.
Table 4-2. Buffer manipulation commands
|C-x b Buffers ? Select Named Buffer||switch-to-buffer||Move to the buffer specified.|
|C-x ? Buffers ? Next Buffer||next-buffer||Move to the next buffer in the buffer list.|
|C-x Buffers ? Previous Buffer||previous-buffer||Move to the previous buffer in the buffer list.|
|C-x C-b Buffers ? List All Buffers||list-buffers||Display the buffer list.|
|C-x k||kill-buffer||Delete the buffer specified.|
|(none)||kill-some-buffers||Ask about deleting each buffer.|
|(none)||rename-buffer||Change the buffer's name to the name specified.|
|C-x s||save-some-buffers||Ask whether you want to save each modified buffer.|
Table 4-3 summarizes the commands for working with the buffer list.
Table 4-3. Buffer list commands
|C-n, Space, n, or||Move to the next buffer in the list (i.e., down one line).||Immediately|
|C-p, p, or||Move to the previous buffer in the list (i.e., up one line).||Immediately|
|d||Mark buffer for deletion.||When you press x|
|k||Mark buffer for deletion.||When you press x|
|s||Save buffer.||When you press x|
|x||Execute other one-letter commands on all marked buffers.||Immediately|
|Del||Unmark the previous buffer in the list; if there is no mark, move up one line.||Immediately|
|~||Mark buffer as unmodified.||Immediately|
|%||Toggle read-only status of buffer.||Immediately|
|1||Display buffer in a full screen.||Immediately|
|2||Display this buffer and the next one in horizontal windows.||Immediately|
|f||Replace buffer list with this buffer.||Immediately|
|o||Replace other window with this buffer.||Immediately|
|m||Mark buffers to be displayed in windows.||When you press v|
|v||Display buffers marked with m; Emacs makes as many windows as needed.||Immediately|
|q||Quit buffer list.||Immediately|