Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 5: Recovering from Errors

Previous HourNext Hour

Sections in this Hour:

 

Automatic Backup


When you load an existing file into Emacs, it makes a backup of it for you the first time it saves this file, in case you later find that you need the original version.

Caution - Please note that it does not make a backup each time you save the buffer, but only when you save it the first time after you read it into Emacs.


There are two different ways Emacs can do these backups:

There are a number of variables that configure this feature. First of all, you can disable backup entirely. Please think carefully before you do this! To disable backup, insert the following line into your .emacs file:


(setq make-backup-files nil)

If you would like Emacs to do a single backup (and it doesn't already), you must insert the following lines into your .emacs file:


 (setq make-backup-files t) 
(setq version-control 'never) 

Finally, if you want Emacs to make numbered backups, you must insert the following lines into your .emacs file:


(setq make-backup-files t) 
(setq version-control t) 

Configuring Numbered Backups

To avoid filling up your disk with backup files, Emacs only keeps a certain number of numbered backups. This number can be configured with two variables:

As an example, the following lines make Emacs keep the original file before you start to edit it and the five latest versions of it:


(setq kept-old-versions 1) 
(setq kept-new-versions 5) 

It should, of course, be inserted into your .emacs file along with the lines that enable numbered backups.

When old numbered backup files are about to be deleted, Emacs asks you for permission to do so. In the long run, this is very annoying, so when you have gained confidence in Emacs and its deletion of old backup files, you might want to insert the following into your .emacs file, which makes it silently delete the old backup files:


(setq delete-old-versions t) 

Keeping All the Backup Files in One Directory

Backup files are normally written next to the files that they are a backup of. This has the advantage that they are easy to find, but it also has the disadvantage that they tend to clobber your hard disk. An alternative is to keep all your backup files in one directory.

To do this, you need the library called backup-dir. It is part of XEmacs, but GNU Emacs users need to copy it from the CD to their Lisp directory.

The library contains many different configurations. It is beyond the scope for this book to discuss all of them. (See the header of the Lisp file for the others.) One way to use it, however, is to make Emacs do all autosaving in one directory. To do this, insert lines similar to the following into your .emacs file:


(require 'backup-dir) 
(setq bkup-backup-directory-info 
      '((t "/home/blackie/.backups" ok-create full-path))) 

You should of course replace /home/blackie/.backups with the directory in which you want your backup files to be located.

Caution - To use this library in GNU Emacs version 19, you need to install the customize library or the cust-stub library. See Appendix A, "Installing Functions and Packages from the CD," for instructions for installing these.


Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 5: Recovering from Errors

Previous HourNext Hour

Sections in this Hour: