casouri / vundo

Visualize the undo tree.
413 stars 20 forks source link

vundo-diff #78

Closed jdtsmith closed 6 months ago

jdtsmith commented 7 months ago

This provides vundo-diff support with the following capabilities:

casouri commented 7 months ago

Thanks, looks nice! But please make sure only indent with spaces, I'm seeing tabs again. Apart from the comments above, I also see terminal color codes in the terminal. I know you are using Emacs facility for diffing, is there anything we can do? Or at least teach users how to resolve it in the docs.

Screenshot 2023-12-03 at 11 27 43 PM
jdtsmith commented 7 months ago

Thanks. Indent fixed. For your color codes in terminal, maybe try (setq diff-switches "-u --color=never")?

The one other feature I considered overnight is just replacing those terrible tmp file names with the Current/Marked (with TS). But it sounds a bit fragile, so maybe not worth it for the improved cleanliness.

jdtsmith commented 7 months ago

I have added a sanity check wrapper prior to the moves, and pushed some README/NEWS changes for your consideration. I'm still playing with the formatting in the diff buffer, will wrap that up soon.

jdtsmith commented 7 months ago

I made a few more improvements today:

This PR is pretty well complete IMO, pending any further review.

casouri commented 6 months ago

Looks nice!

Turns out that diff can be called async, and if so, I need to update/cleanup the diff buffer in the process sentinel.

Why use the async version? IMO the sync version is perfectly fine and should be simpler to use, right?

And I wonder if we can use a single key to mark/unmark nodes, instead of using both m and u. You know, make it vundo-toggle-mark or something.

jdtsmith commented 6 months ago

Turns out that diff can be called async, and if so, I need to update/cleanup the diff buffer in the process sentinel.

Why use the async version? IMO the sync version is perfectly fine and should be simpler to use, right?

Since it's the default, people might be used to that behavior of diff. The cost to support async is not high: just a lambda for the process sentinel. And sometimes tmp files are across a tramp link. [Update: since all the undo data are in process, I don't buy my own argument. I've switched to a sync-call for simplicity. ]

And I wonder if we can use a single key to mark/unmark nodes, instead of using both m and u. You know, make it vundo-toggle-mark or something.

~Good idea. Maybe just m.~ OK, just tried and I don't love it. The problem is this: I often cruise around a few nearby nodes, and set a few different marks in a row, and re-diff looking for "something specific". This would double the number of m's I have to hit.

We could make it so that m on an unmarked node sets is, m on a marked node unsets. But that's getting fancy/non-intuitive. I think m + u is pretty simple and clean, and leverages dired knowledge.

And if you don't mind taking a look up at my question about vundo-refresh-buffer, I'm still a bit confused about the need for that to be there twice.

casouri commented 6 months ago

We could make it so that m on an unmarked node sets is, m on a marked node unsets. But that's getting fancy/non-intuitive. I think m + u is pretty simple and clean, and leverages dired knowledge.

Ok, I trust your judgement here.

And if you don't mind taking a look up at my question about vundo-refresh-buffer, I'm still a bit confused about the need for that to be there twice.

Yeah, moving to a node pushes new undo entries onto undo-list, and we need to process those with vundo-refresh-buffer (update mod-list, etc).

jdtsmith commented 6 months ago

Thanks for the feedback.

And if you don't mind taking a look up at my question about vundo-refresh-buffer, I'm still a bit confused about the need for that to be there twice.

Yeah, moving to a node pushes new undo entries onto undo-list, and we need to process those with vundo-refresh-buffer (update mod-list, etc).

I think what confuses me is this note from the vundo--trim-undo-list doc:

We can call vundo--move-to-node multiple times between two vundo--refresh-buffer.

That doesn't seem to be the case here. I.e. you must call refresh-buffer after each of the pair of moves (there and back) or you get no route. Probably not important.

Found one more little doc tweak I pushed, so this is ready to go.

In terms of version bump, I do have a couple of small things I'd like to send in as a small additional PR once this is merged:

  1. Make l key move to a prior saved node, if already on one (so you can l, l, l, to go back through saved states), and have it report the saved time too.
  2. Ensure the pattern undo-to-node, save it, alter it correctly marks that node as saved: this requires checking all a node's equivalents nodes for any subsequent TS-ful mod. This does not solve the issue outlined in #66, but that is rare in practice.
casouri commented 6 months ago

That doesn't seem to be the case here. I.e. you must call refresh-buffer after each of the pair of moves (there and back) or you get no route.

Oh, I would trust the me that wrote the comment much more than I trust the me right now. If the comment says so, we should be able to run move-to-node multiple times.

I think I know why you'll get "no route". One example: in an undo list [1 2 3 4 5], you'd have mod list [1 2 3 4 5], and if you go back to node 3, your undo list becomes [1 2 3 4 5 4' 3'], but without calling refresh, the mod list remains [1 2 3 4 5]. Now, if you want to go back to 5, there's no route available in the mod list (you can think of it as you can only go left in the list, so from 5 to 1-4, but not the other way around). Once you call refresh, the mod list becomes [1 2 3 4 5 4' 3'], now you have a route from 3 to 5 (in the form of 3' to 5, which is going left).

Good call though, I never thought about this before. I should add a comment somewhere calling this out.

So the branch is ready for a final review, right? It'd be great if you can squash everything and write a commit message. Then I'll review and merge it.

jdtsmith commented 6 months ago

I think I know why you'll get "no route".

Right, you can't change direction between refresh's.

I'll review and merge it.

Great thanks, commits squashed, ready for review. Once merged I'll submit my small PR for timestamp stuff (I'm already loving multiple l).

casouri commented 6 months ago

Ok, some final nits:

jdtsmith commented 6 months ago

OK should be all set, thanks for the review. I also threw in a docstring escape of single quotes to silence the compiler. Once this is merged I have a TS-related PR I'll post.

casouri commented 6 months ago

Merged, thanks!