Go to the previous, next section.

The Definition of  append-to-buffer

The  append-to-buffer command is very nearly as simple as the  mark-whole-buffer command. What it does is copy the region (that is, the part of the buffer between point and mark) from the current buffer to a specified buffer.

The  append-to-buffer command uses the  insert-buffer-substring function to copy the region.  insert-buffer-substring is described by its name: it takes a string of characters from part of a buffer, a "substring", and inserts them into another buffer. Most of  append-to-buffer is concerned with setting up the conditions for  insert-buffer-substring to work: the code must specify both the buffer to which the text will go and the region that will be copied. Here is the complete text of the function:

(defun append-to-buffer (buffer start end)
  "Append to specified buffer the text of the region.
It is inserted into that buffer before its point.

When calling from a program, give three arguments:
a buffer or the name of one, and two character numbers
specifying the portion of the current buffer to be copied."
  (interactive "BAppend to buffer: \nr")
  (let ((oldbuf (current-buffer)))
    (save-excursion
      (set-buffer (get-buffer-create buffer))
      (insert-buffer-substring oldbuf start end))))

The function can be understood by looking at it as a series of filled-in templates.

The outermost template is for the function definition. In this case, it looks like this (with several slots filled in):

(defun append-to-buffer (buffer start end)
  "documentation@dots{}"
  (interactive "BAppend to buffer: \nr")
  body@dots{})

The first line of the function includes its name and three arguments. The arguments are the  buffer to which the text will be copied, and the  start and  end of the region in the current buffer that will be copied.

The next part of the function is the documentation, which is clear and complete.

Go to the previous, next section.