Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I control how Emacs makes backup files?

Tags:

emacs

Emacs puts backup files named foo~ everywhere and I don't like having to remember to delete them. Also, if I edit a file that has a hard link somewhere else in the file system, the hard link points to the backup when I'm done editing, and that's confusing and awful. How can I either eliminate these backup files, or have them go somewhere other than the same directory?

like image 805
jfm3 Avatar asked Sep 30 '08 06:09

jfm3


People also ask

Why does Emacs create an additional file ending with a ~?

When you save a file in Emacs, it automatically creates a backup file (what the file looked like before editing) with the “~” prefix.

Does emacs auto save?

Emacs periodically saves all files that you are visiting; this is called auto-saving. Auto-saving prevents you from losing more than a limited amount of work if the system crashes. By default, auto-saves happen every 300 keystrokes, or after around 30 seconds of idle time.


1 Answers

If you've ever been saved by an Emacs backup file, you probably want more of them, not less of them. It is annoying that they go in the same directory as the file you're editing, but that is easy to change. You can make all backup files go into a directory by putting something like the following in your .emacs.

(setq backup-directory-alist `(("." . "~/.saves"))) 

There are a number of arcane details associated with how Emacs might create your backup files. Should it rename the original and write out the edited buffer? What if the original is linked? In general, the safest but slowest bet is to always make backups by copying.

(setq backup-by-copying t) 

If that's too slow for some reason you might also have a look at backup-by-copying-when-linked.

Since your backups are all in their own place now, you might want more of them, rather than less of them. Have a look at the Emacs documentation for these variables (with C-h v).

(setq delete-old-versions t   kept-new-versions 6   kept-old-versions 2   version-control t) 

Finally, if you absolutely must have no backup files:

(setq make-backup-files nil) 

It makes me sick to think of it though.

like image 198
jfm3 Avatar answered Sep 21 '22 10:09

jfm3