有没有办法让EMACS在会话之间保存撤消历史记录?
我知道savehist lib,saveplace lib,桌面库和windows lib,这些都提供了一些会话控制,但似乎都没有保存撤消历史记录.
Tob*_*itt 19
从版本0.4开始,undo-tree支持在"开箱即用"的会话之间持久存储撤消树数据.(请注意,在最新版本中有与此功能相关的重要错误修复;撰写本文时的最新版本为0.6.3.)
只需启用undo-tree-auto-save-history自定义选项,即可在撤消树缓冲区中自动保存和加载撤消历史记录.或者使用undo-tree-save/load-history命令手动保存和加载撤消历史记录.
你需要至少Emacs版本24.3才能可靠地工作,但是最近有足够的Emacs可以很好地工作.(在撰写本文时,这意味着从bzr获取Emacs的开发版本,并从源代码编译它.但Emacs 24.3应该很快就会发布.)
Tre*_*son 12
这里有一些我写的代码似乎可以解决这个问题.它不是防弹的,因为它不处理Emacs所做的所有文件处理复杂性(例如,覆盖自动保存文件的放置位置,符号链接处理等).但是,它似乎为我操作的一些简单文本文件做了诀窍.
(defun save-undo-filename (orig-name)
"given a filename return the file name in which to save the undo list"
(concat (file-name-directory orig-name)
"."
(file-name-nondirectory orig-name)
".undo"))
(defun save-undo-list ()
"Save the undo list to a file"
(save-excursion
(ignore-errors
(let ((undo-to-save `(setq buffer-undo-list ',buffer-undo-list))
(undo-file-name (save-undo-filename (buffer-file-name))))
(find-file undo-file-name)
(erase-buffer)
(let (print-level
print-length)
(print undo-to-save (current-buffer)))
(let ((write-file-hooks (remove 'save-undo-list write-file-hooks)))
(save-buffer))
(kill-buffer))))
nil)
(defvar handling-undo-saving nil)
(defun load-undo-list ()
"load the undo list if appropriate"
(ignore-errors
(when (and
(not handling-undo-saving)
(null buffer-undo-list)
(file-exists-p (save-undo-filename (buffer-file-name))))
(let* ((handling-undo-saving t)
(undo-buffer-to-eval (find-file-noselect (save-undo-filename (buffer-file-name)))))
(eval (read undo-buffer-to-eval))))))
(add-hook 'write-file-hooks 'save-undo-list)
(add-hook 'find-file-hook 'load-undo-list)
Run Code Online (Sandbox Code Playgroud)
mea*_*ain 11
将以下内容添加到.emacs文件中:
(global-undo-tree-mode)
(setq undo-tree-auto-save-history t)
(setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))
Run Code Online (Sandbox Code Playgroud)
(global-undo-tree-mode) 启用撤消树.
(setq undo-tree-auto-save-history t) 启用撤消历史记录的自动保存.
(setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo"))) 这样你的项目就不会被破坏历史保存文件所困扰.
desktop-save-mode默认不保存buffer-undo-list.你只需要告诉他!
(add-to-list 'desktop-locals-to-save 'buffer-undo-list)
Run Code Online (Sandbox Code Playgroud)