Refactor undo-tree advice

This commit is contained in:
Henrik Lissner 2019-03-28 01:53:15 -04:00
parent 37525bb1bd
commit b3d931d7ce
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 7 additions and 19 deletions

View file

@ -233,32 +233,19 @@ savehist file."
`(("." . ,(concat doom-cache-dir "undo-tree-hist/"))))
(global-undo-tree-mode +1)
(defun doom*shut-up-undo-tree (&rest _) (message ""))
(advice-add #'undo-tree-load-history :after #'doom*shut-up-undo-tree)
;; compress undo history with xz
(defun doom*undo-tree-make-history-save-file-name (file)
(cond ((executable-find "zstd") (concat file ".zst"))
((executable-find "gzip") (concat file ".gz"))
(file)))
(advice-add #'undo-tree-make-history-save-file-name :filter-return
#'doom*undo-tree-make-history-save-file-name)
(and (fset 'doom*undo-tree-make-history-save-file-name
(cond ((executable-find "zstd") (lambda (file) (concat file ".zst")))
((executable-find "gzip") (lambda (file) (concat file ".gz")))))
(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)
(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))
(advice-add #'undo-list-transfer-to-tree :before #'doom*strip-text-properties-from-undo-history))
(def-package! command-log-mode