有没有办法让Emacs在会话之间保存您的撤消历史记录? [英] Is there any way to have Emacs save your undo history between sessions?

查看:84
本文介绍了有没有办法让Emacs在会话之间保存您的撤消历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有意识到savehist lib,saveplace lib,桌面lib和windows lib,这些都提供了一些会话控制,但没有一个可以保存撤消历史记录。

解决方案

似乎做的伎俩它不是防弹的,因为它不处理Emacs所做的所有文件处理复杂(例如覆盖放置自动保存文件的位置,符号链接处理等)。但是,它似乎是为我操纵的一些简单的文本文件做的伎俩。

 (defun save-undo-filename(orig-名称)
给定文件名返回保存撤销列表的文件名
(concat(file-name-directory orig-name)

file-name-nondirectory orig-name)
.undo))

(defun save-undo-list()
将撤销列表保存到文件
(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)
(擦除缓冲区)
(print-level
print-length)
(print undo-to-save(current-buffer)))
(let((write-file-hooks(remove'列表write-file-hooks)))
(save-buffer))
(kill-buffer))))
nil)

(defvar handling- undo-saving nil)

(defun load-undo-list()
如果适用,加载撤消列表
(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)


Is there any way to have EMACS save your undo history between sessions?

I'm aware of the savehist lib, the saveplace lib, the desktop lib, and the windows lib, these all provide some session control but none seem to save the undo history.

解决方案

Here's some code I wrote which seems to do the trick. It isn't bullet-proof, as in, it doesn't handle all the file handling intricacies that Emacs does (e.g. overriding where auto-save files are put, symlink handling, etc.). But, it seemed to do the trick for some simple text files I manipulated.

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

这篇关于有没有办法让Emacs在会话之间保存您的撤消历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