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

Add the following to your .emacs file :

(global-undo-tree-mode)
(setq undo-tree-auto-save-history t)
(setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))

Explanation

  • (global-undo-tree-mode) enables undo tree.

  • (setq undo-tree-auto-save-history t) enables auto save of undo history.

  • (setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo"))) so that your project does not get littered with undo-history savefiles.


From version 0.4 onwards, undo-tree supports persistent storage of undo-tree data between sessions "out of the box". (Note that there are significant bug-fixes related to this feature in more recent versions; the latest version at the time of writing is 0.6.3.)

Simply enable the undo-tree-auto-save-history customization option to automatically save and load undo history in undo-tree buffers. Or use the undo-tree-save/load-history commands to save and load undo history manually.

You need at least Emacs version 24.3 for this to work reliably, but with a recent enough Emacs it works very well.

Tags:

Emacs