Possibly restore undo persistence

This commit is contained in:
Henrik Lissner 2017-07-05 18:18:24 +02:00
parent 1d961563c0
commit 8edba65504
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -205,12 +205,32 @@ fundamental-mode) for performance sake."
(def-package! undo-tree (def-package! undo-tree
:demand t :demand t
:config :config
(global-undo-tree-mode +1)
;; persistent undo history is known to cause undo history corruption, which ;; persistent undo history is known to cause undo history corruption, which
;; can be very destructive! So disable it! ;; can be very destructive! So disable it!
(setq undo-tree-auto-save-history nil (setq undo-tree-auto-save-history t
undo-tree-history-directory-alist undo-tree-history-directory-alist
(list (cons "." (concat doom-cache-dir "undo-tree-hist/")))) (list (cons "." (concat doom-cache-dir "undo-tree-hist/"))))
(defun doom|save-undo-history ()
(when (and (bound-and-true-p undo-tree-mode)
buffer-file-name
(file-writable-p buffer-file-name)
(not (eq buffer-undo-list t))
(not revert-buffer-in-progress-p))
(quiet!
(undo-tree-save-history nil t))))
(defun doom|save-all-undo-history ()
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(doom|save-undo-history))))
(remove-hook 'write-file-functions #'undo-tree-save-history-hook)
(add-hook 'kill-emacs-hook #'doom|save-all-undo-history)
(add-hook 'kill-buffer-hook #'doom|save-undo-history)
(defun doom*silence-undo-tree-load (orig-fn &rest args) (defun doom*silence-undo-tree-load (orig-fn &rest args)
"Silence undo-tree load errors." "Silence undo-tree load errors."
(quiet! (apply orig-fn args))) (quiet! (apply orig-fn args)))