In Emacs, how do I copy a region of text (to paste it in another buffer) without killing it (for example: the file I want to copy from is opened in read-only mode, so killing it isn't an option).
Just mark it (C-space at one end of the range, and move to the other end) and use M-w (kill-ring-save
):
(kill-ring-save BEG END)
Save the region as if killed, but don't kill it.
Two additional ways:
You can also select it with the mouse (mouse-button-1), which will copy the region to the kill ring.
When the buffer is read-only, you can use the
kill-*
routines (C-w and C-k) to copy the region/line to the kill ring. Emacs will beep at you, but it's a documented feature:
If the buffer is read-only, Emacs will beep and refrain from deleting the text, but put the text in the kill ring anyway. This means that you can use the killing commands to copy text from a read-only buffer.
I use the command
M-x append-to-file
the problem with this is that if the file you want to copy it to is open, you will need to refresh the screen somehow so that the new stuff appears there. Also, the stuff you copied will go to the end of the file you choose as the target.
You might also find the commands
M-x write-region
and
C-x i (insert-file)
useful.