| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 24.1 Introduction to Buffers | A buffer holds a block of text such as a file. | |
| 24.2 Buffer Lists | Keeping track of all buffers. | |
| 24.3 Markers and Extents | Tagging locations within a buffer. | |
| 24.4 The Buffer Object | The Lisp object corresponding to a buffer. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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:
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 current_buffer. Switching
to a different window changes the current buffer. Note that Lisp code
can temporarily change the current buffer using set-buffer (often
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 on windows.)
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Recall earlier that buffers are permanent objects, i.e. that
they remain around until explicitly deleted. This entails that there is
a list of all the buffers in existence. This list is actually an
assoc-list (mapping from the buffer's name to the buffer) and is stored
in the global variable Vbuffer_alist.
The order of the buffers in the list is important: the buffers are
ordered approximately from most-recently-used to least-recently-used.
Switching to a buffer using switch-to-buffer,
pop-to-buffer, etc. and switching windows using
other-window, etc. usually brings the new current buffer to the
front of the list. switch-to-buffer, other-buffer,
etc. look at the beginning of the list to find an alternative buffer to
suggest. You can also explicitly move a buffer to the end of the list
using bury-buffer.
In addition to the global ordering in Vbuffer_alist, each frame
has its own ordering of the list. These lists always contain the same
elements as in Vbuffer_alist although possibly in a different
order. buffer-list normally returns the list for the selected
frame. This allows you to work in separate frames without things
interfering with each other.
The standard way to look up a buffer given a name is
get-buffer, and the standard way to create a new buffer is
get-buffer-create, which looks up a buffer with a given name,
creating a new one if necessary. These operations correspond exactly
with the symbol operations intern-soft and intern,
respectively. You can also force a new buffer to be created using
generate-new-buffer, which takes a name and (if necessary) makes
a unique name from this by appending a number, and then creates the
buffer. This is basically like the symbol operation gensym.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Among the things associated with a buffer are things that are logically attached to certain buffer positions. This can be used to keep track of a buffer position when text is inserted and deleted, so that it remains at the same spot relative to the text around it; to assign properties to particular sections of text; etc. There are two such objects that are useful in this regard: they are markers and extents.
A marker is simply a flag placed at a particular buffer
position, which is moved around as text is inserted and deleted.
Markers are used for all sorts of purposes, such as the mark that
is the other end of textual regions to be cut, copied, etc.
An extent is similar to two markers plus some associated properties, and is used to keep track of regions in a buffer as text is inserted and deleted, and to add properties (e.g. fonts) to particular regions of text. The external interface of extents is explained elsewhere.
The important thing here is that markers and extents simply contain buffer positions in them as integers, and every time text is inserted or deleted, these positions must be updated. In order to minimize the amount of shuffling that needs to be done, the positions in markers and extents (there's one per marker, two per extent) are stored in Membpos's. This means that they only need to be moved when the text is physically moved in memory; since the gap structure tries to minimize this, it also minimizes the number of marker and extent indices that need to be adjusted. Look in `insdel.c' for the details of how this works.
One other important distinction is that markers are temporary while extents are permanent. This means that markers disappear as soon as there are no more pointers to them, and correspondingly, there is no way to determine what markers are in a buffer if you are just given the buffer. Extents remain in a buffer until they are detached (which could happen as a result of text being deleted) or the buffer is deleted, and primitives do exist to enumerate the extents in a buffer.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Buffers contain fields not directly accessible by the Lisp programmer. We describe them here, naming them by the names used in the C code. Many are accessible indirectly in Lisp programs via Lisp primitives.
name
save_modified
modtime
auto_save_modified
last_window_start
window-start position in the buffer as of
the last time the buffer was displayed in a window.
undo_list
syntax_table_v
downcase_table
upcase_table
case_canon_table
case_eqv_table
display_table
nil if it
doesn't have one. See section `Display Tables' in XEmacs Lisp Reference Manual.
markers
backed_up
mark
markers. See section `The Mark' in XEmacs Lisp Reference Manual.
mark_active
nil if the buffer's mark is active.
local_var_alist
modeline_format
base_buffer
nil.
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |