Emacs backup function

xiaoxiao2021-03-06  19

For a general situation, when saving a file, the operating system saves the content you edited on your disk, and the original file content will be lost. Emacs When you save a file, you will copy your files to another file, so when you change your mind, you can find it back, these files are called backups. file.

Automatic automatic backup of GNU Emacs

The backup of the file is not necessary. To turn off the function of the automatic backup, you can set the make-backup-files variable value to nil, of course, its default value is usually T, which is the automatic backup file.

When you use the version control system, whether Emacs automatically backs up files to see the value of vc-make-backup-files. The default is NIL, that is, no backup file, because the version control system saves all version of the file, the automatic backup here is extra.

The default value for the backup-enable-predicate variable can ensure that Emacs will not back up files in the zero-file directory. The zero file directory is specified by the two variables of Temporary-File-Directory and Small-Temporary-File-Directory.

Emacs can automatically back up files, or save multiple backups for each file.

Emacs is only backup files when you save it after you open the file. That is, no matter how many times, the contents in the backup file are always in the content before you open the file. But after you turn off this file and open it, Emacs generate a new backup file.

You can come to Emacs to back up files. Save the file with "CU CX CS", when you save the file next time, Emacs will back up this time you saved; save the file with "CU CU CX CS", save the file and put the original file. Save the file with "CU CU CU CU CX CS", will do the two works, save the file and back up the original content, and make a backup when the file is saved.

Automatic backup directory

By default, Emacs can automatically back up files. Emacs automatic backup files are ended with "~", with your original file in the same directory, for example: You are editing a file, its name is Readme, then when you save this file, Emacs will automatically save this file. A copy of the last time, its name is Readme ~ and and readme is in the same directory.

This default backup can make you easier to return to your original work. But this approach is very original and inefficient. Because you will find that it can only return to the previous edited file, and the previous save can not be recovered; and because the backup file and the original file are in the same directory, the time is long, your directory will be very mess. Therefore, many people tend to put backup files in a specific directory to save. Fortunately, Emacs's highly customizable can complete this feature.

You can specify a different backup function by modifying the variable Make-backup-file-name-function. To place a backup file in a different directory, modify backup-directory-alist to specify the directory. A typical modification method is to add "(". "," To Bakcup-Directory-Alist to place all backup files in the DIR directory, when there is a file in different directories, Emacs will automatically modify the backup file. The file name makes them no conflict. You can also add "(". ")" To Backup-Directory-Alist to back up files in hidden subdirectory ". ~". Single backup and multiple backups

Multiple backup files can save a series of backups of files, and its backup file appears in the form of ". ~ N ~". For example, "Readme. ~ 1 ~", "Readme. ~ 2 ~", etc.

Emacs executes a single backup or multiple backups, which are determined by variable Version-Control. The value "T" means executing multiple backups; the value "nil" indicates that if the file has multiple backup files, perform multiple backups, otherwise perform a single backup; value "Never" means performing a single backup.

You can use different Version-Control for different MODEs. You can also set the environment variable Version_Control to tell Emacs how to back up files, and Emacs will determine the value of Version-Control based on Version_Control at the time of startup. When Version_Control is "T" or "Numbered", Version-Control is automatically set to "t"; Version_Control is "NIL" or "exiSTING", Version-Control is automatically set to "nil"; version_Control is set to When "never" or "simple", Version-Control is automatically set to "Never".

Backup automatic deletion

Emacs's automatic backup system automatically deletes a backup file, only reserves the starting backup files and the nearest backup file.

Variable Kept-Old-Versions Specifies how much the first backup file is saved, and the variable kept-new-versions specifies how many recent backup files are saved, and they are default 2. The records of the most recent backup file can be obtained by variable kept-old-version.

If the delete-old-version variable is "T", Emacs automatically deletes the old backup file. If it is "nil", Emacs will ask if you want to delete before deleting, if it is other value, Emacs will not automatically delete old backups file.

In Dired mode, use "." Or delete the old backup file.

Typical setting

Typical setting:

(setq

Backup-by-copying t; automatic backup

Backup-Directory-Alist

'("." "~ / .saves")); automatic backup is under the directory "~ / .saves"

DELETE-OLD-VERSIONS T; Automatically delete old backup files

Kept-New-Versions 6; Keep the nearest two backup files

Kept-Old-Versions 2; Keep the earliest 2 backup files

Version-Control T); multiple backups

Other backups

转载请注明原文地址:https://www.9cbs.com/read-42478.html

New Post(0)