Next: , Up: Buffers   [Index]


7.4.1 About Buffers

A Buffer is a Lisp Object—a special data type

A buffer is a Lisp object containing text to be edited. Buffers in Emacs editing are objects that have distinct names and hold text that can be edited. Each time you visit a file, a buffer is used to hold the file’s text. Each buffer has a unique name, which can be of any length. Most buffers are made by visiting files, and their names are derived from the files’ names; however, you can also create an empty buffer with any name you want.

Buffers appear to Lisp programs as a special data type. You can think of the contents of a buffer as a string that you can extend; insertions and deletions may occur in any part of the buffer.

Files and Windows

Buffers are used to hold the contents of files that are being visited; there may also be buffers that are not visiting files. For examppl each time you invoke Dired, a buffer is used to hold the directory listing. If you send a message with ‘C-x m’, a buffer is used to hold the text of the message. When you ask for a command’s documentation, that appears in a buffer named ‘*Help*’. Each buffer, including the current buffer, may or may not be displayed in any windows. When a buffer is displayed in a window, its name is shown in the mode line.

Current Buffer

Only one buffer is selected and designated the current buffer at any time. When a command operates on “the buffer”, this really means that it operates on the current buffer. When there is only one Emacs window, the buffer displayed in that window is current. When there are multiple windows, the buffer displayed in the “selected window” is current.

Properties

A buffer’s “contents” consist of a series of characters, each of which optionally carries a set of text properties that can specify more information about that character.

Buffer-Local Variables

Buffer-specific information that is directly accessible is stored in buffer-local variable bindings, which are variable values that are effective only in a particular buffer. This feature allows each buffer to override the values of certain variables. Most major modes override variables.

Aside from its textual contents, each buffer records several pieces of information, such as what file it is visiting (if any), whether it is modified, and what major mode and minor modes are in effect. These are stored in “buffer-local variables”—variables that can have a different value in each buffer.

Buffer Positions

A position is the index of a character in the text of a buffer. A position actually identifies the place between characters or before the first character, or after the last character. One speaks of the character either before or after a given position. When one says the character “at” a position, one usually is referring to the character after that position.

Positions can be represented either by integers or by markers. A marker is a special object that relocates automatically when text is inserted or deleted so it stays with the surrounding characters.

Function: bufferp object

Return t if OBJECT is an editor buffer.


Next: Interactive Commands for Creating and Selecting Buffers, Up: Buffers   [Index]