casouri / vundo

Visualize the undo tree.
469 stars 23 forks source link

Exiting vundo should (optionally) exit vundo-diff #88

Open ideasman42 opened 11 months ago

ideasman42 commented 11 months ago

It would be good if quitting vundo would also close the vundo-diff buffer & window. So viewing a vundo-diff buffer doesn't leave this buffer open once I've finished using vundo (which I need to manually exit). I'm not so fussed on this being on by default or not, just that it would be nice if it's a toggle.

Of course it's possible to write advice that does this but it seems like something users might want to enable without the hassle of implementing this themselves.

Note that vundo-post-exit-hook can't easily be used for this as the vundo buffer has been deleted (which is needed to access the name of the diff buffer).


This advice for vundo-quit works but it involves using internal names.

(advice-add
 'vundo-quit
 :around
 #'(lambda (old-fn &rest args)
     (let* ((orig vundo--orig-buffer)
            (oname (buffer-name orig))
            (diff-buf (get-buffer (concat "*vundo-diff-" oname "*"))))
       (when diff-buf
         (let ((diff-window (get-buffer-window diff-buf)))
           (when diff-window
             (delete-window diff-window))
           (kill-buffer diff-buf)))

       (let ((result (apply old-fn args)))
         result))))
jdtsmith commented 11 months ago

92 should I think do what you want; let me know if not.