reddit / emacs

Iniline refined git diff with live update (video demo included)

kcin · 2022-03-21 21:13
I often compare my files to the latest version committed in git and I thought it could be interesting to see these changes inline in the buffer, refined to character level, so I created this package as a proof of concept. I'm putting it here in case someone finds it interesting and wants to productify it (more testing, polishing, melpa), because I don't have the time to finish it. Video demo of how it works: https://i.imgur.com/I7ITkoE.gif Code: https://gist.github.com/codecoll/84245ad37efd947a4d8e3fd494a00091
7890yuiop · 2022-03-21 22:27
That looks neat. Could you `M-x report-emacs-bug` as a feature suggestion, with your code?
dpoggio · 2022-03-22 01:38
This is better than diff-hl-mode. MELPA?
404cn · 2022-03-22 03:09
Looks cool, but has too many problems for now.
404cn · 2022-03-22 03:12
Function `my-inline-diff` bracket not pair. Didn't find incf function, so I replace it with cl-incf. Revert not work:` wrong type argument overlayp, nil ` ​ Emacs29 on macOS
kcin · 2022-03-22 03:41
Yep, there are still some bugs, but it's unlikely I'll have the time to work on them in the near future. I thnk the concept is promising, though, that's why I posted the code, in case somebody wants to finish it.
kcin · 2022-03-22 03:46
>Function my-inline-diff bracket not pair. Fixed. It's a copy paste error. I should have checked it. Thanks. As for the errors, [see this answer](https://reddit.com/r/emacs/comments/tjm6ly/iniline_refined_git_diff_with_live_update_video/i1mc7n4/).
404cn · 2022-03-22 03:47
Yes that make sense
kcin · 2022-03-22 03:48
Yes, please, just somebody should iron out the remaining bugs. I don't think there are many, but I won't have time to work on this in the near future, that's why I posted the code in case somebody's interested.
kcin · 2022-03-22 03:52
I guess it's quicker if someone finishes the code and puts on MELPA, because the core devs have enough things to work on.
7890yuiop · 2022-03-22 04:00
"Quicker" doesn't really factor into it, to my mind. Improvements to Emacs are welcomed by the maintainers, and a better default Emacs benefits everyone. You should feel free to propose improvements and provide code.
ideasman_42 · 2022-03-22 08:58
Does this functionality exist in other editors/IDE's? Is this something others generally find useful? It seems nifty and perhaps useful for minor edits, but would likely end up getting in the way for larger changes. Currently I use hl-diff, then diff-mode / [diff-ansi](https://gitlab.com/ideasman42/emacs-diff-ansi) to get a fuller context of how things have changed.
[deleted] · 2022-03-22 16:05
[deleted]
geza42 · 2022-03-22 21:06
I like this idea. It can behave a little bit odd, though. For example, if I change the word "coordinate" to "reverse", it doesn't show what I'd expect ("coordinate" is red and "reverse" is green), but several added and removed short strings: "\[coo\]r\[dinat\]\[evers\]e". For a more complex example, the result is even worse. A simple, several-line source code change can create a very messy diff, because it diffs on the character level. Do anyone has an idea how to fix this?
kcin · 2022-03-22 21:13
The line "--word-diff-regex=." sets up character-level diffs. You can try commenting out this line to get word-level diffs.
geza42 · 2022-03-22 21:48
Thanks! I tried it, and it solves the messy diff issue, but introduces another one. If there is "// Something", and I remove the space between the "//" and "Something", then it generates a larger diff than I expected. I'd expect a red space, but it considers that "// Something" was removed, and "//Something" is added. Also, it doesn't show whitespace differences. This idea is great, it just needs additional work. Maybe I'll try to solve these issues, if no one else does. I already created a minor mode out of this, and added a unique overlay category so it doesn't mess up other overlays. And I made the narrowing feature toggleable.