17.1 Introduction to Buffers
A buffer is logically just a Lisp object that holds some text.
In this, it is like a string, but a buffer is optimized for
frequent insertion and deletion, while a string is not. Furthermore:
- Buffers are permanent objects, i.e. once you create them, they
remain around, and need to be explicitly deleted before they go away.
- Each buffer has a unique name, which is a string. Buffers are
normally referred to by name. In this respect, they are like
- Buffers have a default insertion position, called point.
Inserting text (unless you explicitly give a position) goes at point,
and moves point forward past the text. This is what is going on when
you type text into Emacs.
- Buffers have lots of extra properties associated with them.
- Buffers can be displayed. What this means is that there
exist a number of windows, which are objects that correspond
to some visible section of your display, and each window has
an associated buffer, and the current contents of the buffer
are shown in that section of the display. The redisplay mechanism
(which takes care of doing this) knows how to look at the
text of a buffer and come up with some reasonable way of displaying
this. Many of the properties of a buffer control how the
buffer’s text is displayed.
- One buffer is distinguished and called the current buffer. It is
stored in the variable
current_buffer. Buffer operations operate
on this buffer by default. When you are typing text into a buffer, the
buffer you are typing into is always
to a different window changes the current buffer. Note that Lisp code
can temporarily change the current buffer using
enclosed in a
save-excursion so that the former current buffer
gets restored when the code is finished). However, calling
set-buffer will NOT cause a permanent change in the current
buffer. The reason for this is that the top-level event loop sets
current_buffer to the buffer of the selected window, each time
it finishes executing a user command.
Make sure you understand the distinction between current buffer
and buffer of the selected window, and the distinction between
point of the current buffer and window-point of the selected
window. (This latter distinction is explained in detail in the section