Skip to content

Instantly share code, notes, and snippets.

@lawlist
Created September 8, 2020 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawlist/4765516cf58a1ccc1d11de63bacaff34 to your computer and use it in GitHub Desktop.
Save lawlist/4765516cf58a1ccc1d11de63bacaff34 to your computer and use it in GitHub Desktop.
(defun undo-tree-visualize-undo (&optional arg)
"Undo changes. A numeric ARG serves as a repeat count."
(interactive "p")
(unless (eq major-mode 'undo-tree-visualizer-mode)
(user-error "Undo-tree mode not enabled in buffer"))
(let ((old (undo-tree-current buffer-undo-tree))
current)
(unwind-protect
;; undo in parent buffer
(with-current-buffer undo-tree-visualizer-parent-buffer
(deactivate-mark)
(let ((undo-tree-inhibit-kill-visualizer t))
(undo-tree-undo-1 arg))
(setq current (undo-tree-current buffer-undo-tree)))
(with-current-buffer undo-tree-visualizer-buffer-name
;; unhighlight old current node
(let ((undo-tree-insert-face 'undo-tree-visualizer-active-branch-face)
(inhibit-read-only t))
(undo-tree-draw-node old))
;; when using lazy drawing, extend tree upwards as required
(when undo-tree-visualizer-lazy-drawing
(undo-tree-expand-up old current))
;; highlight new current node
(let ((inhibit-read-only t))
(undo-tree-draw-node current 'current))
;; update diff display, if any
(when undo-tree-visualizer-diff
(undo-tree-visualizer-update-diff))))))
(defun undo-tree-visualize-redo (&optional arg)
"Redo changes. A numeric ARG serves as a repeat count."
(interactive "p")
(unless (eq major-mode 'undo-tree-visualizer-mode)
(user-error "Undo-tree mode not enabled in buffer"))
(let ((old (undo-tree-current buffer-undo-tree))
current)
(unwind-protect
;; redo in parent buffer
(with-current-buffer undo-tree-visualizer-parent-buffer
(deactivate-mark)
(let ((undo-tree-inhibit-kill-visualizer t))
(undo-tree-redo-1 arg))
(setq current (undo-tree-current buffer-undo-tree)))
(with-current-buffer undo-tree-visualizer-buffer-name
;; unhighlight old current node
(let ((undo-tree-insert-face 'undo-tree-visualizer-active-branch-face)
(inhibit-read-only t))
(undo-tree-draw-node old))
;; when using lazy drawing, extend tree downwards as required
(when undo-tree-visualizer-lazy-drawing
(undo-tree-expand-down old current))
;; highlight new current node
(let ((inhibit-read-only t))
(undo-tree-draw-node current 'current))
;; update diff display, if any
(when undo-tree-visualizer-diff
(undo-tree-visualizer-update-diff))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment