Download GNU Emacs Manual - Programming Systems Lab

Transcript
Chapter 15: File Handling
124
When you delete a substantial part of the text in a large buffer, auto save turns off
temporarily in that buffer. This is because if you deleted the text unintentionally, you
might find the auto-save file more useful if it contains the deleted text. To reenable autosaving after this happens, save the buffer with C-x C-s, or use C-u 1 M-x auto-save-mode.
If you want auto-saving to be done in the visited file rather than in a separate auto-save
file, set the variable auto-save-visited-file-name to a non-nil value. In this mode,
there is no real difference between auto-saving and explicit saving.
A buffer’s auto-save file is deleted when you save the buffer in its visited file. (You can
inhibit this by setting the variable delete-auto-save-files to nil.) Changing the visited
file name with C-x C-w or set-visited-file-name renames any auto-save file to go with
the new visited name.
15.5.2 Controlling Auto-Saving
Each time you visit a file, auto-saving is turned on for that file’s buffer if the variable
auto-save-default is non-nil (but not in batch mode; see Chapter 3 [Entering Emacs],
page 15). The default for this variable is t, so auto-saving is the usual practice for file-visiting
buffers. Auto-saving can be turned on or off for any existing buffer with the command M-x
auto-save-mode. Like other minor mode commands, M-x auto-save-mode turns autosaving on with a positive argument, off with a zero or negative argument; with no argument,
it toggles.
Emacs does auto-saving periodically based on counting how many characters you have
typed since the last time auto-saving was done. The variable auto-save-interval specifies
how many characters there are between auto-saves. By default, it is 300. Emacs doesn’t
accept values that are too small: if you customize auto-save-interval to a value less than
20, Emacs will behave as if the value is 20.
Auto-saving also takes place when you stop typing for a while. The variable autosave-timeout says how many seconds Emacs should wait before it does an auto save (and
perhaps also a garbage collection). (The actual time period is longer if the current buffer
is long; this is a heuristic which aims to keep out of your way when you are editing long
buffers, in which auto-save takes an appreciable amount of time.) Auto-saving during idle
periods accomplishes two things: first, it makes sure all your work is saved if you go away
from the terminal for a while; second, it may avoid some auto-saving while you are actually
typing.
Emacs also does auto-saving whenever it gets a fatal error. This includes killing the
Emacs job with a shell command such as ‘kill %emacs’, or disconnecting a phone line or
network connection.
You can request an auto-save explicitly with the command M-x do-auto-save.
15.5.3 Recovering Data from Auto-Saves
You can use the contents of an auto-save file to recover from a loss of data with the command M-x recover-file RET file RET. This visits file and then (after your confirmation)
restores the contents from its auto-save file ‘#file #’. You can then save with C-x C-s to
put the recovered text into file itself. For example, to recover file ‘foo.c’ from its auto-save
file ‘#foo.c#’, do:
M-x recover-file RET foo.c RET