These are the commands that relate to saving and writing files.
not-modified). With prefix argument (C-u), mark the current buffer as changed.
When you wish to save the file and make your changes permanent, type
C-x C-s (
save-buffer). After saving is finished, C-x C-s
displays a message like this:
If the current buffer is not modified (no changes have been made in it since the buffer was created or last saved), saving is not really done, because it would have no effect. Instead, C-x C-s displays a message like this in the echo area:
(No changes need to be saved)
With a prefix argument, C-u C-x C-s, Emacs also marks the buffer to be backed up when the next save is done. See Backup.
The command C-x s (
save-some-buffers) offers to save any
or all modified buffers. It asks you what to do with each buffer. The
possible responses are analogous to those of
save-some-bufferswithout any more saving.
save-some-bufferswithout even asking about other buffers.
save-some-buffers, which asks the question again.
diff-buffer-with-file(see Comparing Files).
You can customize the value of
save-some-buffers-default-predicate to control which buffers
Emacs will ask about.
C-x C-c, the key sequence to exit Emacs, invokes
save-some-buffers and therefore asks the same questions.
If you have changed a buffer but do not wish to save the changes,
you should take some action to prevent it. Otherwise, each time you
use C-x s or C-x C-c, you are liable to save this buffer
by mistake. One thing you can do is type M-~
not-modified), which clears out the indication that the buffer
is modified. If you do this, none of the save commands will believe
that the buffer needs to be saved. (‘~’ is often used as a
mathematical symbol for “not”; thus M-~ is “not”, metafied.)
Alternatively, you can cancel all the changes made since the file was
visited or saved, by reading the text from the file again. This is
called reverting. See Reverting. (You could also undo all
the changes by repeating the undo command C-x u until you have
undone all the changes; but reverting is easier.)
M-x set-visited-file-name alters the name of the file that the
current buffer is visiting. It reads the new file name using the
minibuffer. Then it marks the buffer as visiting that file name, and
changes the buffer name correspondingly.
does not save the buffer in the newly visited file; it just alters the
records inside Emacs in case you do save later. It also marks the
buffer as modified so that C-x C-s in that buffer
If you wish to mark the buffer as visiting a different file and save
it right away, use C-x C-w (
write-file). This is
set-visited-file-name followed by C-x C-s,
except that C-x C-w asks for confirmation if the file exists.
C-x C-s used on a buffer that is not visiting a file has the
same effect as C-x C-w; that is, it reads a file name, marks the
buffer as visiting that file, and saves it there. The default file
name in a buffer that is not visiting a file is made by combining the
buffer name with the buffer's default directory (see File Names).
If the new file name implies a major mode, then C-x C-w switches
to that major mode, in most cases. The command
set-visited-file-name also does this. See Choosing Modes.
If Emacs is about to save a file and sees that the date of the latest version on disk does not match what Emacs last read or wrote, Emacs notifies you of this fact, because it probably indicates a problem caused by simultaneous editing and requires your immediate attention. See Simultaneous Editing.