Emacs series tutorial (9): Buffer Management

Source: Internet
Author: User

First, the buffer here is the buffer in Emacs. The buffer is the stuff you are editing. For example, if you open a file, emacs creates a buffer to load the file. When you call help, emacs creates a buffer called "* help *" to display the Help content, when tutorial is enabled, the buffer tutorial.cn is displayed. In essence, buffering is a piece of free space opened up in the memory.

Each buffer has its own name, such as "tutorial.cn" or "* Scratch *". This is the default buffer created by Emacs for debugging lisp expressions, the buffer name is displayed on mode line. In an Emacs instance, we can create more than N buffers, but at the same time, only one buffer is active, which is called the "Current Buffer". Most operation commands only work on the current buffer.

 

I. Operation Buffering

run the C-x B buffer ( switch-to-buffer ) to create a buffer. Here, the buffer refers to your buffer name. If the buffer already exists, it will be opened directly. In fact, after you enter C-x B, a default buffer will appear, that is, the buffer used in the previous one. You can use the carriage return function to directly switch over. Use C-x left or C-X right to switch between left and right. Left and right are the left and right direction keys. There are two other buffer creation commands, C-x 4 B buffer ( switch-to-buffer-other-window ) create a buffer and C-x 5 B buffer ( switch-to-buffer-other-frame ) create a buffer in another frame. The concepts of windows and frame will be introduced in the next chapter. Here we will just tell you the two commands. The buffer created in this way is blank at the beginning, and it is not associated with a file. After any edits, it can be directly turned off and not written to the disk. Of course, except that you want to save it as a file. Another way to create a buffer is to create or open a file. By default, emacs creates a buffer with the name of the file name. Therefore, we can see the difference between the file and the buffer, the buffer is not necessarily a file, but the file must be a buffer. Note that the buffer name should not start with a space. This buffer has other functions in Emacs and should be avoided as much as possible.

Show all buffer usage commandsC-x C-B(List-Buffers), You can see the following results.

 

 

 

The first "." indicates the current buffer. There are also some special characters in the CRM column. % indicates read-only buffering, and * indicates that the buffering has been modified. The remaining four columns can be understood by name. This command adds a prefix,C-uC-x C-BOnly the buffer mapped to the file is displayed.

After using Emacs for a period of time, it may accumulate a large amount of buffer, or even slow down.ProgramIn this case, we need to disable some unnecessary buffering to release the point memory. CommandC-x K buffer(Kill-Buffer) Is to disable the specified buffer. If the buffer is correct to a modified file, a prompt is displayed indicating whether to directly close the file. You can also turn off a lot of buffering at a time.Kill-some-Buffers, This command will display a lot of prompts, and then close according to the user's confirmation, first will ask whether to close all unmodified buffer, if the answer "no ", the modified buffer will not be modified, and you will be asked whether to disable it one by one. If you haven't shut down Emacs for three days, try it.Clean-buffer-listBy default, you can turn off the buffer that has not been used for three days.

The following describes some miscellaneous operations:

C-x C-Q(Toggle-read-only) To switch the read-only attribute of the current buffer.

C-u m-gNum, Jump to the row num that uses the buffer before, which is slightly useful when writing reference lines.

Rename-Buffer, Rename a buffer.

Rename-uniquely, Rename the current buffer, and add a numeric suffix directly after it.

View-Buffer, Read-only mode to open a buffer, and nothing can be modified, press Q to exit view mode.

 

Ii. Buffer menu

As mentioned in the previous section, we can use C-x C-B to view all the buffers. In addition, there is a command that can achieve the same effect.Buffer-menuHowever, this command not only allows you to see which buffers are available, but also enables you to manage these buffers. After using the buffer-menu command, we can see that the mode name of Emacs is changed to "buffer menu", indicating that another mode is in place. For details about how to operate these buffers, see the following table:

Buttons Effect Remarks
SPC, n Move to the next item
P Move to the previous item
D, K Mark the deletion buffer and move it to the next item. Take effect after pressing x
C-d Mark the deletion buffer and move it to the previous item. Take effect after pressing x
S Mark save Buffer Take effect after pressing x
X Buffer for deleting or storing tags
U Unmark the current buffer and move it to the next one
Backspace Unmark the current buffer and move it to the previous one
~ Set buffering to unmodified
% Switch the read-only attribute of the buffer
1 The selected buffer is displayed in the full window.
2 Show the selected buffer in the half window
T Buffer display in tags table mode
F, RET Show selected Buffer
O Buffer is displayed in the new window and select this window
C-o The buffer is displayed in the new window, but this window is not selected
B Move the selected buffer to the last row
M Tag Buffer displayed in new window Take effect after pressing v
V Show the marked Buffer
G Refresh buffer menu
T Switch display file association Buffer
Q Exit buffer menu

 

Note that most of the functions take effect immediately, but such functions as D, S, and m only act as tags and are executed after confirmation, after you press these three keys, the three symbols "D", "S", and ">" are displayed before the buffer name as a prompt.

 

Iii. Indirect Buffering

Indirect buffering refers to a buffer that shares content with other buffers. It is linked to a base buffer. CommandM-x make-indirect-buffer RET base-buffer RET indirect-BufferCreates a buffer called "indirect-buffer", which is bound to "base-buffer. Or useClone-indirect-BufferTo quickly copy the current buffer. There is a synchronization between the indirect buffer and the base buffer, that is, their content is exactly the same, but it is only the same content, but it is essentially two completely separated buffers. Different from the base buffer, the indirect buffer cannot be associated with the file. If you try to save an indirect buffer, it only applies to the base buffer. In addition, because of the associations between the two buffering methods, you can disable the Buffer Based on the buffer duration, but disable the indirect buffer will not happen.

There are few places to use Indirect buffering, especially when usingArticleOrCodeVery long. If you want to edit the page header and check the end of the page, indirect buffering is the best choice.

 

Summary:

Buttons

Command

Function

C-x B

Switch-to-Buffer

Open or create a buffer

C-x 4 B

Switch-to-buffer-other-Window

Open or create a buffer in another window

C-x 5 B

Switch-to-buffer-other-Frame

Open or create a buffer in another frame

C-x left

Next-Buffer

Move to the next Buffer

C-X right

Previous-Buffer Move to the previous Buffer
C-x C-B List-Buffers Show all Buffers
C-u C-x C-B Display the buffer mapped to the file
C-x K Kill-Buffer Disable buffering
Kill-some-Buffers Disable multiple Buffers
Clean-buffer-list Disable unused buffering for three days
C-x C-Q Toggle-read-only Switch the buffer read-only attribute
C-u m-g num Jump to the previous buffer num row
Rename-Buffer Rename Cache
Rename-uniquely Rename the buffer and add a number after its name
View-Buffer Enable buffer in read-only mode
Buffer-menu Open buffer menu
Make-indirect-Buffer Indirect Buffering
Clone-indirect-Buffer Establishes the indirect buffer of the Current Buffer

Not complete...

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.