Up: Swapping Text   [Index]


7.4.10.1 buffer-swap-text

Function: buffer-swap-text buffer

Swap the text between current buffer and BUFFER.

This function is very fast because it doesn’t move any text, it only changes the internal data structures of the buffer object to point to a different chunk of text. Using it, you can pretend that a group of two or more buffers are actually a single virtual buffer that holds the contents of all the individual buffers together.

If you use buffer-swap-text on a file-visiting buffer, you should set up a hook to save the buffer’s original text rather than what it was swapped with. write-region-annotate-functions works for this purpose. You should probably set buffer-saved-size to −2 in the buffer, so that changes in the text it is swapped with will not interfere with auto-saving.