Introduction
Disabling automatic backups in Emacs

Disabling automatic backups in Emacs

Emacs, by default, creates backups of the files you're editing. This is done the first time you save the file (in the current session), or by the auto-save feature in emacs, which is also enabled by default. If you're editing a file named test.txt and auto-save is triggered or you manually save it with C-x C-s, then emacs will create a new file called test.txt~ (original file name appended with a tilde). The contents of that file will be whatever was in your original file prior to any editing.

These two features (automatic backups and auto-save) are supposed to protect your content in case you accidentally killed emacs before saving, or if your system crashed, for example. However, this will also litter your directory with all of these backups, especially if you have a large number of files and you do a lot of editing.

To prevent this from happening, open your emacs config file, ~/.emacs, and add the following two lines:

(setq backup-inhibited t)
(setq auto-save-default nil)

The config file is written in Emacs Lisp, a flavor of Lisp used to configure and customize things in Emacs. The first line assigns a value of t (true) to the symbol/variable named backup-inhibited. This is what tells emacs to stop creating backup files. The second line, similar to the first, will give the variable auto-save-default a value of nil, effectively telling emacs to disable the auto-save feature.

For the changes to take effect, you can either exit and re-run emacs, or evaluate the lines we just added. To do the latter, mark the two lines by placing the cursor at the opening parenthesis of the first line, hit C-SPC, move the cursor past the closing parenthesis of the second line, then Esc-x eval-region, and hit enter. The changes should take effect immediately.

Check out Robert Chassel's Emacs Lisp - An Introduction or Learning GNU Emacs.

Author

binshdev

View Comments
Previous Post

DNS queries with drill

Subscribe to binsh.dev

Subscribe to our newsletter and receive access to exclusive posts and content updates. We don't spam and your email won't be shared with third-parties.

Thanks for subscribing!

Check your inbox to confirm your subscription.

Please enter a valid email address!