Update Tuesday, 27th of January, Anno Domini MMIX, at the hour of the Rat
[git/dscho.git] / source-1232888842.txt
blob53866660414930a75c56c2ccf76acd1b345c2ad1
1 Regular diff with word coloring (as opposed to word diff)
3 You know, if I were a bit faster with everything I do, I could do so much more!
5 For example, Junio's idea that you could keep showing a regular diff, only
6 coloring the words that have been removed/deleted.
8 Just imagine looking at the diff of a long line in LaTeX source code.  It
9 should be much nicer to the eye to see the complete removed/added sentences
10 instead of one sentence with colored words in between, disrupting your read
11 flow.
13 Compare these two versions:
15 Regular diff with colored words:
16 <blockquote><tt>
17 -This sentence has a <font color=red>tyop</font> in it.<br>
18 +This sentence has a <font color=green>typo</font> in it.<br>
19 </tt></blockquote>
21 Word diff:
22 <blockquote><tt>
23 This sentence has a <font color=red>tyop</font><font color=green>typo</font> in it.<br>
24 </tt></blockquote>
26 And it should not be hard to do at all!
28 In ''diff&#95;words&#95;show()'', we basically get the minus lines as
29 ''diff&#95;words->minus'' and the plus lines as ''diff&#95;words->plus''.  The
30 function then prepares the word lists and calls the xdiff engine to do all the
31 hard work, analyzing the result from xdiff and printing the lines in
32 ''fn&#95;out&#95;diff&#95;words&#95;aux()''.
34 So all that would have to be changed would be to _record_ the positions
35 of the removed/added words instead of outputting them, and at the end printing
36 the minus/plus buffers using the recorded information to color the words.
38 This would involve
40 <ul>
41 <li>adding two new members holding the offsets in the ''diff&#95;words''
42 struct,
43 <li>having a special handling for that mode in
44 ''fn&#95;out&#95;diff&#95;words&#95;aux()'' that appends the offsets and
45 returns,
46 <li>adding a function ''show&#95;lines&#95;with&#95;colored&#95;words()'' that
47 outputs a buffer with a given prefix ('-' or '+') and coloring the words at
48 given offsets with a given color,
49 <li>modify ''diff&#95;words&#95;show()'' to call that function for the "special
50 case: only removal" and at the end of the function, and
51 <li> disabling the ''fwrite()'' at the end of ''diff_words_show()'' for that
52 mode.
53 </ul>
55 Of course, the hardest part is to find a nice user interface for that.  Maybe
56 ''--colored-words''? :-)