diff --git a/core/core-editor.el b/core/core-editor.el index 23bc9266d..2a3bc6548 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -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)) -(use-package! undo-tree - ;; Branching & persistent undo +(use-package! undo-fu :after-call doom-switch-buffer-hook after-find-file :config - (setq undo-tree-visualizer-diff t - undo-tree-auto-save-history t - undo-tree-enable-undo-in-region t - ;; Increase undo-limits by a factor of ten to avoid emacs prematurely - ;; 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/")))) + ;; Store more undo history to prevent loss of data + (setq undo-limit 400000 + undo-strong-limit 3000000 + undo-outer-limit 3000000) - ;; Compress undo-tree history files with zstd, if available. File size isn't - ;; the (only) concern here: the file IO barrier is slow for Emacs to cross; - ;; 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 - ;; SSDs). Whether or not that's true in practice, we still enjoy zstd's ~80% - ;; file savings (these files add up over time and zstd is so incredibly fast). + (global-set-key [remap undo] #'undo-fu-only-undo) + (global-set-key [remap redo] #'undo-fu-only-redo) + + (with-eval-after-load 'undo-tree + (global-set-key [remap undo-tree-undo] #'undo-fu-only-undo) + (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") - (defadvice! doom--undo-tree-make-history-save-file-name-a (file) - :filter-return #'undo-tree-make-history-save-file-name - (concat file ".zst"))) + (defadvice! doom--undo-fu-session-use-zstd-a (filename) + :filter-return #'undo-fu-session--make-file-name + (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 - ;; 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)) + (global-undo-fu-session-mode +1)) (use-package! ws-butler diff --git a/core/packages.el b/core/packages.el index 65ab0d342..ade4e95ae 100644 --- a/core/packages.el +++ b/core/packages.el @@ -27,7 +27,8 @@ ;; on a potato. :recipe (:host github :repo "hlissner/emacs-so-long") :pin "ed666b0716") -(package! undo-tree :pin "5b6df03781") +(package! undo-fu :pin "8c461a00a0") +(package! undo-fu-session :pin "35d4cf3771") (package! ws-butler ;; Use my fork of ws-butler, which has a few choice improvements and ;; optimizations (the original has been abandoned). diff --git a/docs/faq.org b/docs/faq.org index 88ad9ae30..898bd3274 100644 --- a/docs/faq.org +++ b/docs/faq.org @@ -968,9 +968,6 @@ known fix for this. To work around it, you must either: ** Doom crashes when... 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 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 diff --git a/modules/editor/objed/config.el b/modules/editor/objed/config.el index adfabed32..f58c55f78 100644 --- a/modules/editor/objed/config.el +++ b/modules/editor/objed/config.el @@ -4,9 +4,7 @@ :after-call pre-command-hook :config ;; Prevent undo actions from exiting edit state - (add-to-list 'objed-keeper-commands 'undo-tree-undo) - (add-to-list 'objed-keeper-commands 'undo-tree-redo) - (add-to-list 'objed-keeper-commands 'undo-tree-visualize) + (pushnew! objed-keeper-commands 'undo-fu-only-undo 'undo-fu-only-redo) (defvar +objed--extra-face-remaps nil) diff --git a/modules/ui/ophints/config.el b/modules/ui/ophints/config.el index c94aab8c3..2db9a2850 100644 --- a/modules/ui/ophints/config.el +++ b/modules/ui/ophints/config.el @@ -31,7 +31,6 @@ :unless (featurep! :editor evil) :after-call pre-command-hook :config - (volatile-highlights-mode) - (after! undo-tree - (vhl/define-extension 'undo-tree 'undo-tree-yank 'undo-tree-move) - (vhl/install-extension 'undo-tree))) + (after! undo-fu + (vhl/define-extension 'undo-fu 'undo-fu-only-undo 'undo-fu-only-redo) + (vhl/install-extension 'undo-fu)))