Hide emacs’ backups inside an hidden folder

browsing a working directory full of files and their backups, cli or gui wise, was turning into an annoying vision.

So, finally i decided to make those backups go elsewhere!

With the help of the friendly irc ppl (#emacs in irc.freenode.org) and building on Ryan Barrett (from /snarfed.org) i came into this:

;; create an invisible backup directory and make the backups also invisable
(defun make-backup-file-name (filename)
(defvar backups-dir "./.backups/")
(make-directory backups-dir t)
(concat backups-dir "." (file-name-nondirectory filename) "~")
(file-name-directory filename)))

Put those lines in .emacs (on your home folder ‘~/’) and on the next time you start your emacs the backups will be placed inside a hidden folder (.backups) on the directory were your file is visited (opened) and these backups will also be hidden (.namefile~). So, if you are visiting /some/dir/somefile.el it will create /some/dir/.backups/.somefile.el~
simple isn’t it?

also i’ve learned to evaluate a function inside emacs: M-x eval-defun RET
(place the cursor on the line of the function to be evaluated)

this M-x toggle-debug-on-error RET will make emacs show up a backtrace if an error comes up


2 thoughts on “Hide emacs’ backups inside an hidden folder

  1. Thank you! I’ve looking for this for a while but was too lazy to google until now. I did change the backup directory to .emacs.backups to my $HOME directory though

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s