I would like to be able to save a copy (or a snapshot) of a buffer into a file. The behavior would be similar to write-file
, except that it would not set the buffer to visit this file.
For a usecase, imagine that you have a shell session, and you want to quickly save it all into a log file. The buffer should not be renamed (so that functions relying on the buffer name still work), and it should not be visiting a file (so that the file is not accidentally overwritten, and there is no warning when exitting emacs).
I can imagine a few dirty ways of doing this, I will post one as a self-answer, but reading from the manual, the whole "visited file" system is more complicated than it looks, and I guess it is easy to draft a wrong solution. Is there a hidden, built-in, way of achieving this?