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:
- Directory pollution with numerous
*~
files - Version control noise (need to add patterns to .gitignore)
- Visual clutter when viewing directories
- 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:
- Disable backup files completely
- 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
comments powered by Disqus