设置 Emacs TRAMP 存储本地备份
我喜欢 emacs,但有些事情一直困扰着我。当我通过 trapmp 编辑文件时,我似乎无法让 emacs 存储文件的本地备份。
目前,当我编辑本地文件时,一组旧版本存储在 /tmp/myusername/emacs_backup 文件夹中。但是,当我通过 trapmp 进行 FTPing 时,旧版本不会存储在那里(我假设它正在尝试远程存储它们?)。
以下是我的 .emacs 设置:
(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-temporary-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)))
我不关心 tmp su 编辑是否也存储在 tmp 文件夹中 - 我认为越多越好。非常感谢任何帮助!
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-temporary-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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
tramp-backup-directory-alist
的文档说我将其解释为备份远程计算机(“他们的主机”)上的临时文件。查看tramp.el中的实现,这也是默认实现(如果未设置tramp-backup-directory-alist,则backup-directory- alist 是)。
TRAMP 假定远程文件的备份也应该始终是远程的,并在执行备份之前显式地预先添加方法/用户/主机位。如果您想更改行为,我认为您必须建议
tramp-handle-find-backup-file-name
调整文件名(因此它是有效的本地文件名)并与backup-directory-alist
中的条目。FWIW:从长远来看,将备份放在临时文件目录中不会有太大帮助。 “临时”有点违背了备份的目的。
The documentation for
tramp-backup-directory-alist
saysWhich 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 (iftramp-backup-directory-alist
isn't set, thenbackup-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 inbackup-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.
我还尝试在本地存储备份。我提交了一个 bug 因为我认为
tramp-backup- Directory-alist
已损坏。在与 Michael Albinus 交谈后,我发现我误解了tramp-backup-directory-alist
,这是一种存储远程文件的远程备份的方式,我应该这样做: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 misunderstoodtramp-backup-directory-alist
, which is a way to store remote backups of remote files, and that I should instead do:我找到了一个解决方法(我尝试通过tramp-backup-directory-alist进行设置 - 但显然有一个tramp能够在本地保存远程缓冲区)。我没有使用内置备份,而是找到了名为的 elisp 脚本: backup-each-save.el 由 Benjamin Rutt 编写。
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.
重新定义
trump-handle-find-backup-file-name
对我有用。它摆脱了想要在远程服务器上保存备份的行为。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.Tl;dr:我有以下设置,TRAMP 将远程文件备份到我的本地目录。
说明:
根据 TRAMP 2.6.1.5 的实现,
这里的逻辑是
if
tramp-backup-directory-alist
is set, then ranp 尝试附加 trapmp 文件前缀,即 host /user/...,到每个备份目录,如果该目录满足三个条件:否则,请使用
backup-directory-alist
而不进行修改。Tl;dr: I have the following settings, Tramp backups remote file to my local directory.
Explanation:
According to the implementation of Tramp 2.6.1.5,
The logic here reads
if
tramp-backup-directory-alist
is set, then tramp tries to append the tramp file prefix, i.e., host/user/..., to each of the backup directory if the directory satisfies three conditions:Otherwise, use
backup-directory-alist
without modification.