One thing that really bugs me about Emacs is the way it clutters up my directories with backup files (filenames ending in ~
) and autosave files (filenames starting with #
). Fortunately there's an easy way to move them elsewhere. Unfortunately the technique isn't consistent across Emacs versions. In GNU Emacs 21, you can set backup-directory-alist
and auto-save-file-name-transforms
. In XEmacs 21, you can set bkup-backup-directory-info
and auto-save-directory
. Here's what I do in GNU Emacs:
(defvar user-temporary-file-directory (concat temporary-file-directory user-login-name "/")) (make-directory user-temporary-file-directory t) (setq backup-by-copying t) (setq backup-directory-alist `(("." . ,user-temporary-file-directory) (,tramp-file-name-regexp nil))) (setq auto-save-list-file-prefix (concat user-temporary-file-directory ".auto-saves-")) (setq auto-save-file-name-transforms `((".*" ,user-temporary-file-directory t)))
Here's what I do in XEmacs:
(require 'auto-save) (require 'backup-dir) (defvar user-temporary-file-directory (concat (temp-directory) "/" (user-login-name))) (make-directory user-temporary-file-directory t) (setq backup-by-copying t) (setq auto-save-directory user-temporary-file-directory) (setq auto-save-list-file-prefix (concat user-temporary-file-directory ".auto-saves-")) (setq bkup-backup-directory-info `((t ,user-temporary-file-directory full-path)))
I'm much happier with Emacs temporary files being kept out of my way.
Labels: emacs
13 comments:
Subscribe to:
Post Comments (Atom)
Just what I wanted - many thanks
Thanks for your help, that worked in version gnu 22.2.1.
I've wanted to fix that forever, but I'm no emacs expert. Thanks for posting it!
Thanks a lot!
Before I lost my .emacs, I had a version which adds the current date/time to the filename.
Do u have any idea how I can do this?
Max
Max: sorry, I don't know how to add the date/time. I just let the OS record the date/time and use that.
Those backup files have saved my butt on more than one occasion and I don't find "rm *~" that much of a chore. Thanks fore exposing the settings, though!
Be advised that for Debian-based systems (including ubuntu), the default is to clean out /tmp on every boot; so storing your autosave backup files there might not be a good idea. (Autosave especially, as you normally need them exactly when you've rebooted unexpectedly!) So users of those systems may want to set user-temporary-file-directory to something more permanent, thus:
(defvar user-temporary-file-directory
"~/.emacs-backup")
Thanks! I was using the function "make-backup-file-name" for my backup, but for some unknow reasons this function doesn't work anymore on my new computer.
I am running emacs 23.1 on Windows, accessing files on a network (Linux) drive. This method seems to not work for files on the network drive (L:\), but works fine for files on the local harddrive (C:\) ??
Hi Anonymous — yes, there are all sorts of weird things that happen with network drives, unfortunately. It's not just Emacs; it's that network drive protocols don't always support the full set of file operations. I'm afraid I don't have any suggestions for you :(
Thank you, works great
Hey, thanks! That is what I'm looking for.
Thanks! That is what I'm looking for
Post a Comment