Replace undo-tree with undo-fu + undo-fu-session

Despite the recent patches to fix undo history corruption, its history
would still get unpredictably truncated due to non-linear memory
expansion.

Relevant to #2339
This commit is contained in:
Henrik Lissner 2020-04-07 20:15:32 -04:00
parent 6bc0fcf714
commit 8ab0cd66a7
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
5 changed files with 33 additions and 49 deletions

View file

@ -543,49 +543,38 @@ files, so we replace calls to `pp' with the much faster `prin1'."
(setq so-long-predicate #'doom-buffer-has-long-lines-p)) (setq so-long-predicate #'doom-buffer-has-long-lines-p))
(use-package! undo-tree (use-package! undo-fu
;; Branching & persistent undo
:after-call doom-switch-buffer-hook after-find-file :after-call doom-switch-buffer-hook after-find-file
:config :config
(setq undo-tree-visualizer-diff t ;; Store more undo history to prevent loss of data
undo-tree-auto-save-history t (setq undo-limit 400000
undo-tree-enable-undo-in-region t undo-strong-limit 3000000
;; Increase undo-limits by a factor of ten to avoid emacs prematurely undo-outer-limit 3000000)
;; truncating the undo history and corrupting the tree. See
;; https://github.com/syl20bnr/spacemacs/issues/12110
undo-limit 800000
undo-strong-limit 12000000
undo-outer-limit 120000000
undo-tree-history-directory-alist
`(("." . ,(concat doom-cache-dir "undo-tree-hist/"))))
;; Compress undo-tree history files with zstd, if available. File size isn't (global-set-key [remap undo] #'undo-fu-only-undo)
;; the (only) concern here: the file IO barrier is slow for Emacs to cross; (global-set-key [remap redo] #'undo-fu-only-redo)
;; reading a tiny file and piping it in-memory through zstd is *slightly*
;; faster than Emacs reading the entire undo-tree file from the get go (on (with-eval-after-load 'undo-tree
;; SSDs). Whether or not that's true in practice, we still enjoy zstd's ~80% (global-set-key [remap undo-tree-undo] #'undo-fu-only-undo)
;; file savings (these files add up over time and zstd is so incredibly fast). (global-set-key [remap undo-tree-redo] #'undo-fu-only-redo)
(global-undo-tree-mode -1)))
(use-package! undo-fu-session
:after undo-fu
:init
(setq undo-fu-session-directory (concat doom-cache-dir "undo-fu-session/")
undo-fu-session-incompatible-files '("/COMMIT_EDITMSG\\'" "/git-rebase-todo\\'"))
:config
;; HACK Use the faster zstd to compress undo files instead of gzip
(when (executable-find "zstd") (when (executable-find "zstd")
(defadvice! doom--undo-tree-make-history-save-file-name-a (file) (defadvice! doom--undo-fu-session-use-zstd-a (filename)
:filter-return #'undo-tree-make-history-save-file-name :filter-return #'undo-fu-session--make-file-name
(concat file ".zst"))) (if undo-fu-session-compression
(concat (file-name-sans-extension filename) ".zst")
filename)))
;; Strip text properties from undo-tree data to stave off bloat. File size (global-undo-fu-session-mode +1))
;; isn't the concern here; undo cache files bloat easily, which can cause
;; freezing, crashes, GC-induced stuttering or delays when opening files.
(defadvice! doom--undo-tree-strip-text-properties-a (&rest _)
:before #'undo-list-transfer-to-tree
(dolist (item buffer-undo-list)
(and (consp item)
(stringp (car item))
(setcar item (substring-no-properties (car item))))))
;; Undo-tree is too chatty about saving its history files. This doesn't
;; totally suppress it logging to *Messages*, it only stops it from appearing
;; in the echo-area.
(advice-add #'undo-tree-save-history :around #'doom-shut-up-a)
(global-undo-tree-mode +1))
(use-package! ws-butler (use-package! ws-butler

View file

@ -27,7 +27,8 @@
;; on a potato. ;; on a potato.
:recipe (:host github :repo "hlissner/emacs-so-long") :recipe (:host github :repo "hlissner/emacs-so-long")
:pin "ed666b0716") :pin "ed666b0716")
(package! undo-tree :pin "5b6df03781") (package! undo-fu :pin "8c461a00a0")
(package! undo-fu-session :pin "35d4cf3771")
(package! ws-butler (package! ws-butler
;; Use my fork of ws-butler, which has a few choice improvements and ;; Use my fork of ws-butler, which has a few choice improvements and
;; optimizations (the original has been abandoned). ;; optimizations (the original has been abandoned).

View file

@ -968,9 +968,6 @@ known fix for this. To work around it, you must either:
** Doom crashes when... ** Doom crashes when...
Here are a few common causes for random crashes: Here are a few common causes for random crashes:
+ You have enabled ~undo-tree-auto-save-history~. A bloated cache for a
particular file can cause a stack overflow. These caches are stored in
=~/.emacs.d/.local/cache/undo-tree-hist/=. Delete this folder to clear it.
+ On some systems (particularly MacOS), manipulating the fringes or window + On some systems (particularly MacOS), manipulating the fringes or window
margins can cause Emacs to crash. This is most prominent in the Doom Dashboard margins can cause Emacs to crash. This is most prominent in the Doom Dashboard
(which tries to center its contents), in org-mode buffers (which uses (which tries to center its contents), in org-mode buffers (which uses

View file

@ -4,9 +4,7 @@
:after-call pre-command-hook :after-call pre-command-hook
:config :config
;; Prevent undo actions from exiting edit state ;; Prevent undo actions from exiting edit state
(add-to-list 'objed-keeper-commands 'undo-tree-undo) (pushnew! objed-keeper-commands 'undo-fu-only-undo 'undo-fu-only-redo)
(add-to-list 'objed-keeper-commands 'undo-tree-redo)
(add-to-list 'objed-keeper-commands 'undo-tree-visualize)
(defvar +objed--extra-face-remaps nil) (defvar +objed--extra-face-remaps nil)

View file

@ -31,7 +31,6 @@
:unless (featurep! :editor evil) :unless (featurep! :editor evil)
:after-call pre-command-hook :after-call pre-command-hook
:config :config
(volatile-highlights-mode) (after! undo-fu
(after! undo-tree (vhl/define-extension 'undo-fu 'undo-fu-only-undo 'undo-fu-only-redo)
(vhl/define-extension 'undo-tree 'undo-tree-yank 'undo-tree-move) (vhl/install-extension 'undo-fu)))
(vhl/install-extension 'undo-tree)))