Go to the first, previous, next, last section, table of contents.


The Current Buffer

The current buffer is the buffer being displayed in the current window (see section Windows), all functions which take an optional buffer argument will operate on the current buffer if this argument is undefined. Similarly if a window argument to a function is left undefined the current window will be used.

Function: current-buffer &optional window
Returns the buffer being displayed by the window window (or the current window).

(current-buffer)
    => #<buffer programmer.texi>

The set-current-buffer function sets the current buffer of a window. If, when the window is next redisplayed (i.e. after each command), the current buffer is different to what it was at the last redisplay the new buffer will be displayed in the window.

Function: set-current-buffer buffer &optional window
Sets the buffer that the window is displaying.

Usually a window's current buffer will be the buffer which is at the head of the window's buffer-list. The function goto-buffer can be used to set both of these at once.

Function: goto-buffer buffer
Set the current buffer to buffer which is either a buffer or a string naming a buffer. The selected buffer is moved to the head of the window's buffer-list.

If buffer is a string and no buffer exists of that name a new one is created.

Often you will want to temporarily switch to a different current buffer, that is what the with-buffer special form is for.

Special Form: with-buffer buffer forms...
Temporarily sets the current buffer to the value of evaluating buffer, then evaluates the forms in sequence. The old value of the current buffer is reinstated and the structure returns the value of the last of the forms to be evaluated.

If the implicit progn evaluating forms is exited abnormally the old value of the current buffer will still be reinstated.

If the window is redisplayed while the forms are being evaluated (i.e. in a recursive edit) the new buffer will be drawn into the window.

(with-buffer new-buffer         ;Enter a recursive edit in
  (recursive-edit))             ; the buffer new-buffer.


Go to the first, previous, next, last section, table of contents.