Domanda

I use emacsclient to edit temp files in /tmp a lot and would like to create backup copies of my files automatically like we do with other files. I'm sure there is a way to do it - but how? :)

(I searched the Emacs manual, emacswiki and SO but couldn't find anything useful)

È stato utile?

Soluzione

Look at the normal-backup-enable-predicate function, which is the default value for the backup-enable-predicate variable.

As the sole purpose of the default function is to inhibit backups for files in various temporary directories, you may just want to set a replacement which returns t unconditionally.

(setq backup-enable-predicate (lambda (name) t))

The usage in files.el suggests to me that you could also just set this variable to nil. That's not stated in the documentation, so it might not be reliable, but the variable isn't referenced by any other library in Emacs, so it's probably fine (but I'd still recommend using the lambda, because it's more obvious what that's doing).

See also C-hig (elisp) Making Backups RET

n.b. I'm not actually familiar with small-temporary-file-directory (see the docstring for that variable), but the temporary-file-directory value would typically be /tmp/, so those two cases are usually the same.

If you did want to retain the default behaviour for some temporary directories but not others, you should define a modified copy of the original function: (defun my-backup-enable-predicate ...) and then (setq backup-enable-predicate 'my-backup-enable-predicate)

Altri suggerimenti

Stick this in yer .emacs file:

;; create an invisible backup directory so our directories 
;; look a bit cleaner
;; thanks to #emacs in irc.freenode.org, Ryan Barrett of snarfed.org
;; and freethegnu.wordpress.com
 (defun make-backup-file-name (filename)
 (defvar backups-dir "/tmp/")
 (make-directory backups-dir t)
 (expand-file-name
 (concat backups-dir (file-name-nondirectory filename) "~")
 (file-name-directory filename)))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top