设置 Emacs TRAMP 存储本地备份

发布于 2024-09-26 21:04:48 字数 976 浏览 4 评论 0原文

我喜欢 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

半窗疏影 2024-10-03 21:04:48

tramp-backup-directory-alist 的文档说

(setq Tramp-backup-directory-alist backup-directory-alist)

为主机上的 TRAMP 文件提供与本地文件策略相同的备份策略。

我将其解释为备份远程计算机(“他们的主机”)上的临时文件。查看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 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.

白昼 2024-10-03 21:04:48

我还尝试在本地存储备份。我提交了一个 bug 因为我认为 tramp-backup- Directory-alist 已损坏。在与 Michael Albinus 交谈后,我发现我误解了 tramp-backup-directory-alist,这是一种存储远程文件的远程备份的方式,我应该这样做:

(add-to-list 'backup-directory-alist
             (cons tramp-file-name-regexp "/my/local/backup/"))

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/"))
一生独一 2024-10-03 21:04:48

我找到了一个解决方法(我尝试通过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.

眼泪也成诗 2024-10-03 21:04:48

重新定义 trump-handle-find-backup-file-name 对我有用。它摆脱了想要在远程服务器上保存备份的行为。

(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))))

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))))
与风相奔跑 2024-10-03 21:04:48

Tl;dr:我有以下设置,TRAMP 将远程文件备份到我的本地目录。

(setq backup-directory-alist '(("." . "~/.emacs.d/tmp")))
(setq tramp-backup-directory-alist nil)

说明:

根据 TRAMP 2.6.1.5 的实现,

(let ((backup-directory-alist
   (if tramp-backup-directory-alist
       (mapcar
    (lambda (x)
      (cons
       (car x)
       (if (and (stringp (cdr x))
           (file-name-absolute-p (cdr x))
           (not (tramp-tramp-file-p (cdr x))))
          (tramp-make-tramp-file-name v (cdr x))
         (cdr x))))
    tramp-backup-directory-alist)
     backup-directory-alist))
  result)
  ...
)

这里的逻辑是

  • if tramp-backup-directory-alist is set, then ranp 尝试附加 trapmp 文件前缀,即 host /user/...,到每个备份目录,如果该目录满足三个条件:

    1. 是一个字符串,
    2. 是绝对路径,并且
    3. 不是流浪者之路。
  • 否则,请使用 backup-directory-alist 而不进行修改。

Tl;dr: I have the following settings, Tramp backups remote file to my local directory.

(setq backup-directory-alist '(("." . "~/.emacs.d/tmp")))
(setq tramp-backup-directory-alist nil)

Explanation:

According to the implementation of Tramp 2.6.1.5,

(let ((backup-directory-alist
   (if tramp-backup-directory-alist
       (mapcar
    (lambda (x)
      (cons
       (car x)
       (if (and (stringp (cdr x))
           (file-name-absolute-p (cdr x))
           (not (tramp-tramp-file-p (cdr x))))
          (tramp-make-tramp-file-name v (cdr x))
         (cdr x))))
    tramp-backup-directory-alist)
     backup-directory-alist))
  result)
  ...
)

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:

    1. is a string,
    2. is an absolute path, and
    3. not a tramp path.
  • Otherwise, use backup-directory-alist without modification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文