Preventing Backup File Clutter in Emacs

Emacs creates backup file for each file by default. I’ll disable this behavior to prevent directories being cluttered.

The Problem with Backup Files

When editing files in Emacs, it automatically creates backup files (ending with ~) in the same directory as the original file. This causes several issues:

  1. Directory pollution with numerous *~ files
  2. Version control noise (need to add patterns to .gitignore)
  3. Visual clutter when viewing directories
  4. Unnecessary files in project workspace

For example, if you have init.el, Emacs creates init.el~ in the same directory.

Solution Design

We have two main approaches:

  1. Disable backup files completely
  2. Centralize backup files in a specific directory

For most users, disabling backups is the simplest solution, as Emacs’ auto-save feature and version control provide sufficient safety nets.

Implementation

Here’s the configuration to disable backup files:

(leaf backup
  :custom
  (make-backup-files . nil)
  (auto-save-default . nil))

This configuration:

  • Disables creation of backup files (*~)
  • Disables auto-save files (#*#)

How It Works

make-backup-files

  • When set to nil, prevents creation of backup files
  • Default is t, which creates backups
  • Affects all file editing operations

auto-save-default

  • Controls auto-save file creation
  • When nil, prevents #file# style auto-save files
  • Default is t

Preventing Backup File Clutter in Emacs

[previous sections remain the same…]

Conclusion

Proper backup file management is essential for maintaining a clean and efficient Emacs workflow.

The state of init.el at the conclusion of this article can be found here: https://github.com/Rindrics/.emacs.d/blob/c011776900c95484bd35122ca2bcea55c60205f7/init.el

References

  1. GNU Emacs Manual: Backup Files
  2. EmacsWiki: Backup Files
  3. Stack Overflow: How do I control how Emacs makes backup files?
  4. Emacs: Auto-Save & Backup Configuration Tutorial

comments powered by Disqus