E.9.1 Buffer Internals
Two structures (see buffer.h) are used to represent buffers in C. The buffer_text structure contains fields describing the text of a buffer; the buffer structure holds other fields. In the case of indirect buffers, two or more buffer structures reference the same buffer_text structure.
Here are some of the fields in struct buffer_text:
begβ
The address of the buffer contents. The buffer contents is a linear C array of char, with the gap somewhere in its midst.
gptβ
gpt_byteβ
The character and byte positions of the buffer gap. See Buffer Gap.
zβ
z_byteβ
The character and byte positions of the end of the buffer text.
gap_sizeβ
The size of bufferβs gap. See Buffer Gap.
modiffβ
save_modiffβ
chars_modiffβ
overlay_modiffβ
These fields count the number of buffer-modification events performed in this buffer. modiff is incremented after each buffer-modification event, and is never otherwise changed; save_modiff contains the value of modiff the last time the buffer was visited or saved; chars_modiff counts only modifications to the characters in the buffer, ignoring all other kinds of changes (such as text properties); and overlay_modiff counts only modifications to the bufferβs overlays.
beg_unchangedβ
end_unchangedβ
The number of characters at the start and end of the text that are known to be unchanged since the last complete redisplay.
unchanged_modifiedβ
overlay_unchanged_modifiedβ
The values of modiff and overlay_modiff, respectively, after the last complete redisplay. If their current values match modiff or overlay_modiff, that means beg_unchanged and end_unchanged contain no useful information.
markersβ
The markers that refer to this buffer. This is actually a single marker, and successive elements in its marker chain (a linked list) are the other markers referring to this buffer text.
intervalsβ
The interval tree which records the text properties of this buffer.
Some of the fields of struct buffer are:
headerβ
A header of type union vectorlike_header is common to all vectorlike objects.
own_textβ
A struct buffer_text structure that ordinarily holds the buffer contents. In indirect buffers, this field is not used.
textβ
A pointer to the buffer_text structure for this buffer. In an ordinary buffer, this is the own_text field above. In an indirect buffer, this is the own_text field of the base buffer.
nextβ
A pointer to the next buffer, in the chain of all buffers, including killed buffers. This chain is used only for allocation and garbage collection, in order to collect killed buffers properly.
ptβ
pt_byteβ
The character and byte positions of point in a buffer.
begvβ
begv_byteβ
The character and byte positions of the beginning of the accessible range of text in the buffer.
zvβ
zv_byteβ
The character and byte positions of the end of the accessible range of text in the buffer.
base_bufferβ
In an indirect buffer, this points to the base buffer. In an ordinary buffer, it is null.
local_flagsβ
This field contains flags indicating that certain variables are local in this buffer. Such variables are declared in the C code using DEFVAR_PER_BUFFER, and their buffer-local bindings are stored in fields in the buffer structure itself. (Some of these fields are described in this table.)
modtimeβ
The modification time of the visited file. It is set when the file is written or read. Before writing the buffer into a file, this field is compared to the modification time of the file to see if the file has changed on disk. See Buffer Modification.
auto_save_modifiedβ
The time when the buffer was last auto-saved.
last_window_startβ
The window-start position in the buffer as of the last time the buffer was displayed in a window.
clip_changedβ
This flag indicates that narrowing has changed in the buffer. See Narrowing.
prevent_redisplay_optimizations_pβ
This flag indicates that redisplay optimizations should not be used to display this buffer.
overlay_centerβ
This field holds the current overlay center position. See Managing Overlays.
overlays_beforeβ
overlays_afterβ
These fields hold, respectively, a list of overlays that end at or before the current overlay center, and a list of overlays that end after the current overlay center. See Managing Overlays. overlays_before is sorted in order of decreasing end position, and overlays_after is sorted in order of increasing beginning position.
nameβ
A Lisp string that names the buffer. It is guaranteed to be unique. See Buffer Names. This and the following fields have their names in the C struct definition end in a _ to indicate that they should not be accessed directly, but via the BVAR macro, like this:
Lisp_Object buf_name = BVAR (buffer, name);
save_lengthβ
The length of the file this buffer is visiting, when last read or saved. It can have 2 special values: -1 means auto-saving was turned off in this buffer, and -2 means donβt turn off auto-saving if buffer text shrinks a lot. This and other fields concerned with saving are not kept in the buffer_text structure because indirect buffers are never saved.
directoryβ
The directory for expanding relative file names. This is the value of the buffer-local variable default-directory (see File Name Expansion).
filenameβ
The name of the file visited in this buffer, or nil. This is the value of the buffer-local variable buffer-file-name (see Buffer File Name).
undo_listβ
backed_upβ
auto_save_file_nameβ
auto_save_file_formatβ
read_onlyβ
file_formatβ
file_truenameβ
invisibility_specβ
display_countβ
display_timeβ
These fields store the values of Lisp variables that are automatically buffer-local (see Buffer-Local Variables), whose corresponding variable names have the additional prefix buffer- and have underscores replaced with dashes. For instance, undo_list stores the value of buffer-undo-list.
markβ
The mark for the buffer. The mark is a marker, hence it is also included on the list markers. See The Mark.
local_var_alistβ
The association list describing the buffer-local variable bindings of this buffer, not including the built-in buffer-local bindings that have special slots in the buffer object. (Those slots are omitted from this table.) See Buffer-Local Variables.
major_modeβ
Symbol naming the major mode of this buffer, e.g., lisp-mode.
mode_nameβ
Pretty name of the major mode, e.g., "Lisp".
keymapβ
abbrev_tableβ
syntax_tableβ
category_tableβ
display_tableβ
These fields store the bufferβs local keymap (see Keymaps), abbrev table (see Abbrev Tables), syntax table (see Syntax Tables), category table (see Categories), and display table (see Display Tables).
downcase_tableβ
upcase_tableβ
case_canon_tableβ
These fields store the conversion tables for converting text to lower case, upper case, and for canonicalizing text for case-fold search. See Case Tables.
minor_modesβ
An alist of the minor modes of this buffer.
pt_markerβ
begv_markerβ
zv_markerβ
These fields are only used in an indirect buffer, or in a buffer that is the base of an indirect buffer. Each holds a marker that records pt, begv, and zv respectively, for this buffer when the buffer is not current.
mode_line_formatβ
header_line_formatβ
case_fold_searchβ
tab_widthβ
fill_columnβ
left_marginβ
auto_fill_functionβ
truncate_linesβ
word_wrapβ
ctl_arrowβ
bidi_display_reorderingβ
bidi_paragraph_directionβ
selective_displayβ
selective_display_ellipsesβ
overwrite_modeβ
abbrev_modeβ
mark_activeβ
enable_multibyte_charactersβ
buffer_file_coding_systemβ
cache_long_line_scansβ
point_before_scrollβ
left_fringe_widthβ
right_fringe_widthβ
fringes_outside_marginsβ
scroll_bar_widthβ
indicate_empty_linesβ
indicate_buffer_boundariesβ
fringe_indicator_alistβ
fringe_cursor_alistβ
scroll_up_aggressivelyβ
scroll_down_aggressivelyβ
cursor_typeβ
cursor_in_non_selected_windowsβ
These fields store the values of Lisp variables that are automatically buffer-local (see Buffer-Local Variables), whose corresponding variable names have underscores replaced with dashes. For instance, mode_line_format stores the value of mode-line-format.
last_selected_windowβ
This is the last window that was selected with this buffer in it, or nil if that window no longer displays this buffer.