From 261aa7c944b826338c14e002b00e7e57e5116201 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 3 Aug 2018 18:34:51 +0200 Subject: [PATCH] Compress/compact undo-tree history (and shut up) --- core/core-editor.el | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/core/core-editor.el b/core/core-editor.el index 0a35f5e36..f198f89ec 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -219,7 +219,31 @@ savehist file." undo-tree-enable-undo-in-region nil undo-tree-history-directory-alist `(("." . ,(concat doom-cache-dir "undo-tree-hist/")))) - (global-undo-tree-mode +1)) + (global-undo-tree-mode +1) + + ;; compress undo with xz + (advice-add #'undo-tree-make-history-save-file-name :filter-return + (cond ((executable-find "zstd") (lambda (file) (concat file ".zst"))) + ((executable-find "gzip") (lambda (file) (concat file ".gz"))))) + + (advice-add #'undo-tree-load-history :around #'doom*shut-up) + + (defun doom*strip-text-properties-from-undo-history (orig-fn &rest args) + (dolist (item buffer-undo-list) + (and (consp item) + (stringp (car item)) + (setcar item (substring-no-properties (car item))))) + (apply orig-fn args)) + (advice-add 'undo-list-transfer-to-tree :around #'doom*strip-text-properties-from-undo-history) + + (defun doom*compress-undo-tree-history (orig-fn &rest args) + (cl-letf* ((jka-compr-verbose nil) + (old-write-region (symbol-function #'write-region)) + ((symbol-function #'write-region) + (lambda (start end filename &optional append _visit &rest args) + (apply old-write-region start end filename append 0 args)))) + (apply orig-fn args))) + (advice-add #'undo-tree-save-history :around #'doom*compress-undo-tree-history)) ;;