Skip to content

Commit 7c7a4e6

Browse files
jwhite510chrisbra
authored andcommitted
patch 9.1.1009: diff feature can be improved
Problem: diff feature can be improved Solution: include the linematch diff alignment algorithm (Jonathon) closes: #9661 Signed-off-by: Jonathon <jonathonwhite@protonmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent faf250c commit 7c7a4e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2162
-102
lines changed

Filelist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ SRC_ALL = \
5252
src/debugger.c \
5353
src/dict.c \
5454
src/diff.c \
55+
src/linematch.c \
5556
src/digraph.c \
5657
src/drawline.c \
5758
src/drawscreen.c \
@@ -286,6 +287,7 @@ SRC_ALL = \
286287
src/proto/insexpand.pro \
287288
src/proto/job.pro \
288289
src/proto/json.pro \
290+
src/proto/linematch.pro \
289291
src/proto/list.pro \
290292
src/proto/locale.pro \
291293
src/proto/logfile.pro \

runtime/doc/options.txt

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 9.1. Last change: 2025 Jan 10
1+
*options.txt* For Vim version 9.1. Last change: 2025 Jan 12
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2880,11 +2880,20 @@ A jump table for the options with a short description can be found at |Q_op|.
28802880
Option settings for diff mode. It can consist of the following items.
28812881
All are optional. Items must be separated by a comma.
28822882

2883-
filler Show filler lines, to keep the text
2884-
synchronized with a window that has inserted
2885-
lines at the same position. Mostly useful
2886-
when windows are side-by-side and 'scrollbind'
2887-
is set.
2883+
algorithm:{text} Use the specified diff algorithm with the
2884+
internal diff engine. Currently supported
2885+
algorithms are:
2886+
myers the default algorithm
2887+
minimal spend extra time to generate the
2888+
smallest possible diff
2889+
patience patience diff algorithm
2890+
histogram histogram diff algorithm
2891+
2892+
closeoff When a window is closed where 'diff' is set
2893+
and there is only one window remaining in the
2894+
same tab page with 'diff' set, execute
2895+
`:diffoff` in that window. This undoes a
2896+
`:diffsplit` command.
28882897

28892898
context:{n} Use a context of {n} lines between a change
28902899
and a fold that contains unchanged lines.
@@ -2895,6 +2904,23 @@ A jump table for the options with a short description can be found at |Q_op|.
28952904
value (999999) to disable folding completely.
28962905
See |fold-diff|.
28972906

2907+
filler Show filler lines, to keep the text
2908+
synchronized with a window that has inserted
2909+
lines at the same position. Mostly useful
2910+
when windows are side-by-side and 'scrollbind'
2911+
is set.
2912+
2913+
foldcolumn:{n} Set the 'foldcolumn' option to {n} when
2914+
starting diff mode. Without this 2 is used.
2915+
2916+
followwrap Follow the 'wrap' option and leave as it is.
2917+
2918+
horizontal Start diff mode with horizontal splits (unless
2919+
explicitly specified otherwise).
2920+
2921+
hiddenoff Do not use diff mode for a buffer when it
2922+
becomes hidden.
2923+
28982924
iblank Ignore changes where lines are all blank. Adds
28992925
the "-B" flag to the "diff" command if
29002926
'diffexpr' is empty. Check the documentation
@@ -2908,6 +2934,17 @@ A jump table for the options with a short description can be found at |Q_op|.
29082934
are considered the same. Adds the "-i" flag
29092935
to the "diff" command if 'diffexpr' is empty.
29102936

2937+
indent-heuristic
2938+
Use the indent heuristic for the internal
2939+
diff library.
2940+
2941+
internal Use the internal diff library. This is
2942+
ignored when 'diffexpr' is set. *E960*
2943+
When running out of memory when writing a
2944+
buffer this item will be ignored for diffs
2945+
involving that buffer. Set the 'verbose'
2946+
option to see when this happens.
2947+
29112948
iwhite Ignore changes in amount of white space. Adds
29122949
the "-b" flag to the "diff" command if
29132950
'diffexpr' is empty. Check the documentation
@@ -2927,46 +2964,19 @@ A jump table for the options with a short description can be found at |Q_op|.
29272964
of the "diff" command for what this does
29282965
exactly.
29292966

