undo-tree不会自动加载历史记录

时间:2016-07-18 05:07:19

标签: emacs undo

我试图在emacs中创建持久的撤消历史记录。

我有(setq undo-tree-auto-save history t)。保存文件时,确实保存了历史记录。但是当我打开文件时,直到我使用undo。

才会加载撤消历史记录

因此,如果我打开一个文件并进行一些更改,然后运行M-x undo-tree-visualize,之前的撤消树已经消失,只有最近的更改。但如果我先运行M-x undo-tree-visualize,那么我就能看到旧的undo树。或者,如果我在进行任何更改之前只使用撤消,则会加载旧的撤消历史记录并撤消按预期工作。

修改:我的配置如下所示:https://gitlab.com/snippets/22693

Edit2:最小的配置文件仍会出现此问题:

;;; init.el --- user init file      -*- no-byte-compile: t -*-
(load-file "~/.emacs.d/undo-tree.el")
(global-undo-tree-mode 1)
(setq undo-tree-auto-save-history t)

5 个答案:

答案 0 :(得分:1)

为什么没有人注意到这一点?撤消树中存在一个错误。

undo-list-transfer-to-tree命令无法将undo-tree-canary附加到buffer-undo-list,导致丢弃buffer-undo-tree的内容。

我还在调查,看看能否找到解决方案。只需将“undo-tree-canary”附加到buffer-undo-list,导致它丢弃到buffer-undo-list中的内容

编辑:解决方案确实是将canary放在buffer-undo-list的末尾

  (when (not (eq (last buffer-undo-list) 'undo-tree-canary))
    (setq buffer-undo-list (append buffer-undo-list '(nil undo-tree-canary))))

答案 1 :(得分:1)

启用undo-tree-auto-save-history后,undo-tree-load-history-hook功能会从文件加载撤消历史记录,该功能会添加到find-file-hook。因此,当您打开启用了undo-tree-mode的文件时,将自动加载撤消历史记录。

@djangoliv是对的:这只有在启用global-undo-tree-mode时才有效,因为在undo-tree-mode被调用之前需要启用find-file-hook。如果undo-tree-mode次模式函数检测到自上次撤消历史记录保存后缓冲区未被修改,则该global-undo-tree-mode次模式函数可能会尝试加载历史记录。但目前,它并没有。

但是,您的配置会启用global-undo-tree-mode,因此这不是问题所在。

启用table.row后,历史记录加载对我来说很合适。因此,除非您提供一个完整的MWE来重现您的问题 - 即从" emacs -Q"开始的逐步说明。并且包括Emacs和撤消树版本号 - 你不太可能在这里获得更多帮助。 (另请注意,stackexchange不是错误跟踪器。应通过电子邮件将错误报告发送到程序包顶部列出的地址。)

答案 2 :(得分:0)

您是否修改了加载插件的订单以及通过init.el或.emacs自动打开的文件?这对我有用。邪恶需要撤消树。因此,在加载Evil之前,所有与undo-tree有关的内容都应该触发。特别是如果你使用":e"而不是" find-file"用于加载文件。至少在我的系统上解决了这个问题。

答案 3 :(得分:0)

我只是想说明我遇到类似的事情。

如果我emacs file-x来自终端,我file-x之前无法获得undo-tree-load-history的早期撤消树历史记录。但是,当我打开emacs和然后 :edit file-x时,历史记录加载得很好。

我使用spacemacs 0.105.19emacs-24.5.1

我的.spacemacshttps://pastebin.com/VNWtB0F1

答案 4 :(得分:0)

此行为的原因是,即使启用了undo-tree-auto-save-history,当您启动emacs并在缓冲区中打开文件时,应按原样调用undo-tree-load-historybuffer-undo-list才被设置到nil。如果您在调用撤消树的任何功能之前进行了编辑,则buffer-undo-list的值将不以undo-tree-canary结尾。

undo-list-transfer-to-tree看到buffer-undo-list不以undo-tree-canary结尾时,它将丢弃当前的buffer-undo-tree并构造一个值为buffer-undo-list的新值,该值只有撤消初始编辑的历史记录。因此,先前由buffer-undo-tree构建的undo-tree-load-history将被删除,并且只剩下一次撤消历史记录,您将得到最少的新鲜buffer-undo-tree

因此,为了防止这种情况的发生,我建议通过建议buffer-undo-list调用undo-tree-canary并将undo-tree-load-history-hook设置为{ {1}},它也被称为打开文件,作为undo-tree-load-history的一部分。

也就是说,我将以下代码行添加到了我的初始化文件中:

undo-tree-auto-save-history