casouri / vundo

Visualize the undo tree.
413 stars 20 forks source link

Add hooks for entering and exiting vundo #44

Closed ideasman42 closed 2 years ago

ideasman42 commented 2 years ago

This makes it possible to activate a minor mode while Vundo is in use.

(setq undo-hl-undo-commands (list 'vundo-backward 'vundo-forward 'vundo-stem-root 'vundo-stem-end))
(add-hook 'vundo-enter-hook (lambda () (undo-hl-mode 1)))
(add-hook 'vundo-exit-hook (lambda () (undo-hl-mode -1)))
casouri commented 2 years ago

Thanks, merged. I changed the hook names to pre-enter-hook and post-exit-hook to indicate they runs at the very beginning and end.

ideasman42 commented 2 years ago

Are these changes meant to be in master? (last commit was from ~17 days ago)

casouri commented 2 years ago

Yeah yeah, I merged and pushed locally and made a new version, but I was like "better address any possible follow ups before pushing a new version". So I'm waiting for all the conversations to settle before I push the updates.

ideasman42 commented 2 years ago

Thanks, closing.

noctuid commented 2 years ago

@ideasman42 Can you actually get hl-undo-mode to work with vundo like that (with the correct hook names)? I can't seem to get hl-undo-mode to work with vundo at all.

Also the documentation for vundo-post-exit-hook still needs to be fixed ("entering" -> "exiting, "exists" -> "exits").

ideasman42 commented 2 years ago

@noctuid yes, but it was a bit of a hassle as the pre-command hook needs to run in the text-buffer. Even though vundo commands are running int the vundo buffer.

(setq undo-hl-undo-commands
  (list 'vundo-backward 'vundo-forward 'vundo-stem-root 'vundo-stem-end))

(defvar my-real-vundo-buf nil)
(defun my-vundo-forward-pre-command-hook ()
  (let ((buf (current-buffer)))
    (when (bound-and-true-p my-real-vundo-buf)
      (unless (eq buf my-real-vundo-buf)
        (with-current-buffer my-real-vundo-buf (run-hooks 'pre-command-hook))))))

(add-hook 'vundo-pre-enter-hook
  (lambda ()
    (setq my-real-vundo-buf (current-buffer))
    (add-hook 'pre-command-hook 'my-vundo-forward-pre-command-hook)
    (undo-hl-mode 1)))
(add-hook 'vundo-post-exit-hook
  (lambda ()
    (remove-hook 'pre-command-hook 'my-vundo-forward-pre-command-hook)
    (undo-hl-mode -1)
    (makunbound 'my-real-vundo-buf)))