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

后端 未结 6 805
再見小時候
再見小時候 2020-12-28 13:57

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, thes

6条回答
  •  盖世英雄少女心
    2020-12-28 14:07

    I have managed to get the undo history working by using the information provided here: http://emacs.stackexchange.com/q/3725/2287

    Instead of patching the original file desktop.el.gz I created an advice that temporarily overrides (buffer-local-variables) then I use it together with the function that gathers information about the buffer.

    (defun +append-buffer-undo-list-to-buffer-local-variables-advice (orig-fn &rest args)
      "Override `buffer-local-variables' and call ORIG-FN with ARGS.
    There is a bug in Emacs where the `buffer-undo-list' data is
    missing from the output of `buffer-local-variables'. This
    advice temporarily overrides the function and appends the
    missing data."
      (let ((orig-buffer-local-variables-fn (symbol-function 'buffer-local-variables)))
        (cl-letf (((symbol-function 'buffer-local-variables)
                   #'(lambda () (append (funcall orig-buffer-local-variables-fn)
                                   `(,(cons 'buffer-undo-list buffer-undo-list))))))
          (apply orig-fn args))))
    
    (advice-add #'desktop-buffer-info :around #'+append-buffer-undo-list-to-buffer-local-variables-advice)
    (push 'buffer-undo-list desktop-locals-to-save)
    (desktop-save-mode 1)
    

    I hope this helps someone else.

提交回复
热议问题