casouri / vundo

Visualize the undo tree.
413 stars 20 forks source link

diff not working in some buffers #84

Closed serycjon closed 6 months ago

serycjon commented 6 months ago

Hi,

I have tried vundo, but the diff feature didn't work properly for me. It does work in init.el buffer, but it doesn't work in 15.py - the diff is not shown at all: EmacsPgU29p

After a bit of digging, I have found that the problem is caused by vundo-diff--cleanup-diff-buffer - before it is called, the diff is shown. Seems like an issue with the regexp:

(rx-to-string `(and bol ,pat (+ space)
            (group (group (+ (not ?\t)))
               (* any))
            eol))

In particular, when I replace the greedy operators + and * by their non-greedy variant:

(rx-to-string `(and bol ,pat (+ space)
            (group (group (+? (not ?\t)))
               (*? any))
            eol))

The diff is shown nicely: Emacs5eP2WP

I don't know why this only happens in some buffers.

jdtsmith commented 6 months ago

Interesting, thanks; I worried about that regexp replace going wrong. I don't see that behavior with the same filename, so it must be something about the tmp-file location on your system confusing things.

Can you mention the diff headers it had prior to vundo-diff--cleanup-diff-buffer? I see it also left the file names in the diff call above. So it's not correctly recognizing those and replacing them.

serycjon commented 6 months ago

with the call to vundo-diff--cleanup-diff-buffer commented out:

diff -u --label \#\<buffer\ 15.py-vundo-diff-markedltV4fE\> --label \#\<buffer\ 15.py\> /tmp/buffer-content-G0Qe91 /tmp/buffer-content-iCyxJQ
--- #<buffer 15.py-vundo-diff-markedltV4fE>
+++ #<buffer 15.py>
@@ -74,4 +74,6 @@
     for slot_id, (label, focal_length) in enumerate(box):
         total += (1 + box_id) * (1 + slot_id) * focal_length
 print(total)
-tnaoeun
\ No newline at end of file
+tnaoeun
+
+ontoeuh
\ No newline at end of file

Diff finished.  Sat Dec 16 21:33:03 2023

with the cleanup:

vundo-diff: 15.py
diff -u --label \#\<buffer\ 15.py-vundo-diff-markedvaGqK2\> --label \#\<buffer\ 15.py\> /tmp/buffer-content-rC66Mo /tmp/buffer-content-4HZRRj
--- <15.py> [mod 5] (Parent)
jdtsmith commented 6 months ago

That's very interesting, thanks. What system is this? It's using an interesting --label option to diff that I don't have (mine just mention the bare temp files).

My cleanup regexp indeed presumed a tab would appear after the file, but it does not for you (possibly because of --label), so it was swallowing the entire diff. Please try my branch at https://github.com/jdtsmith/vundo/tree/fix-cleanup. I am also let-binding diff-use-labels=nil to hopefully get your diff command looking right. Give a try and let me know how it goes.

serycjon commented 6 months ago

Arch linux, diff (GNU diffutils) 3.10

After your fix it looks good I think:

vundo-diff: 15.py
diff -u [5] [6]
--- <15.py> [mod 5] (Parent)
+++ <15.py> [mod 6] (Current)
@@ -74,4 +74,6 @@
     for slot_id, (label, focal_length) in enumerate(box):
         total += (1 + box_id) * (1 + slot_id) * focal_length
 print(total)
-tnaoeun
\ No newline at end of file
+tnaoeun
+
+ontoeuh
\ No newline at end of file

Diff finished.  Sun Dec 17 01:28:08 2023
jdtsmith commented 6 months ago

Great thanks.

ideasman42 commented 6 months ago

I'm running into this too, I'm not too familier with rx-to-string, personally I'd prefer a regex literal e.g.

                (re-search-forward (concat
                                    "^"
                                    ;; Prefix.
                                    "\\-\\-\\-[[:blank:]]+.*\n" ; '--- '
                                    "\\+\\+\\+[[:blank:]]+.*\n") ; '+++ '
                                   nil t 1)
jdtsmith commented 6 months ago

You should check out rx, it's a fantastic way to clarify regexes. rx-to-string is just the runtime equivalent of the macro, when you have dynamic elements. See #86 for a fix (please let me know how that works for you).

justinbarclay commented 6 months ago

That's very interesting, thanks. What system is this? It's using an interesting --label option to diff that I don't have (mine just mention the bare temp files).

My cleanup regexp indeed presumed a tab would appear after the file, but it does not for you (possibly because of --label), so it was swallowing the entire diff. Please try my branch at https://github.com/jdtsmith/vundo/tree/fix-cleanup. I am also let-binding diff-use-labels=nil to hopefully get your diff command looking right. Give a try and let me know how it goes.

I was running into the same problem on macOs with diff 3.10 and this branch fixed the issue for me

jdtsmith commented 6 months ago

See #86. Should be merged soon I hope.