Advanced Text-Fu · Lesson 10 of 13
Emacs Manipulate Files
0 / 5 checkpoints answered
Emacs visits files in buffers. Editing changes the buffer first; saving writes its current contents to the associated pathname. Read minibuffer messages because permissions, conflicting disk changes, or other errors can prevent a write.
Visiting a File
Use C-x C-f, which runs find-file, then enter a pathname in the minibuffer and press Enter:
C-x C-f
Emacs opens an existing readable file in a buffer or prepares a new file-visiting buffer when the pathname is missing. In the second case, no disk file exists until a save succeeds.
You can use Tab completion while entering a pathname. Visiting a directory normally opens Dired, Emacs's directory editor, rather than treating the directory as a text file.
CheckWhich Emacs key sequence prompts for a pathname and visits it?
press 1/2/3 to answer · → next lesson
CheckWhen C-x C-f visits a pathname that does not exist, when is the disk file normally created?
press 1/2/3 to answer · → next lesson
Saving the Current Buffer
Use C-x C-s, which runs save-buffer, to save the current file-visiting buffer:
C-x C-s
If the buffer has no associated filename, Emacs prompts for one. A successful write clears the buffer's modified indicator; a failure leaves the unsaved data in the buffer and reports an error.
CheckWhich key sequence saves the current file-visiting buffer?
press 1/2/3 to answer · → next lesson
Writing under Another Name
Use C-x C-w, which runs write-file, to prompt for a pathname, write the buffer there, and make the buffer visit that new file:
C-x C-w
This is the Emacs “Save As” behavior. It differs from merely writing a separate copy while continuing to visit the original pathname.
CheckWhich key sequence performs the usual Save As operation for the current buffer?
press 1/2/3 to answer · → next lesson
Reviewing Several Modified Buffers
Use C-x s, which runs save-some-buffers, to examine modified file-visiting buffers:
C-x s
Emacs normally asks whether to save each eligible modified buffer. Read the buffer name and answer deliberately; this is not an unconditional save-all shortcut.
CheckWhat does C-x s normally do?
press 1/2/3 to answer · → next lesson
Reverting from Disk
If a file changed on disk and you intentionally want to discard the buffer's current contents, run M-x revert-buffer and review the confirmation prompt. Reverting can destroy unsaved buffer edits, so use it only after confirming which source should win.
To compare before deciding, save a separate copy or use version-control and diff tools. Avoid treating reload operations as harmless when the buffer is modified.
Summary
You can now manage file-backed buffers without confusing visits and writes.
- Visit a pathname with
C-x C-f. - Create a missing file only when its buffer is saved.
- Save the current buffer with
C-x C-s. - Save under a new visited name with
C-x C-w. - Review several modified buffers with
C-x s.
Lesson complete
You finished Emacs Manipulate Files. Nice work — keep the momentum going.