Add :emacs undo module
Moves undo-fu/undo-tree out of core and allows uses to choose one or the other. Relevant to #2339
This commit is contained in:
parent
187ba0f66f
commit
3e340ab415
7 changed files with 152 additions and 37 deletions
54
modules/emacs/undo/README.org
Normal file
54
modules/emacs/undo/README.org
Normal file
|
@ -0,0 +1,54 @@
|
|||
#+TITLE: emacs/undo
|
||||
#+DATE: April 13, 2020
|
||||
#+SINCE: v3.0.0
|
||||
#+STARTUP: inlineimages nofold
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#maintainers][Maintainers]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#plugins][Plugins]]
|
||||
- [[#hacks][Hacks]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#features][Features]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#troubleshooting][Troubleshooting]]
|
||||
|
||||
* Description
|
||||
This module augments Emacs' built-in undo system to be more intuitive.
|
||||
|
||||
** Maintainers
|
||||
This module has no dedicated maintainers.
|
||||
|
||||
** Module Flags
|
||||
+ =+tree= Uses ~undo-tree~ instead of ~undo-fu~, which is a little less stable,
|
||||
but offers branching undo history and a visualizer for navigating it.
|
||||
|
||||
** Plugins
|
||||
+ [[https://gitlab.com/ideasman42/emacs-undo-fu][undo-fu]]
|
||||
+ [[https://gitlab.com/ideasman42/emacs-undo-fu-session][undo-fu-session]]
|
||||
+ [[https://github.com/emacsmirror/undo-tree][undo-tree]] (=+tree=)
|
||||
|
||||
** Hacks
|
||||
+ Both undo-fu and undo-tree have been modified to use zstd to compress undo
|
||||
history if it is available.
|
||||
+ undo-tree only
|
||||
+ Text properties are stripped from undo history to shrink it.
|
||||
+ Undo-tree is too chatty about saving its history files. This has be
|
||||
"silenced". i.e. It's visible in \*Messages\*, but won't appear in your
|
||||
minibuffer.
|
||||
+ unfo-fu only
|
||||
+ Doom defines =undo-fu-mode= to make it easier to add hooks/mode-local
|
||||
keybinds.
|
||||
|
||||
* Prerequisites
|
||||
This module has no prereqisites.
|
||||
|
||||
* TODO Features
|
||||
# An in-depth list of features, how to use them, and their dependencies.
|
||||
|
||||
* TODO Configuration
|
||||
# How to configure this module, including common problems and how to address them.
|
||||
|
||||
* TODO Troubleshooting
|
||||
# Common issues and their solution, or places to look for help.
|
89
modules/emacs/undo/config.el
Normal file
89
modules/emacs/undo/config.el
Normal file
|
@ -0,0 +1,89 @@
|
|||
;;; emacs/undo/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(use-package! undo-fu
|
||||
:unless (featurep! +tree)
|
||||
:after-call doom-switch-buffer after-find-file
|
||||
:init
|
||||
(after! undo-tree
|
||||
(global-undo-tree-mode -1))
|
||||
:config
|
||||
;; Store more undo history to prevent loss of data
|
||||
(setq undo-limit 400000
|
||||
undo-strong-limit 3000000
|
||||
undo-outer-limit 3000000)
|
||||
|
||||
(define-minor-mode undo-fu-mode
|
||||
"Enables `undo-fu' for the current session."
|
||||
:keymap (let ((map (make-sparse-keymap)))
|
||||
(define-key map [remap undo] #'undo-fu-only-undo)
|
||||
(define-key map [remap redo] #'undo-fu-only-redo)
|
||||
map)
|
||||
:init-value t
|
||||
:global t))
|
||||
|
||||
|
||||
(use-package! undo-fu-session
|
||||
:unless (featurep! +tree)
|
||||
:hook (undo-fu-mode . global-undo-fu-session-mode)
|
||||
:preface
|
||||
(setq undo-fu-session-directory (concat doom-cache-dir "undo-fu-session/")
|
||||
undo-fu-session-incompatible-files '("/COMMIT_EDITMSG\\'" "/git-rebase-todo\\'"))
|
||||
|
||||
;; HACK We avoid `:config' here because `use-package's `:after' complicates
|
||||
;; the load order of a package's `:config' block and makes it impossible
|
||||
;; for the user to override its settings with merely `after!' (or
|
||||
;; `eval-after-load'). See jwiegley/use-package#829.
|
||||
(after! undo-fu-session
|
||||
;; HACK Use the faster zstd to compress undo files instead of gzip
|
||||
(when (executable-find "zstd")
|
||||
(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)))))
|
||||
|
||||
|
||||
(use-package! undo-tree
|
||||
:when (featurep! +tree)
|
||||
;; Branching & persistent undo
|
||||
: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/"))))
|
||||
|
||||
;; 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).
|
||||
(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")))
|
||||
|
||||
;; 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))
|
7
modules/emacs/undo/packages.el
Normal file
7
modules/emacs/undo/packages.el
Normal file
|
@ -0,0 +1,7 @@
|
|||
;; -*- no-byte-compile: t; -*-
|
||||
;;; emacs/undo/packages.el
|
||||
|
||||
(if (not (featurep! +tree))
|
||||
(package! undo-tree :pin "5b6df03781")
|
||||
(package! undo-fu :pin "0c34b6747e")
|
||||
(package! undo-fu-session :pin "b808ef0cdc"))
|
Loading…
Add table
Add a link
Reference in a new issue