Copying Or Writing An Emacs Region

Emacs provides a nice set of commands to copy a region in a buffer to another buffer or to write it to a file. In each case, these functions will prompt for the name of the file or buffer when called interactively. The functions are:

  • append-to-buffer
    Despite its name, this function does not, strictly speaking append the region to a new buffer. Rather it inserts it in the new buffer at point.
  • copy-to-buffer
    This command replaces the text in the new buffer with the region from the current buffer.
  • append-to-file
    Append the region onto the end of the file.
  • write-region
    Write the region to the named file. When called from Elisp, this function has 4 optional arguments that control whether or not to append to the file, whether the file can already exist, and alternate naming.

These aren't commands that you'll use a lot but they are convenient for moving part of a buffer to another buffer or file.

This entry was posted in General and tagged . Bookmark the permalink.