Next: , Previous: , Up: Top   [Contents][Index]

9.7 Accumulating Text

Usually you copy or move text by killing it and yanking it, but there are other ways that are useful for copying one block of text in many places, or for copying many scattered blocks of text into one place.

If you like, you can accumulate blocks of text from scattered locations either into a buffer or into a file. The relevant commands are described here. You can also use Emacs registers for storing and accumulating text. See Registers.

M-x append-to-buffer

Append region to contents of specified buffer (append-to-buffer).

M-x prepend-to-buffer

Prepend region to contents of specified buffer.

M-x copy-to-buffer

Copy region into specified buffer, deleting that buffer’s old contents.

M-x insert-buffer

Insert contents of specified buffer into current buffer at point.

M-x append-to-file

Append region to the end of the contents of specified file.

To accumulate text into a buffer, use the command M-x append-to-buffer, which inserts a copy of the region into the buffer buffername, at the location of point in that buffer. If there is no buffer with the given name, one is created.

If you append text to a buffer that has been used for editing, the copied text goes to the place where point is. Point in that buffer is left at the end of the copied text, so successive uses of append-to-buffer accumulate the text in the specified buffer in the same order as they were copied. Strictly speaking, this command does not always append to the text already in the buffer; but if this command is the only command used to alter a buffer, it does always append to the existing text because point is always at the end.

M-x prepend-to-buffer is similar to append-to-buffer, but point in the other buffer is left before the copied text, so successive prependings add text in reverse order. M-x copy-to-buffer is similar, except that any existing text in the other buffer is deleted, so the buffer is left containing just the text newly copied into it.

You can retrieve the accumulated text from that buffer with M-x insert-buffer, which takes buffername as an argument. It inserts a copy of the text in buffer buffername into the selected buffer. You could alternatively select the other buffer for editing, perhaps moving text from it by killing or with append-to-buffer. See Buffers, for background information on buffers.

Instead of accumulating text within Emacs in a buffer, you can append text directly into a file with M-x append-to-file, which takes file-name as an argument. It adds the text of the region to the end of the specified file. The file is changed immediately on disk. This command is normally used with files that are not being visited in Emacs. Using it on a file that Emacs is visiting can produce confusing results, because the file’s text inside Emacs does not change while the file itself changes.

Next: , Previous: , Up: Top   [Contents][Index]