I have noticed that in long editing sessions, calling undo-tree
(C-x C-u) becomes slower and slower. I presume that the reason is that as the tree grows bigger it takes longer to parse it (as it keeps track of all my edits since I opened the file)
Is there any way to clear up the tree of undos on an open file? I have tried C-x C-v
(find-alternate-file
), but this re-opens the file which resets the cursor (and in modes like org-mode
collapses my lists)
Reset the buffer-undo-tree
variable using M-: (setq buffer-undo-tree nil)
. This discards the entire undo history of the buffer, as recorded by undo-tree.el
.
This can also be made into a command and bound to a key with code like this:
(defun clear-undo-tree ()
(interactive)
(setq buffer-undo-tree nil))
(global-set-key [(control c) u] 'clear-undo-tree)
Note that this tip may be obsolete in recent undo-tree versions. From version 0.6 onwards, undo-tree uses "lazy tree-drawing" by default. This significantly speeds up visualization of large undo trees, by only drawing the visible portion (and extending it as necessary as you move around the tree). See the docstring for the undo-tree-visualizer-lazy-drawing
variable for further details.
If you nonetheless want to discard the entire undo tree, manually setting buffer-undo-tree
to nil
is a good one-off solution. A longer-term solution is to reduce the values of undo-limit
, undo-strong-limit
, and undo-outer-limit
to limit the undo tree size, by limiting how much undo history it stores before discarding older data.
Manually calling undo-tree-discard-history
is pointless. It gets called automatically whenever you do anything undo-related.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With