reddit / emacs

An experiment to make diffs easier to read

kcin · 2022-04-02 16:46
When a line is changed diff usually shows you one deleted line and one added line (assuming unified diffs). Would it be better if it showed only the changes within the line? There is refinement as an option, but that too gives you two lines. Here's an experimental package which converts a unified diff into an inline diff, collapsing changed lines into a single line where green shows the added part and reddish color shows the removed part. Here's how it looks: https://i.imgur.com/Jn6Tffp.png I made this package as an experiment to test how useful it is. Currently, it works with files under git when you compare it to the latest commited version (C-x v =), but it shouldn't be hard to make it generic. I'm just putting it here, in case someone finds this useful. The code: https://gist.github.com/codecoll/8791162296eb9a2d504238f5d8a121cd
paretoOptimalDev · 2022-04-02 17:22
This looks like difftastic: https://difftastic.wilfred.me.uk/
kcin · 2022-04-02 18:09
The difference is this one does not need to understand syntax, it works with syntaxless textfiles too.
grimscythe_ · 2022-04-02 18:48
Very nice, thanks a million kind stranger.
blvaga · 2022-04-02 20:30
love little projects like these! Very cool
MaximRegret · 2022-04-03 17:32
You might be interested in [Delta](https://github.com/dandavison/delta) and the emacs package [magit-delta](https://github.com/dandavison/magit-delta) that uses it. It has this feature and several other as well.
kcin · 2022-04-03 17:38
Doesn't look the same. Judging from the screenshots delta still shows a deleted and added line when a line is changed. It only does not do that when the side by side view is activated.
MaximRegret · 2022-04-03 17:43
Ah, yes, you're right. It still shows the lines separately but it highlights the part of the line that has changed.
kcin · 2022-04-03 18:01
Emacs does that out of the box by itself. It's called diff refining.
casouri · 2022-04-03 21:08
Looks cool! I’ll try it out.
KonpakuYoumu · 2022-04-06 05:27
Neet! Please make it into Emacs core.