insert-buffer
insert-buffer is yet another buffer-related function. This
command copies another buffer into the current buffer. It is the
reverse of append-to-buffer or copy-to-buffer, since they
copy a region of text from the current buffer to another buffer.
In addition, this code illustrates the use of interactive with a
buffer that might be read-only and the important distinction
between the name of an object and the object actually referred to. Here
is the code:
(defun insert-buffer (buffer)
"Insert after point the contents of BUFFER.
Puts mark after the inserted text.
BUFFER may be a buffer or a buffer name."
(interactive "*bInsert buffer: ")
(or (bufferp buffer)
(setq buffer (get-buffer buffer)))
(let (start end newmark)
(save-excursion
(save-excursion
(set-buffer buffer)
(setq start (point-min) end (point-max)))
(insert-buffer-substring buffer start end)
(setq newmark (point)))
(push-mark newmark)))
As with other function definitions, you can use a template to see an outline of the function:
(defun insert-buffer (buffer) "documentation..." (interactive "*bInsert buffer: ") body...)
Go to the first, previous, next, last section, table of contents.