2930-
horizontal Start diff mode with horizontal splits (unless
2931-
explicitly specified otherwise).
2967+
linematch:{n} Align and mark changes between the most
2968+
similar lines between the buffers. When the
2969+
total number of lines in the diff hunk exceeds
2970+
{n}, the lines will not be aligned because for
2971+
very large diff hunks there will be a
2972+
noticeable lag. A reasonable setting is
2973+
"linematch:60", as this will enable alignment
2974+
for a 2 buffer diff hunk of 30 lines each,
2975+
or a 3 buffer diff hunk of 20 lines each.
29322976

29332977
vertical Start diff mode with vertical splits (unless
29342978
explicitly specified otherwise).
29352979

2936-
closeoff When a window is closed where 'diff' is set
2937-
and there is only one window remaining in the
2938-
same tab page with 'diff' set, execute
2939-
`:diffoff` in that window. This undoes a
2940-
`:diffsplit` command.
2941-
2942-
hiddenoff Do not use diff mode for a buffer when it
2943-
becomes hidden.
2944-
2945-
foldcolumn:{n} Set the 'foldcolumn' option to {n} when
2946-
starting diff mode. Without this 2 is used.
2947-
2948-
followwrap Follow the 'wrap' option and leave as it is.
2949-
2950-
internal Use the internal diff library. This is
2951-
ignored when 'diffexpr' is set. *E960*
2952-
When running out of memory when writing a
2953-
buffer this item will be ignored for diffs
2954-
involving that buffer. Set the 'verbose'
2955-
option to see when this happens.
2956-
2957-
indent-heuristic
2958-
Use the indent heuristic for the internal
2959-
diff library.
2960-
2961-
algorithm:{text} Use the specified diff algorithm with the
2962-
internal diff engine. Currently supported
2963-
algorithms are:
2964-
myers the default algorithm
2965-
minimal spend extra time to generate the
2966-
smallest possible diff
2967-
patience patience diff algorithm
2968-
histogram histogram diff algorithm
2969-
29702980
Examples: >
29712981
:set diffopt=internal,filler,context:4
29722982
:set diffopt=

runtime/doc/version9.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2025 Jan 02
1+
*version9.txt* For Vim version 9.1. Last change: 2025 Jan 12
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41625,6 +41625,9 @@ Changed~
4162541625
the "matches" key
4162641626
- |v:stacktrace| The stack trace of the exception most recently caught and
4162741627
not finished
41628+
- include the linematch algorithm for the 'diffopt' setting. This aligns
41629+
changes between buffers on similar lines improving the diff highlighting in
41630+
Vim
4162841631

4162941632
*added-9.2*
4163041633
Added ~

src/Make_ami.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ SRC += \
123123
indent.c \
124124
insexpand.c \
125125
json.c \
126+
linematch.c\
126127
list.c \
127128
locale.c \
128129
logfile.c \

src/Make_cyg_ming.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ OBJ = \
817817
$(OUTDIR)/indent.o \
818818
$(OUTDIR)/insexpand.o \
819819
$(OUTDIR)/json.o \
820+
$(OUTDIR)/linematch.o \
820821
$(OUTDIR)/list.o \
821822
$(OUTDIR)/locale.o \
822823
$(OUTDIR)/logfile.o \

src/Make_mvc.mak

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ OBJ = \
738738
$(OUTDIR)\indent.obj \
739739
$(OUTDIR)\insexpand.obj \
740740
$(OUTDIR)\json.obj \
741+
$(OUTDIR)\linematch.obj \
741742
$(OUTDIR)\list.obj \
742743
$(OUTDIR)\locale.obj \
743744
$(OUTDIR)\logfile.obj \
@@ -1675,6 +1676,8 @@ $(OUTDIR)/job.obj: $(OUTDIR) job.c $(INCL)
16751676

16761677
$(OUTDIR)/json.obj: $(OUTDIR) json.c $(INCL)
16771678

1679+
$(OUTDIR)/linematch.obj: $(OUTDIR) linematch.c $(INCL)
1680+
16781681
$(OUTDIR)/list.obj: $(OUTDIR) list.c $(INCL)
16791682

