Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple diff functionality #56

Closed
jdtsmith opened this issue Oct 30, 2022 · 5 comments
Closed

Simple diff functionality #56

jdtsmith opened this issue Oct 30, 2022 · 5 comments

Comments

@jdtsmith
Copy link
Contributor

I missed the "diff" function of undo-tree. You don't always need it, but for complex changes, it can be very helpful to figure out which branch you want. I cobbled together something that works for me — an "on demand" diff on key "d". I didn't study vundo's source closely enough to do this more intelligently, but it would be lovely if something like this made it into vundo.

Thanks for this simple, robust, and great tool.

(defun my/vundo-diff ()
    (interactive)
    (let* ((orig vundo--orig-buffer)
           (source (vundo--current-node vundo--prev-mod-list))
           (dest (vundo-m-parent source)))
      (if (or (not dest) (eq source dest))
          (message "vundo diff not available.")
	(let ((buf (make-temp-name (concat (buffer-name orig) "-vundo-diff"))))
          (vundo--move-to-node source dest orig vundo--prev-mod-list)
          (with-current-buffer (get-buffer-create buf)
	    (insert-buffer orig))
          (vundo--refresh-buffer orig (current-buffer) 'incremental)
          (vundo--move-to-node dest source orig vundo--prev-mod-list)
          (vundo--refresh-buffer orig (current-buffer) 'incremental)
          (diff-buffers buf orig)
          (kill-buffer buf)))))
(define-key vundo-mode-map "d" #'my/vundo-diff)
@casouri
Copy link
Owner

casouri commented Nov 16, 2022

Oh Cool! I guess it can be useful when you couldn't tell what was changed in an undo. You can use undo-hl but this is another way. I'll see what I can come up with when I find som time. Thanks!

@jdtsmith
Copy link
Contributor Author

Yeah especially for "big" diffs like copying in a bunch of changes from another version, or a complex find/replace, it really helps. I probably use it 1 in 20 times I invoke vundo. Compared to undo-tree, I actually find I prefer the diff not to change as I move around nodes, i.e. only when invoked. That said, it would be very nice to highlight the node from which diff was invoked in some way. I.e. add another overlay that does vundo--highlight-node but in diff-header face color.

One thing I didn't quite figure out was what (vundo--refresh-buffer orig (current-buffer) 'incremental) really does, so I sprinkled them in until it worked ;). Probably this could be streamlined.

@jdtsmith
Copy link
Contributor Author

jdtsmith commented Dec 2, 2023

Picking this back up. It would be nice to (m)ark a node (or (u)nmark it), navigate around using the normal vundo nav functions, then (d)iff between the marked and current node (by default, the prior node, as above). I can take a look.

@gitrj95
Copy link

gitrj95 commented Dec 2, 2023

This would be great for my workflow. Thanks.

@jdtsmith
Copy link
Contributor Author

This is implemented in #78.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants