From 646cba3f68709c2df214d3a6ccefcc67b47cbd00 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 13 May 2019 14:31:49 -0400 Subject: [PATCH] Bring back undo history compression But only if zstd is available. Also strips text properties from the undo list. This often provides a 30-50% size benefit, with a negligible performance impact. --- core/core-editor.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/core-editor.el b/core/core-editor.el index a70163462..215e9c3d0 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -263,6 +263,20 @@ savehist file." undo-tree-enable-undo-in-region nil undo-tree-history-directory-alist `(("." . ,(concat doom-cache-dir "undo-tree-hist/")))) + + (when (executable-find "zstd") + (defun doom*undo-tree-make-history-save-file-name (file) + (concat file ".zst")) + (advice-add #'undo-tree-make-history-save-file-name :filter-return + #'doom*undo-tree-make-history-save-file-name)) + + (defun doom*strip-text-properties-from-undo-history (&rest _) + (dolist (item buffer-undo-list) + (and (consp item) + (stringp (car item)) + (setcar item (substring-no-properties (car item)))))) + (advice-add #'undo-list-transfer-to-tree :before #'doom*strip-text-properties-from-undo-history) + (global-undo-tree-mode +1))