16801683
$(OUTDIR)/locale.obj: $(OUTDIR) locale.c $(INCL)
@@ -1954,6 +1957,7 @@ proto.h: \
19541957
proto/indent.pro \
19551958
proto/insexpand.pro \
19561959
proto/json.pro \
1960+
proto/linematch.pro \
19571961
proto/list.pro \
19581962
proto/locale.pro \
19591963
proto/logfile.pro \

src/Make_vms.mms

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ SRC = \
381381
insexpand.c \
382382
job.c \
383383
json.c \
384+
linematch.c \
384385
list.c \
385386
locale.c \
386387
logfile.c \
@@ -514,6 +515,7 @@ OBJ = \
514515
insexpand.obj \
515516
job.obj \
516517
json.obj \
518+
linematch.obj \
517519
list.obj \
518520
locale.obj \
519521
logfile.obj \
@@ -986,6 +988,9 @@ job.obj : job.c vim.h [.auto]config.h feature.h os_unix.h
986988
json.obj : json.c vim.h [.auto]config.h feature.h os_unix.h \
987989
ascii.h keymap.h termdefs.h macros.h structs.h regexp.h gui.h beval.h \
988990
[.proto]gui_beval.pro option.h ex_cmds.h proto.h errors.h globals.h
991+
linematch.obj : linematch.c vim.h [.auto]config.h feature.h os_unix.h \
992+
ascii.h keymap.h termdefs.h macros.h structs.h regexp.h gui.h beval.h \
993+
[.proto]gui_beval.pro option.h ex_cmds.h proto.h errors.h globals.h
989994
list.obj : list.c vim.h [.auto]config.h feature.h os_unix.h \
990995
ascii.h keymap.h termdefs.h macros.h option.h structs.h regexp.h gui.h \
991996
beval.h [.proto]gui_beval.pro alloc.h ex_cmds.h spell.h proto.h \

src/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,7 @@ BASIC_SRC = \
15311531
indent.c \
15321532
insexpand.c \
15331533
json.c \
1534+
linematch.c \
15341535
list.c \
15351536
locale.c \
15361537
logfile.c \
@@ -1693,6 +1694,7 @@ OBJ_COMMON = \
16931694
objects/if_xcmdsrv.o \
16941695
objects/indent.o \
16951696
objects/insexpand.o \
1697+
objects/linematch.o \
16961698
objects/list.o \
16971699
objects/locale.o \
16981700
objects/logfile.o \
@@ -1842,6 +1844,7 @@ PRO_AUTO = \
18421844
debugger.pro \
18431845
dict.pro \
18441846
diff.pro \
1847+
linematch.pro \
18451848
digraph.pro \
18461849
drawline.pro \
18471850
drawscreen.pro \
@@ -3343,6 +3346,9 @@ objects/json_test.o: json_test.c
33433346
objects/kword_test.o: kword_test.c
33443347
$(CCC) -o $@ kword_test.c
33453348

3349+
objects/linematch.o: linematch.c
3350+
$(CCC) -o $@ linematch.c
3351+
33463352
objects/list.o: list.c
33473353
$(CCC) -o $@ list.c
33483354

@@ -3944,6 +3950,11 @@ objects/json.o: json.c vim.h protodef.h auto/config.h feature.h os_unix.h \
39443950
proto/gui_beval.pro structs.h regexp.h gui.h libvterm/include/vterm.h \
39453951
libvterm/include/vterm_keycodes.h alloc.h ex_cmds.h spell.h proto.h \
39463952
globals.h errors.h
3953+
objects/linematch.o: linematch.c vim.h protodef.h auto/config.h feature.h \
3954+
os_unix.h auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h \
3955+
beval.h proto/gui_beval.pro structs.h regexp.h gui.h \
3956+
libvterm/include/vterm.h libvterm/include/vterm_keycodes.h xdiff/xdiff.h \
3957+
xdiff/../vim.h alloc.h ex_cmds.h spell.h proto.h globals.h errors.h
39473958
objects/list.o: list.c vim.h protodef.h auto/config.h feature.h os_unix.h \
39483959
auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \
39493960
proto/gui_beval.pro structs.h regexp.h gui.h libvterm/include/vterm.h \

0 commit comments

Comments
 (0)