I love emacs, but something has been nagging me. I can't seem to get emacs to store local backups of files when I am editing them via tramp.
Currently, when I edit a local file a set of old versions is stored in the /tmp/myusername/emacs_backup folder. However, when I am FTPing via tramp, old versions aren't stored there (I assume it is trying to store them remotely?).
Here are my .emacs settings:
(defvar user-temporary-file-directory
(concat "/tmp/" user-login-name "/emacs_backup/"))
(make-directory user-temporary-file-directory t)
(setq make-backup-files t)
(setq backup-by-copying t)
(setq version-control t)
(setq delete-old-versions t)
(setq kept-new-versions 10)
(setq backup-directory-alist `(("." . ,user-tempor开发者_Python百科ary-file-directory)))
(setq tramp-backup-directory-alist backup-directory-alist)
(setq tramp-auto-save-directory user-temporary-file-directory)
(setq auto-save-list-file-prefix
(concat user-temporary-file-directory ".auto-saves-"))
(setq auto-save-file-name-transforms
`((".*" ,user-temporary-file-directory t)))
I don't care if tramp su editing is also stored in the tmp folder - the more the merrier in my opinion. Any help is greatly appreciated!
The documentation for tramp-backup-directory-alist
says
(setq tramp-backup-directory-alist backup-directory-alist)
gives the same backup policy for Tramp files on their hosts like the policy for local files.
Which I would interpret as backing up tramp files on the remote machine ("their host"). Looking at the implementation in tramp.el
this is also the default implementation (if tramp-backup-directory-alist
isn't set, then backup-directory-alist
is).
Tramp assumes that a backup of a remote file should always be remote too, and explicitly prepends the method/user/host bits before doing the backup. If you want to change the behavior I think you'll have to advise tramp-handle-find-backup-file-name
to adjust the file name (so it's a valid local one) and to coordinate with an entry in backup-directory-alist
.
FWIW: Putting backup in the temporary file directory isn't going to help much in the long run. "Temporary" kind of defeats the purpose of backups.
I was also trying to store backups locally. I submitted a bug because I thought tramp-backup-directory-alist
was broken. After talking to Michael Albinus, I found out that I misunderstood tramp-backup-directory-alist
, which is a way to store remote backups of remote files, and that I should instead do:
(add-to-list 'backup-directory-alist
(cons tramp-file-name-regexp "/my/local/backup/"))
I was able to find a workaround (I tried setting it up via tramp-backup-directory-alist - but apparently there is a with tramp's ability to locally save remote buffers) . Rather than using the built-in backup, I found the elisp script called: backup-each-save.el written by Benjamin Rutt.
Redefining trump-handle-find-backup-file-name
works for me. It gets rid of the behavior that wants to save the backups on the remote server.
(defun tramp-handle-find-backup-file-name (filename)
"Like `find-backup-file-name' for Tramp files."
(with-parsed-tramp-file-name filename nil
(tramp-run-real-handler 'find-backup-file-name (list filename))))
精彩评论