Книга: Learning GNU Emacs, 3rd Edition

2.6.4 Going Back to a Previous Version: Backup Files

2.6.4 Going Back to a Previous Version: Backup Files

The first time you save a file during an editing session, Emacs creates a backup file. If something disastrous happens, and the other techniques for undoing changes won't help you, you can always return to the backup file. The name of the backup file is the same as the name of the file you're editing, with a tilde (~) added. For example, if you are editing the file text, the backup file is text~.

Emacs doesn't provide any special commands for restoring a buffer from the backup copy. The easiest way to do this is to edit the backup copy and then save it as the real file. For example, if you were working with a file called text, you could: exit Emacs by typing C-x C-c, then start Emacs again by typing emacs text~. After the backup file is displayed, save it as the real file by typing C-x C-w textEnter. As a safeguard, Emacs asks you before it writes over the original file:

File text exists; overwrite? (y or n)

Type y to overwrite the original file with the backup file.

GNU Emacs also has a numbered backup facility. If you turn on numbered backups, Emacs creates a backup file (with the suffix ~n~) every time you save your file. n increments with each successive save. If you are nervous about deleting older versions, it might be worth using: you can keep all of your old versions forever, if you want to. However, numbered backups can also waste disk space; a happy medium may be to tell Emacs to keep the last n versions, where n is the number of versions you want to keep. The variables that control numbered backups are described in Appendix A. If you are interested in full-blown version control, check out VC mode, discussed in Chapter 12. Table 2-12 summarizes the commands for stopping commands and undoing changes.

Table 2-12. Stopping and undoing commands

Keystrokes Command name Action
C-g keyboard-quit Abort current command.
C-x u advertised-undo[17] Undo last edit (can be done repeatedly).
C-_ Edit ? Undo undo Undo last edit (can be done repeatedly).
(none) revert-buffer Restore buffer to the state it was in when the file was last saved (or auto-saved).

Оглавление книги


Генерация: 2.959. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз