Mercurial > vim
annotate src/diff.c @ 27301:ebe56a24acb6 v8.2.4179
patch 8.2.4179: 'foldtext' is evaluated in the current script context
Commit: https://github.com/vim/vim/commit/9530b580a7b71960dbbdb2b12a3aafeb540bd135
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 22 13:39:08 2022 +0000
patch 8.2.4179: 'foldtext' is evaluated in the current script context
Problem: 'foldtext' is evaluated in the current script context.
Solution: Use the script context where the option was set.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 22 Jan 2022 14:45:02 +0100 |
parents | ac75c145f0a9 |
children | e4d25cbc2bd7 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10013
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
1788 | 11 * diff.c: code for diff'ing two, three or four buffers. |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
12 * |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
13 * There are three ways to diff: |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
14 * - Shell out to an external diff program, using files. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
15 * - Use the compiled-in xdiff library. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
16 * - Let 'diffexpr' do the work, using files. |
7 | 17 */ |
18 | |
19 #include "vim.h" | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
20 #include "xdiff/xdiff.h" |
7 | 21 |
22 #if defined(FEAT_DIFF) || defined(PROTO) | |
23 | |
14776
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
24 static int diff_busy = FALSE; // using diff structs, don't change them |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
25 static int diff_need_update = FALSE; // ex_diffupdate needs to be called |
7 | 26 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
27 // flags obtained from the 'diffopt' option |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
28 #define DIFF_FILLER 0x001 // display filler lines |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
29 #define DIFF_IBLANK 0x002 // ignore empty lines |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
30 #define DIFF_ICASE 0x004 // ignore case |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
31 #define DIFF_IWHITE 0x008 // ignore change in white space |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
32 #define DIFF_IWHITEALL 0x010 // ignore all white space changes |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
33 #define DIFF_IWHITEEOL 0x020 // ignore change in white space at EOL |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
34 #define DIFF_HORIZONTAL 0x040 // horizontal splits |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
35 #define DIFF_VERTICAL 0x080 // vertical splits |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
36 #define DIFF_HIDDEN_OFF 0x100 // diffoff when hidden |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
37 #define DIFF_INTERNAL 0x200 // use internal xdiff algorithm |
18590
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
38 #define DIFF_CLOSE_OFF 0x400 // diffoff when closing window |
23895
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
39 #define DIFF_FOLLOWWRAP 0x800 // follow the wrap option |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
40 #define ALL_WHITE_DIFF (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL) |
18590
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
41 static int diff_flags = DIFF_INTERNAL | DIFF_FILLER | DIFF_CLOSE_OFF; |
7 | 42 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
43 static long diff_algorithm = 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
44 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
45 #define LBUFLEN 50 // length of line in diff file |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
46 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
47 static int diff_a_works = MAYBE; // TRUE when "diff -a" works, FALSE when it |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
48 // doesn't work, MAYBE when not checked yet |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
49 #if defined(MSWIN) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
50 static int diff_bin_works = MAYBE; // TRUE when "diff --binary" works, FALSE |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
51 // when it doesn't work, MAYBE when not |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
52 // checked yet |
7 | 53 #endif |
54 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
55 // used for diff input |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
56 typedef struct { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
57 char_u *din_fname; // used for external diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
58 mmfile_t din_mmfile; // used for internal diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
59 } diffin_T; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
60 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
61 // used for diff result |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
62 typedef struct { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
63 char_u *dout_fname; // used for external diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
64 garray_T dout_ga; // used for internal diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
65 } diffout_T; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
66 |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
67 // used for recording hunks from xdiff |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
68 typedef struct { |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
69 linenr_T lnum_orig; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
70 long count_orig; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
71 linenr_T lnum_new; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
72 long count_new; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
73 } diffhunk_T; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
74 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
75 // two diff inputs and one result |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
76 typedef struct { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
77 diffin_T dio_orig; // original file input |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
78 diffin_T dio_new; // new file input |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
79 diffout_T dio_diff; // diff result |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
80 int dio_internal; // using internal diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
81 } diffio_T; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
82 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
83 static int diff_buf_idx(buf_T *buf); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
84 static int diff_buf_idx_tp(buf_T *buf, tabpage_T *tp); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
85 static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T line2, long amount, long amount_after); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
86 static void diff_check_unchanged(tabpage_T *tp, diff_T *dp); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
87 static int diff_check_sanity(tabpage_T *tp, diff_T *dp); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
88 static int check_external_diff(diffio_T *diffio); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
89 static int diff_file(diffio_T *diffio); |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
90 static int diff_equal_entry(diff_T *dp, int idx1, int idx2); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
91 static int diff_cmp(char_u *s1, char_u *s2); |
7 | 92 #ifdef FEAT_FOLDING |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
93 static void diff_fold_update(diff_T *dp, int skip_idx); |
7 | 94 #endif |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
95 static void diff_read(int idx_orig, int idx_new, diffio_T *dio); |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
96 static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, int idx_new); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
97 static diff_T *diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp); |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
98 static int parse_diff_ed(char_u *line, diffhunk_T *hunk); |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
99 static int parse_diff_unified(char_u *line, diffhunk_T *hunk); |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
100 static int xdiff_out(long start_a, long count_a, long start_b, long count_b, void *priv); |
7 | 101 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
102 #define FOR_ALL_DIFFBLOCKS_IN_TAB(tp, dp) \ |
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
103 for ((dp) = (tp)->tp_first_diff; (dp) != NULL; (dp) = (dp)->df_next) |
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
104 |
7 | 105 /* |
106 * Called when deleting or unloading a buffer: No longer make a diff with it. | |
107 */ | |
108 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
109 diff_buf_delete(buf_T *buf) |
7 | 110 { |
111 int i; | |
672 | 112 tabpage_T *tp; |
7 | 113 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
114 FOR_ALL_TABPAGES(tp) |
7 | 115 { |
672 | 116 i = diff_buf_idx_tp(buf, tp); |
117 if (i != DB_COUNT) | |
118 { | |
119 tp->tp_diffbuf[i] = NULL; | |
120 tp->tp_diff_invalid = TRUE; | |
1761 | 121 if (tp == curtab) |
122 diff_redraw(TRUE); | |
672 | 123 } |
7 | 124 } |
125 } | |
126 | |
127 /* | |
16 | 128 * Check if the current buffer should be added to or removed from the list of |
129 * diff buffers. | |
130 */ | |
131 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
132 diff_buf_adjust(win_T *win) |
16 | 133 { |
134 win_T *wp; | |
672 | 135 int i; |
16 | 136 |
137 if (!win->w_p_diff) | |
138 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
139 // When there is no window showing a diff for this buffer, remove |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
140 // it from the diffs. |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
141 FOR_ALL_WINDOWS(wp) |
16 | 142 if (wp->w_buffer == win->w_buffer && wp->w_p_diff) |
143 break; | |
144 if (wp == NULL) | |
672 | 145 { |
146 i = diff_buf_idx(win->w_buffer); | |
147 if (i != DB_COUNT) | |
148 { | |
149 curtab->tp_diffbuf[i] = NULL; | |
150 curtab->tp_diff_invalid = TRUE; | |
1761 | 151 diff_redraw(TRUE); |
672 | 152 } |
153 } | |
16 | 154 } |
155 else | |
156 diff_buf_add(win->w_buffer); | |
157 } | |
158 | |
159 /* | |
7 | 160 * Add a buffer to make diffs for. |
672 | 161 * Call this when a new buffer is being edited in the current window where |
162 * 'diff' is set. | |
1788 | 163 * Marks the current buffer as being part of the diff and requiring updating. |
672 | 164 * This must be done before any autocmd, because a command may use info |
165 * about the screen contents. | |
7 | 166 */ |
167 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
168 diff_buf_add(buf_T *buf) |
7 | 169 { |
170 int i; | |
171 | |
172 if (diff_buf_idx(buf) != DB_COUNT) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
173 return; // It's already there. |
7 | 174 |
175 for (i = 0; i < DB_COUNT; ++i) | |
672 | 176 if (curtab->tp_diffbuf[i] == NULL) |
7 | 177 { |
672 | 178 curtab->tp_diffbuf[i] = buf; |
179 curtab->tp_diff_invalid = TRUE; | |
1761 | 180 diff_redraw(TRUE); |
7 | 181 return; |
182 } | |
183 | |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26044
diff
changeset
|
184 semsg(_(e_cannot_diff_more_than_nr_buffers), DB_COUNT); |
7 | 185 } |
186 | |
187 /* | |
10821
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
188 * Remove all buffers to make diffs for. |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
189 */ |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
190 static void |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
191 diff_buf_clear(void) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
192 { |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
193 int i; |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
194 |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
195 for (i = 0; i < DB_COUNT; ++i) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
196 if (curtab->tp_diffbuf[i] != NULL) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
197 { |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
198 curtab->tp_diffbuf[i] = NULL; |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
199 curtab->tp_diff_invalid = TRUE; |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
200 diff_redraw(TRUE); |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
201 } |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
202 } |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
203 |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
204 /* |
672 | 205 * Find buffer "buf" in the list of diff buffers for the current tab page. |
7 | 206 * Return its index or DB_COUNT if not found. |
207 */ | |
208 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
209 diff_buf_idx(buf_T *buf) |
7 | 210 { |
211 int idx; | |
212 | |
213 for (idx = 0; idx < DB_COUNT; ++idx) | |
672 | 214 if (curtab->tp_diffbuf[idx] == buf) |
215 break; | |
216 return idx; | |
217 } | |
218 | |
219 /* | |
220 * Find buffer "buf" in the list of diff buffers for tab page "tp". | |
221 * Return its index or DB_COUNT if not found. | |
222 */ | |
223 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
224 diff_buf_idx_tp(buf_T *buf, tabpage_T *tp) |
672 | 225 { |
226 int idx; | |
227 | |
228 for (idx = 0; idx < DB_COUNT; ++idx) | |
229 if (tp->tp_diffbuf[idx] == buf) | |
7 | 230 break; |
231 return idx; | |
232 } | |
233 | |
234 /* | |
672 | 235 * Mark the diff info involving buffer "buf" as invalid, it will be updated |
236 * when info is requested. | |
7 | 237 */ |
238 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
239 diff_invalidate(buf_T *buf) |
7 | 240 { |
672 | 241 tabpage_T *tp; |
242 int i; | |
243 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
244 FOR_ALL_TABPAGES(tp) |
7 | 245 { |
672 | 246 i = diff_buf_idx_tp(buf, tp); |
247 if (i != DB_COUNT) | |
248 { | |
249 tp->tp_diff_invalid = TRUE; | |
250 if (tp == curtab) | |
251 diff_redraw(TRUE); | |
252 } | |
7 | 253 } |
254 } | |
255 | |
256 /* | |
672 | 257 * Called by mark_adjust(): update line numbers in "curbuf". |
7 | 258 */ |
259 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
260 diff_mark_adjust( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
261 linenr_T line1, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
262 linenr_T line2, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
263 long amount, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
264 long amount_after) |
7 | 265 { |
672 | 266 int idx; |
267 tabpage_T *tp; | |
268 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
269 // Handle all tab pages that use the current buffer in a diff. |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
270 FOR_ALL_TABPAGES(tp) |
672 | 271 { |
272 idx = diff_buf_idx_tp(curbuf, tp); | |
273 if (idx != DB_COUNT) | |
274 diff_mark_adjust_tp(tp, idx, line1, line2, amount, amount_after); | |
275 } | |
276 } | |
277 | |
278 /* | |
279 * Update line numbers in tab page "tp" for "curbuf" with index "idx". | |
280 * This attempts to update the changes as much as possible: | |
281 * When inserting/deleting lines outside of existing change blocks, create a | |
282 * new change block and update the line numbers in following blocks. | |
283 * When inserting/deleting lines in existing change blocks, update them. | |
284 */ | |
285 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
286 diff_mark_adjust_tp( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
287 tabpage_T *tp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
288 int idx, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
289 linenr_T line1, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
290 linenr_T line2, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
291 long amount, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
292 long amount_after) |
672 | 293 { |
7 | 294 diff_T *dp; |
295 diff_T *dprev; | |
296 diff_T *dnext; | |
297 int i; | |
298 int inserted, deleted; | |
299 int n, off; | |
300 linenr_T last; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
301 linenr_T lnum_deleted = line1; // lnum of remaining deletion |
7 | 302 int check_unchanged; |
303 | |
14764
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
304 if (diff_internal()) |
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
305 { |
14780
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
306 // Will update diffs before redrawing. Set _invalid to update the |
14764
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
307 // diffs themselves, set _update to also update folds properly just |
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
308 // before redrawing. |
14972
5d52b21b2e7f
patch 8.1.0497: :%diffput changes order of lines
Bram Moolenaar <Bram@vim.org>
parents:
14893
diff
changeset
|
309 // Do update marks here, it is needed for :%diffput. |
14764
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
310 tp->tp_diff_invalid = TRUE; |
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
311 tp->tp_diff_update = TRUE; |
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
312 } |
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
313 |
7 | 314 if (line2 == MAXLNUM) |
315 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
316 // mark_adjust(99, MAXLNUM, 9, 0): insert lines |
7 | 317 inserted = amount; |
318 deleted = 0; | |
319 } | |
320 else if (amount_after > 0) | |
321 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
322 // mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines |
7 | 323 inserted = amount_after; |
324 deleted = 0; | |
325 } | |
326 else | |
327 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
328 // mark_adjust(98, 99, MAXLNUM, -2): delete lines |
7 | 329 inserted = 0; |
330 deleted = -amount_after; | |
331 } | |
332 | |
333 dprev = NULL; | |
672 | 334 dp = tp->tp_first_diff; |
7 | 335 for (;;) |
336 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
337 // If the change is after the previous diff block and before the next |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
338 // diff block, thus not touching an existing change, create a new diff |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
339 // block. Don't do this when ex_diffgetput() is busy. |
7 | 340 if ((dp == NULL || dp->df_lnum[idx] - 1 > line2 |
341 || (line2 == MAXLNUM && dp->df_lnum[idx] > line1)) | |
342 && (dprev == NULL | |
343 || dprev->df_lnum[idx] + dprev->df_count[idx] < line1) | |
344 && !diff_busy) | |
345 { | |
672 | 346 dnext = diff_alloc_new(tp, dprev, dp); |
7 | 347 if (dnext == NULL) |
348 return; | |
349 | |
350 dnext->df_lnum[idx] = line1; | |
351 dnext->df_count[idx] = inserted; | |
352 for (i = 0; i < DB_COUNT; ++i) | |
672 | 353 if (tp->tp_diffbuf[i] != NULL && i != idx) |
7 | 354 { |
355 if (dprev == NULL) | |
356 dnext->df_lnum[i] = line1; | |
357 else | |
358 dnext->df_lnum[i] = line1 | |
359 + (dprev->df_lnum[i] + dprev->df_count[i]) | |
360 - (dprev->df_lnum[idx] + dprev->df_count[idx]); | |
361 dnext->df_count[i] = deleted; | |
362 } | |
363 } | |
364 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
365 // if at end of the list, quit |
7 | 366 if (dp == NULL) |
367 break; | |
368 | |
369 /* | |
370 * Check for these situations: | |
371 * 1 2 3 | |
372 * 1 2 3 | |
373 * line1 2 3 4 5 | |
374 * 2 3 4 5 | |
375 * 2 3 4 5 | |
376 * line2 2 3 4 5 | |
377 * 3 5 6 | |
378 * 3 5 6 | |
379 */ | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
380 // compute last line of this change |
7 | 381 last = dp->df_lnum[idx] + dp->df_count[idx] - 1; |
382 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
383 // 1. change completely above line1: nothing to do |
7 | 384 if (last >= line1 - 1) |
385 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
386 // 6. change below line2: only adjust for amount_after; also when |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
387 // "deleted" became zero when deleted all lines between two diffs |
7 | 388 if (dp->df_lnum[idx] - (deleted + inserted != 0) > line2) |
389 { | |
390 if (amount_after == 0) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
391 break; // nothing left to change |
7 | 392 dp->df_lnum[idx] += amount_after; |
393 } | |
394 else | |
395 { | |
396 check_unchanged = FALSE; | |
397 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
398 // 2. 3. 4. 5.: inserted/deleted lines touching this diff. |
7 | 399 if (deleted > 0) |
400 { | |
401 if (dp->df_lnum[idx] >= line1) | |
402 { | |
403 off = dp->df_lnum[idx] - lnum_deleted; | |
404 if (last <= line2) | |
405 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
406 // 4. delete all lines of diff |
7 | 407 if (dp->df_next != NULL |
408 && dp->df_next->df_lnum[idx] - 1 <= line2) | |
409 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
410 // delete continues in next diff, only do |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
411 // lines until that one |
7 | 412 n = dp->df_next->df_lnum[idx] - lnum_deleted; |
413 deleted -= n; | |
414 n -= dp->df_count[idx]; | |
415 lnum_deleted = dp->df_next->df_lnum[idx]; | |
416 } | |
417 else | |
418 n = deleted - dp->df_count[idx]; | |
419 dp->df_count[idx] = 0; | |
420 } | |
421 else | |
422 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
423 // 5. delete lines at or just before top of diff |
7 | 424 n = off; |
425 dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1; | |
426 check_unchanged = TRUE; | |
427 } | |
428 dp->df_lnum[idx] = line1; | |
429 } | |
430 else | |
431 { | |
432 off = 0; | |
433 if (last < line2) | |
434 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
435 // 2. delete at end of diff |
7 | 436 dp->df_count[idx] -= last - lnum_deleted + 1; |
437 if (dp->df_next != NULL | |
438 && dp->df_next->df_lnum[idx] - 1 <= line2) | |
439 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
440 // delete continues in next diff, only do |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
441 // lines until that one |
7 | 442 n = dp->df_next->df_lnum[idx] - 1 - last; |
443 deleted -= dp->df_next->df_lnum[idx] | |
444 - lnum_deleted; | |
445 lnum_deleted = dp->df_next->df_lnum[idx]; | |
446 } | |
447 else | |
448 n = line2 - last; | |
449 check_unchanged = TRUE; | |
450 } | |
451 else | |
452 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
453 // 3. delete lines inside the diff |
7 | 454 n = 0; |
455 dp->df_count[idx] -= deleted; | |
456 } | |
457 } | |
458 | |
459 for (i = 0; i < DB_COUNT; ++i) | |
672 | 460 if (tp->tp_diffbuf[i] != NULL && i != idx) |
7 | 461 { |
462 dp->df_lnum[i] -= off; | |
463 dp->df_count[i] += n; | |
464 } | |
465 } | |
466 else | |
467 { | |
468 if (dp->df_lnum[idx] <= line1) | |
469 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
470 // inserted lines somewhere in this diff |
7 | 471 dp->df_count[idx] += inserted; |
472 check_unchanged = TRUE; | |
473 } | |
474 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
475 // inserted lines somewhere above this diff |
7 | 476 dp->df_lnum[idx] += inserted; |
477 } | |
478 | |
479 if (check_unchanged) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
480 // Check if inserted lines are equal, may reduce the |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
481 // size of the diff. TODO: also check for equal lines |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
482 // in the middle and perhaps split the block. |
672 | 483 diff_check_unchanged(tp, dp); |
7 | 484 } |
485 } | |
486 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
487 // check if this block touches the previous one, may merge them. |
7 | 488 if (dprev != NULL && dprev->df_lnum[idx] + dprev->df_count[idx] |
489 == dp->df_lnum[idx]) | |
490 { | |
491 for (i = 0; i < DB_COUNT; ++i) | |
672 | 492 if (tp->tp_diffbuf[i] != NULL) |
7 | 493 dprev->df_count[i] += dp->df_count[i]; |
494 dprev->df_next = dp->df_next; | |
495 vim_free(dp); | |
496 dp = dprev->df_next; | |
497 } | |
498 else | |
499 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
500 // Advance to next entry. |
7 | 501 dprev = dp; |
502 dp = dp->df_next; | |
503 } | |
504 } | |
505 | |
506 dprev = NULL; | |
672 | 507 dp = tp->tp_first_diff; |
7 | 508 while (dp != NULL) |
509 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
510 // All counts are zero, remove this entry. |
7 | 511 for (i = 0; i < DB_COUNT; ++i) |
672 | 512 if (tp->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) |
7 | 513 break; |
514 if (i == DB_COUNT) | |
515 { | |
516 dnext = dp->df_next; | |
517 vim_free(dp); | |
518 dp = dnext; | |
519 if (dprev == NULL) | |
672 | 520 tp->tp_first_diff = dnext; |
7 | 521 else |
522 dprev->df_next = dnext; | |
523 } | |
524 else | |
525 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
526 // Advance to next entry. |
7 | 527 dprev = dp; |
528 dp = dp->df_next; | |
529 } | |
530 | |
531 } | |
672 | 532 |
533 if (tp == curtab) | |
534 { | |
17851
ba63a184e6b6
patch 8.1.1922: in diff mode global operations can be very slow
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
535 // Don't redraw right away, this updates the diffs, which can be slow. |
ba63a184e6b6
patch 8.1.1922: in diff mode global operations can be very slow
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
536 need_diff_redraw = TRUE; |
7 | 537 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
538 // Need to recompute the scroll binding, may remove or add filler |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
539 // lines (e.g., when adding lines above w_topline). But it's slow when |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
540 // making many changes, postpone until redrawing. |
672 | 541 diff_need_scrollbind = TRUE; |
542 } | |
7 | 543 } |
544 | |
545 /* | |
546 * Allocate a new diff block and link it between "dprev" and "dp". | |
547 */ | |
548 static diff_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
549 diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) |
7 | 550 { |
551 diff_T *dnew; | |
552 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16806
diff
changeset
|
553 dnew = ALLOC_ONE(diff_T); |
7 | 554 if (dnew != NULL) |
555 { | |
556 dnew->df_next = dp; | |
557 if (dprev == NULL) | |
672 | 558 tp->tp_first_diff = dnew; |
7 | 559 else |
560 dprev->df_next = dnew; | |
561 } | |
562 return dnew; | |
563 } | |
564 | |
565 /* | |
566 * Check if the diff block "dp" can be made smaller for lines at the start and | |
567 * end that are equal. Called after inserting lines. | |
568 * This may result in a change where all buffers have zero lines, the caller | |
569 * must take care of removing it. | |
570 */ | |
571 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
572 diff_check_unchanged(tabpage_T *tp, diff_T *dp) |
7 | 573 { |
574 int i_org; | |
575 int i_new; | |
576 int off_org, off_new; | |
577 char_u *line_org; | |
578 int dir = FORWARD; | |
579 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
580 // Find the first buffers, use it as the original, compare the other |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
581 // buffer lines against this one. |
7 | 582 for (i_org = 0; i_org < DB_COUNT; ++i_org) |
672 | 583 if (tp->tp_diffbuf[i_org] != NULL) |
7 | 584 break; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
585 if (i_org == DB_COUNT) // safety check |
7 | 586 return; |
587 | |
672 | 588 if (diff_check_sanity(tp, dp) == FAIL) |
7 | 589 return; |
590 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
591 // First check lines at the top, then at the bottom. |
7 | 592 off_org = 0; |
593 off_new = 0; | |
594 for (;;) | |
595 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
596 // Repeat until a line is found which is different or the number of |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
597 // lines has become zero. |
7 | 598 while (dp->df_count[i_org] > 0) |
599 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
600 // Copy the line, the next ml_get() will invalidate it. |
7 | 601 if (dir == BACKWARD) |
602 off_org = dp->df_count[i_org] - 1; | |
672 | 603 line_org = vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], |
7 | 604 dp->df_lnum[i_org] + off_org, FALSE)); |
605 if (line_org == NULL) | |
606 return; | |
607 for (i_new = i_org + 1; i_new < DB_COUNT; ++i_new) | |
608 { | |
672 | 609 if (tp->tp_diffbuf[i_new] == NULL) |
7 | 610 continue; |
611 if (dir == BACKWARD) | |
612 off_new = dp->df_count[i_new] - 1; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
613 // if other buffer doesn't have this line, it was inserted |
7 | 614 if (off_new < 0 || off_new >= dp->df_count[i_new]) |
615 break; | |
672 | 616 if (diff_cmp(line_org, ml_get_buf(tp->tp_diffbuf[i_new], |
7 | 617 dp->df_lnum[i_new] + off_new, FALSE)) != 0) |
618 break; | |
619 } | |
620 vim_free(line_org); | |
621 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
622 // Stop when a line isn't equal in all diff buffers. |
7 | 623 if (i_new != DB_COUNT) |
624 break; | |
625 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
626 // Line matched in all buffers, remove it from the diff. |
7 | 627 for (i_new = i_org; i_new < DB_COUNT; ++i_new) |
672 | 628 if (tp->tp_diffbuf[i_new] != NULL) |
7 | 629 { |
630 if (dir == FORWARD) | |
631 ++dp->df_lnum[i_new]; | |
632 --dp->df_count[i_new]; | |
633 } | |
634 } | |
635 if (dir == BACKWARD) | |
636 break; | |
637 dir = BACKWARD; | |
638 } | |
639 } | |
640 | |
641 /* | |
642 * Check if a diff block doesn't contain invalid line numbers. | |
643 * This can happen when the diff program returns invalid results. | |
644 */ | |
645 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
646 diff_check_sanity(tabpage_T *tp, diff_T *dp) |
7 | 647 { |
648 int i; | |
649 | |
650 for (i = 0; i < DB_COUNT; ++i) | |
672 | 651 if (tp->tp_diffbuf[i] != NULL) |
7 | 652 if (dp->df_lnum[i] + dp->df_count[i] - 1 |
672 | 653 > tp->tp_diffbuf[i]->b_ml.ml_line_count) |
7 | 654 return FAIL; |
655 return OK; | |
656 } | |
657 | |
658 /* | |
672 | 659 * Mark all diff buffers in the current tab page for redraw. |
7 | 660 */ |
17851
ba63a184e6b6
patch 8.1.1922: in diff mode global operations can be very slow
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
661 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
662 diff_redraw( |
14764
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
663 int dofold) // also recompute the folds |
7 | 664 { |
665 win_T *wp; | |
25717
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
666 win_T *wp_other = NULL; |
26044
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
667 int used_max_fill_other = FALSE; |
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
668 int used_max_fill_curwin = FALSE; |
7 | 669 int n; |
670 | |
17851
ba63a184e6b6
patch 8.1.1922: in diff mode global operations can be very slow
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
671 need_diff_redraw = FALSE; |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
672 FOR_ALL_WINDOWS(wp) |
7 | 673 if (wp->w_p_diff) |
674 { | |
738 | 675 redraw_win_later(wp, SOME_VALID); |
25717
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
676 if (wp != curwin) |
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
677 wp_other = wp; |
7 | 678 #ifdef FEAT_FOLDING |
679 if (dofold && foldmethodIsDiff(wp)) | |
680 foldUpdateAll(wp); | |
681 #endif | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
682 // A change may have made filler lines invalid, need to take care |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
683 // of that for other windows. |
3904 | 684 n = diff_check(wp, wp->w_topline); |
685 if ((wp != curwin && wp->w_topfill > 0) || n > 0) | |
7 | 686 { |
687 if (wp->w_topfill > n) | |
688 wp->w_topfill = (n < 0 ? 0 : n); | |
3904 | 689 else if (n > 0 && n > wp->w_topfill) |
25717
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
690 { |
3904 | 691 wp->w_topfill = n; |
25717
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
692 if (wp == curwin) |
26044
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
693 used_max_fill_curwin = TRUE; |
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
694 else if (wp_other != NULL) |
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
695 used_max_fill_other = TRUE; |
25717
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
696 } |
5934 | 697 check_topfill(wp, FALSE); |
7 | 698 } |
699 } | |
25717
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
700 |
26044
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
701 if (wp_other != NULL && curwin->w_p_scb) |
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
702 { |
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
703 if (used_max_fill_curwin) |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
704 // The current window was set to use the maximum number of filler |
26044
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
705 // lines, may need to reduce them. |
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
706 diff_set_topline(wp_other, curwin); |
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
707 else if (used_max_fill_other) |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
708 // The other window was set to use the maximum number of filler |
26044
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
709 // lines, may need to reduce them. |
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
710 diff_set_topline(curwin, wp_other); |
2e8226c03007
patch 8.2.3556: filler lines are incorrect for other window in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25717
diff
changeset
|
711 } |
7 | 712 } |
713 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
714 static void |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
715 clear_diffin(diffin_T *din) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
716 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
717 if (din->din_fname == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
718 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
719 vim_free(din->din_mmfile.ptr); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
720 din->din_mmfile.ptr = NULL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
721 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
722 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
723 mch_remove(din->din_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
724 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
725 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
726 static void |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
727 clear_diffout(diffout_T *dout) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
728 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
729 if (dout->dout_fname == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
730 ga_clear_strings(&dout->dout_ga); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
731 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
732 mch_remove(dout->dout_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
733 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
734 |
7 | 735 /* |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
736 * Write buffer "buf" to a memory buffer. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
737 * Return FAIL for failure. |
7 | 738 */ |
739 static int | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
740 diff_write_buffer(buf_T *buf, diffin_T *din) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
741 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
742 linenr_T lnum; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
743 char_u *s; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
744 long len = 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
745 char_u *ptr; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
746 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
747 // xdiff requires one big block of memory with all the text. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
748 for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) |
14766
7a11facdf74b
patch 8.1.0395: compiler warning on 64-bit MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
14764
diff
changeset
|
749 len += (long)STRLEN(ml_get_buf(buf, lnum, FALSE)) + 1; |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
750 ptr = alloc(len); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
751 if (ptr == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
752 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
753 // Allocating memory failed. This can happen, because we try to read |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
754 // the whole buffer text into memory. Set the failed flag, the diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
755 // will be retried with external diff. The flag is never reset. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
756 buf->b_diff_failed = TRUE; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
757 if (p_verbose > 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
758 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
759 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
760 smsg(_("Not enough memory to use internal diff for buffer \"%s\""), |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
761 buf->b_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
762 verbose_leave(); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
763 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
764 return FAIL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
765 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
766 din->din_mmfile.ptr = (char *)ptr; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
767 din->din_mmfile.size = len; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
768 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
769 len = 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
770 for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
771 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
772 for (s = ml_get_buf(buf, lnum, FALSE); *s != NUL; ) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
773 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
774 if (diff_flags & DIFF_ICASE) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
775 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
776 int c; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
777 int orig_len; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
778 char_u cbuf[MB_MAXBYTES + 1]; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
779 |
26794
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
780 if (*s == NL) |
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
781 c = NUL; |
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
782 else |
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
783 { |
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
784 // xdiff doesn't support ignoring case, fold-case the text. |
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
785 c = PTR2CHAR(s); |
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
786 c = MB_CASEFOLD(c); |
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
787 } |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
788 orig_len = mb_ptr2len(s); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
789 if (mb_char2bytes(c, cbuf) != orig_len) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
790 // TODO: handle byte length difference |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
791 mch_memmove(ptr + len, s, orig_len); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
792 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
793 mch_memmove(ptr + len, cbuf, orig_len); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
794 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
795 s += orig_len; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
796 len += orig_len; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
797 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
798 else |
26794
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
799 { |
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
800 ptr[len++] = *s == NL ? NUL : *s; |
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
801 s++; |
83a99f08d1e8
patch 8.2.3925: diff mode confused by NUL bytes
Bram Moolenaar <Bram@vim.org>
parents:
26786
diff
changeset
|
802 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
803 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
804 ptr[len++] = NL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
805 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
806 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
807 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
808 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
809 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
810 * Write buffer "buf" to file or memory buffer. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
811 * Return FAIL for failure. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
812 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
813 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
814 diff_write(buf_T *buf, diffin_T *din) |
7 | 815 { |
816 int r; | |
817 char_u *save_ff; | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
818 int save_cmod_flags; |
7 | 819 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
820 if (din->din_fname == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
821 return diff_write_buffer(buf, din); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
822 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
823 // Always use 'fileformat' set to "unix". |
7 | 824 save_ff = buf->b_p_ff; |
825 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
826 save_cmod_flags = cmdmod.cmod_flags; |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18590
diff
changeset
|
827 // Writing the buffer is an implementation detail of performing the diff, |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18590
diff
changeset
|
828 // so it shouldn't update the '[ and '] marks. |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
829 cmdmod.cmod_flags |= CMOD_LOCKMARKS; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
830 r = buf_write(buf, din->din_fname, NULL, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
831 (linenr_T)1, buf->b_ml.ml_line_count, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
832 NULL, FALSE, FALSE, FALSE, TRUE); |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
833 cmdmod.cmod_flags = save_cmod_flags; |
7 | 834 free_string_option(buf->b_p_ff); |
835 buf->b_p_ff = save_ff; | |
836 return r; | |
837 } | |
838 | |
839 /* | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
840 * Update the diffs for all buffers involved. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
841 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
842 static void |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
843 diff_try_update( |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
844 diffio_T *dio, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
845 int idx_orig, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
846 exarg_T *eap) // "eap" can be NULL |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
847 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
848 buf_T *buf; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
849 int idx_new; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
850 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
851 if (dio->dio_internal) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
852 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
853 ga_init2(&dio->dio_diff.dout_ga, sizeof(char *), 1000); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
854 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
855 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
856 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
857 // We need three temp file names. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
858 dio->dio_orig.din_fname = vim_tempname('o', TRUE); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
859 dio->dio_new.din_fname = vim_tempname('n', TRUE); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
860 dio->dio_diff.dout_fname = vim_tempname('d', TRUE); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
861 if (dio->dio_orig.din_fname == NULL |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
862 || dio->dio_new.din_fname == NULL |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
863 || dio->dio_diff.dout_fname == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
864 goto theend; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
865 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
866 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
867 // Check external diff is actually working. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
868 if (!dio->dio_internal && check_external_diff(dio) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
869 goto theend; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
870 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
871 // :diffupdate! |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
872 if (eap != NULL && eap->forceit) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
873 for (idx_new = idx_orig; idx_new < DB_COUNT; ++idx_new) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
874 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
875 buf = curtab->tp_diffbuf[idx_new]; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
876 if (buf_valid(buf)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
877 buf_check_timestamp(buf, FALSE); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
878 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
879 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
880 // Write the first buffer to a tempfile or mmfile_t. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
881 buf = curtab->tp_diffbuf[idx_orig]; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
882 if (diff_write(buf, &dio->dio_orig) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
883 goto theend; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
884 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
885 // Make a difference between the first buffer and every other. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
886 for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
887 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
888 buf = curtab->tp_diffbuf[idx_new]; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
889 if (buf == NULL || buf->b_ml.ml_mfp == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
890 continue; // skip buffer that isn't loaded |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
891 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
892 // Write the other buffer and diff with the first one. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
893 if (diff_write(buf, &dio->dio_new) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
894 continue; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
895 if (diff_file(dio) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
896 continue; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
897 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
898 // Read the diff output and add each entry to the diff list. |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
899 diff_read(idx_orig, idx_new, dio); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
900 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
901 clear_diffin(&dio->dio_new); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
902 clear_diffout(&dio->dio_diff); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
903 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
904 clear_diffin(&dio->dio_orig); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
905 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
906 theend: |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
907 vim_free(dio->dio_orig.din_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
908 vim_free(dio->dio_new.din_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
909 vim_free(dio->dio_diff.dout_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
910 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
911 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
912 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
913 * Return TRUE if the options are set to use the internal diff library. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
914 * Note that if the internal diff failed for one of the buffers, the external |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
915 * diff will be used anyway. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
916 */ |
14764
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
917 int |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
918 diff_internal(void) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
919 { |
15971
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15900
diff
changeset
|
920 return (diff_flags & DIFF_INTERNAL) != 0 |
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15900
diff
changeset
|
921 #ifdef FEAT_EVAL |
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15900
diff
changeset
|
922 && *p_dex == NUL |
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15900
diff
changeset
|
923 #endif |
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15900
diff
changeset
|
924 ; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
925 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
926 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
927 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
928 * Return TRUE if the internal diff failed for one of the diff buffers. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
929 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
930 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
931 diff_internal_failed(void) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
932 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
933 int idx; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
934 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
935 // Only need to do something when there is another buffer. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
936 for (idx = 0; idx < DB_COUNT; ++idx) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
937 if (curtab->tp_diffbuf[idx] != NULL |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
938 && curtab->tp_diffbuf[idx]->b_diff_failed) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
939 return TRUE; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
940 return FALSE; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
941 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
942 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
943 /* |
7 | 944 * Completely update the diffs for the buffers involved. |
14764
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
945 * When using the external "diff" command the buffers are written to a file, |
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
946 * also for unmodified buffers (the file could have been produced by |
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
947 * autocommands, e.g. the netrw plugin). |
7 | 948 */ |
949 void | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
950 ex_diffupdate(exarg_T *eap) // "eap" can be NULL |
7 | 951 { |
952 int idx_orig; | |
953 int idx_new; | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
954 diffio_T diffio; |
14780
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
955 int had_diffs = curtab->tp_first_diff != NULL; |
7 | 956 |
14776
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
957 if (diff_busy) |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
958 { |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
959 diff_need_update = TRUE; |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
960 return; |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
961 } |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
962 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
963 // Delete all diffblocks. |
672 | 964 diff_clear(curtab); |
965 curtab->tp_diff_invalid = FALSE; | |
7 | 966 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
967 // Use the first buffer as the original text. |
7 | 968 for (idx_orig = 0; idx_orig < DB_COUNT; ++idx_orig) |
672 | 969 if (curtab->tp_diffbuf[idx_orig] != NULL) |
7 | 970 break; |
971 if (idx_orig == DB_COUNT) | |
14780
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
972 goto theend; |
7 | 973 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
974 // Only need to do something when there is another buffer. |
7 | 975 for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) |
672 | 976 if (curtab->tp_diffbuf[idx_new] != NULL) |
7 | 977 break; |
978 if (idx_new == DB_COUNT) | |
14780
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
979 goto theend; |
7 | 980 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
981 // Only use the internal method if it did not fail for one of the buffers. |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
982 CLEAR_FIELD(diffio); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
983 diffio.dio_internal = diff_internal() && !diff_internal_failed(); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
984 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
985 diff_try_update(&diffio, idx_orig, eap); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
986 if (diffio.dio_internal && diff_internal_failed()) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
987 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
988 // Internal diff failed, use external diff instead. |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
989 CLEAR_FIELD(diffio); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
990 diff_try_update(&diffio, idx_orig, eap); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
991 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
992 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
993 // force updating cursor position on screen |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
994 curwin->w_valid_cursor.lnum = 0; |
7 | 995 |
14780
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
996 theend: |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
997 // A redraw is needed if there were diffs and they were cleared, or there |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
998 // are diffs now, which means they got updated. |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
999 if (had_diffs || curtab->tp_first_diff != NULL) |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
1000 { |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
1001 diff_redraw(TRUE); |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
1002 apply_autocmds(EVENT_DIFFUPDATED, NULL, NULL, FALSE, curbuf); |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
1003 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1004 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1005 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1006 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1007 * Do a quick test if "diff" really works. Otherwise it looks like there |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1008 * are no differences. Can't use the return value, it's non-zero when |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1009 * there are differences. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1010 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1011 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1012 check_external_diff(diffio_T *diffio) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1013 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1014 FILE *fd; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1015 int ok; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1016 int io_error = FALSE; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1017 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1018 // May try twice, first with "-a" and then without. |
7 | 1019 for (;;) |
1020 { | |
1021 ok = FALSE; | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1022 fd = mch_fopen((char *)diffio->dio_orig.din_fname, "w"); |
1757 | 1023 if (fd == NULL) |
1024 io_error = TRUE; | |
1025 else | |
7 | 1026 { |
1757 | 1027 if (fwrite("line1\n", (size_t)6, (size_t)1, fd) != 1) |
1028 io_error = TRUE; | |
7 | 1029 fclose(fd); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1030 fd = mch_fopen((char *)diffio->dio_new.din_fname, "w"); |
1757 | 1031 if (fd == NULL) |
1032 io_error = TRUE; | |
1033 else | |
7 | 1034 { |
1757 | 1035 if (fwrite("line2\n", (size_t)6, (size_t)1, fd) != 1) |
1036 io_error = TRUE; | |
7 | 1037 fclose(fd); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1038 fd = NULL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1039 if (diff_file(diffio) == OK) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1040 fd = mch_fopen((char *)diffio->dio_diff.dout_fname, "r"); |
1757 | 1041 if (fd == NULL) |
1042 io_error = TRUE; | |
1043 else | |
7 | 1044 { |
1045 char_u linebuf[LBUFLEN]; | |
1046 | |
1047 for (;;) | |
1048 { | |
24683
05c199ea8295
patch 8.2.2880: unified diff fails if actually used
Bram Moolenaar <Bram@vim.org>
parents:
23895
diff
changeset
|
1049 // For normal diff there must be a line that contains |
05c199ea8295
patch 8.2.2880: unified diff fails if actually used
Bram Moolenaar <Bram@vim.org>
parents:
23895
diff
changeset
|
1050 // "1c1". For unified diff "@@ -1 +1 @@". |
15840
734b1928a5aa
patch 8.1.0927: USE_CR is never defined
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
1051 if (vim_fgets(linebuf, LBUFLEN, fd)) |
7 | 1052 break; |
24683
05c199ea8295
patch 8.2.2880: unified diff fails if actually used
Bram Moolenaar <Bram@vim.org>
parents:
23895
diff
changeset
|
1053 if (STRNCMP(linebuf, "1c1", 3) == 0 |
05c199ea8295
patch 8.2.2880: unified diff fails if actually used
Bram Moolenaar <Bram@vim.org>
parents:
23895
diff
changeset
|
1054 || STRNCMP(linebuf, "@@ -1 +1 @@", 11) == 0) |
7 | 1055 ok = TRUE; |
1056 } | |
1057 fclose(fd); | |
1058 } | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1059 mch_remove(diffio->dio_diff.dout_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1060 mch_remove(diffio->dio_new.din_fname); |
7 | 1061 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1062 mch_remove(diffio->dio_orig.din_fname); |
7 | 1063 } |
1064 | |
1065 #ifdef FEAT_EVAL | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1066 // When using 'diffexpr' break here. |
7 | 1067 if (*p_dex != NUL) |
1068 break; | |
1069 #endif | |
1070 | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1071 #if defined(MSWIN) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1072 // If the "-a" argument works, also check if "--binary" works. |
7 | 1073 if (ok && diff_a_works == MAYBE && diff_bin_works == MAYBE) |
1074 { | |
1075 diff_a_works = TRUE; | |
1076 diff_bin_works = TRUE; | |
1077 continue; | |
1078 } | |
1079 if (!ok && diff_a_works == TRUE && diff_bin_works == TRUE) | |
1080 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1081 // Tried --binary, but it failed. "-a" works though. |
7 | 1082 diff_bin_works = FALSE; |
1083 ok = TRUE; | |
1084 } | |
1085 #endif | |
1086 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1087 // If we checked if "-a" works already, break here. |
7 | 1088 if (diff_a_works != MAYBE) |
1089 break; | |
1090 diff_a_works = ok; | |
1091 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1092 // If "-a" works break here, otherwise retry without "-a". |
7 | 1093 if (ok) |
1094 break; | |
1095 } | |
1096 if (!ok) | |
1097 { | |
1757 | 1098 if (io_error) |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
1099 emsg(_(e_cannot_read_or_write_temp_files)); |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26044
diff
changeset
|
1100 emsg(_(e_cannot_create_diffs)); |
7 | 1101 diff_a_works = MAYBE; |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1102 #if defined(MSWIN) |
7 | 1103 diff_bin_works = MAYBE; |
1104 #endif | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1105 return FAIL; |
7 | 1106 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1107 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1108 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1109 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1110 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1111 * Invoke the xdiff function. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1112 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1113 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1114 diff_file_internal(diffio_T *diffio) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1115 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1116 xpparam_t param; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1117 xdemitconf_t emit_cfg; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1118 xdemitcb_t emit_cb; |
7 | 1119 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1120 CLEAR_FIELD(param); |
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1121 CLEAR_FIELD(emit_cfg); |
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1122 CLEAR_FIELD(emit_cb); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1123 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1124 param.flags = diff_algorithm; |
3524 | 1125 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1126 if (diff_flags & DIFF_IWHITE) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1127 param.flags |= XDF_IGNORE_WHITESPACE_CHANGE; |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
1128 if (diff_flags & DIFF_IWHITEALL) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
1129 param.flags |= XDF_IGNORE_WHITESPACE; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
1130 if (diff_flags & DIFF_IWHITEEOL) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
1131 param.flags |= XDF_IGNORE_WHITESPACE_AT_EOL; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
1132 if (diff_flags & DIFF_IBLANK) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
1133 param.flags |= XDF_IGNORE_BLANK_LINES; |
7 | 1134 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1135 emit_cfg.ctxlen = 0; // don't need any diff_context here |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1136 emit_cb.priv = &diffio->dio_diff; |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1137 emit_cfg.hunk_func = xdiff_out; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1138 if (xdl_diff(&diffio->dio_orig.din_mmfile, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1139 &diffio->dio_new.din_mmfile, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1140 ¶m, &emit_cfg, &emit_cb) < 0) |
7 | 1141 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
1142 emsg(_(e_problem_creating_internal_diff)); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1143 return FAIL; |
7 | 1144 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1145 return OK; |
7 | 1146 } |
1147 | |
1148 /* | |
1149 * Make a diff between files "tmp_orig" and "tmp_new", results in "tmp_diff". | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1150 * return OK or FAIL; |
7 | 1151 */ |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1152 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1153 diff_file(diffio_T *dio) |
7 | 1154 { |
1155 char_u *cmd; | |
1872 | 1156 size_t len; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1157 char_u *tmp_orig = dio->dio_orig.din_fname; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1158 char_u *tmp_new = dio->dio_new.din_fname; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1159 char_u *tmp_diff = dio->dio_diff.dout_fname; |
7 | 1160 |
1161 #ifdef FEAT_EVAL | |
1162 if (*p_dex != NUL) | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1163 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1164 // Use 'diffexpr' to generate the diff file. |
7 | 1165 eval_diff(tmp_orig, tmp_new, tmp_diff); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1166 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1167 } |
7 | 1168 else |
1169 #endif | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1170 // Use xdiff for generating the diff. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1171 if (dio->dio_internal) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1172 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1173 return diff_file_internal(dio); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1174 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1175 else |
7 | 1176 { |
1872 | 1177 len = STRLEN(tmp_orig) + STRLEN(tmp_new) |
1178 + STRLEN(tmp_diff) + STRLEN(p_srr) + 27; | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
15971
diff
changeset
|
1179 cmd = alloc(len); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1180 if (cmd == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1181 return FAIL; |
193 | 1182 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1183 // We don't want $DIFF_OPTIONS to get in the way. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1184 if (getenv("DIFF_OPTIONS")) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1185 vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)""); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1186 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1187 // Build the diff command and execute it. Always use -a, binary |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1188 // differences are of no use. Ignore errors, diff returns |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1189 // non-zero when differences have been found. |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
1190 vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s%s%s%s %s", |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1191 diff_a_works == FALSE ? "" : "-a ", |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1192 #if defined(MSWIN) |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1193 diff_bin_works == TRUE ? "--binary " : "", |
7 | 1194 #else |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1195 "", |
7 | 1196 #endif |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1197 (diff_flags & DIFF_IWHITE) ? "-b " : "", |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
1198 (diff_flags & DIFF_IWHITEALL) ? "-w " : "", |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
1199 (diff_flags & DIFF_IWHITEEOL) ? "-Z " : "", |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
1200 (diff_flags & DIFF_IBLANK) ? "-B " : "", |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1201 (diff_flags & DIFF_ICASE) ? "-i " : "", |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1202 tmp_orig, tmp_new); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1203 append_redir(cmd, (int)len, p_srr, tmp_diff); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1204 block_autocmds(); // avoid ShellCmdPost stuff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1205 (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1206 unblock_autocmds(); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1207 vim_free(cmd); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1208 return OK; |
7 | 1209 } |
1210 } | |
1211 | |
1212 /* | |
1213 * Create a new version of a file from the current buffer and a diff file. | |
1214 * The buffer is written to a file, also for unmodified buffers (the file | |
1215 * could have been produced by autocommands, e.g. the netrw plugin). | |
1216 */ | |
1217 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1218 ex_diffpatch(exarg_T *eap) |
7 | 1219 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1220 char_u *tmp_orig; // name of original temp file |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1221 char_u *tmp_new; // name of patched temp file |
7 | 1222 char_u *buf = NULL; |
1872 | 1223 size_t buflen; |
7 | 1224 win_T *old_curwin = curwin; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1225 char_u *newname = NULL; // name of patched file buffer |
7 | 1226 #ifdef UNIX |
1227 char_u dirbuf[MAXPATHL]; | |
1228 char_u *fullname = NULL; | |
1229 #endif | |
1230 #ifdef FEAT_BROWSE | |
1231 char_u *browseFile = NULL; | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
1232 int save_cmod_flags = cmdmod.cmod_flags; |
7 | 1233 #endif |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
1234 stat_T st; |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1235 char_u *esc_name = NULL; |
7 | 1236 |
1237 #ifdef FEAT_BROWSE | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
1238 if (cmdmod.cmod_flags & CMOD_BROWSE) |
7 | 1239 { |
28 | 1240 browseFile = do_browse(0, (char_u *)_("Patch file"), |
13802
378f9f8e6d8f
patch 8.0.1773: dialog messages are not translated
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1241 eap->arg, NULL, NULL, |
378f9f8e6d8f
patch 8.0.1773: dialog messages are not translated
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1242 (char_u *)_(BROWSE_FILTER_ALL_FILES), NULL); |
7 | 1243 if (browseFile == NULL) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1244 return; // operation cancelled |
7 | 1245 eap->arg = browseFile; |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
1246 cmdmod.cmod_flags &= ~CMOD_BROWSE; // don't let do_ecmd() browse again |
7 | 1247 } |
1248 #endif | |
1249 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1250 // We need two temp file names. |
6721 | 1251 tmp_orig = vim_tempname('o', FALSE); |
1252 tmp_new = vim_tempname('n', FALSE); | |
7 | 1253 if (tmp_orig == NULL || tmp_new == NULL) |
1254 goto theend; | |
1255 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1256 // Write the current buffer to "tmp_orig". |
7 | 1257 if (buf_write(curbuf, tmp_orig, NULL, |
1258 (linenr_T)1, curbuf->b_ml.ml_line_count, | |
1259 NULL, FALSE, FALSE, FALSE, TRUE) == FAIL) | |
1260 goto theend; | |
1261 | |
1262 #ifdef UNIX | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1263 // Get the absolute path of the patchfile, changing directory below. |
7 | 1264 fullname = FullName_save(eap->arg, FALSE); |
1265 #endif | |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1266 esc_name = vim_strsave_shellescape( |
7 | 1267 # ifdef UNIX |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1268 fullname != NULL ? fullname : |
7 | 1269 # endif |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1270 eap->arg, TRUE, TRUE); |
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1271 if (esc_name == NULL) |
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1272 goto theend; |
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1273 buflen = STRLEN(tmp_orig) + STRLEN(esc_name) + STRLEN(tmp_new) + 16; |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
15971
diff
changeset
|
1274 buf = alloc(buflen); |
7 | 1275 if (buf == NULL) |
1276 goto theend; | |
1277 | |
1278 #ifdef UNIX | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1279 // Temporarily chdir to /tmp, to avoid patching files in the current |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1280 // directory when the patch file contains more than one patch. When we |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1281 // have our own temp dir use that instead, it will be cleaned up when we |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1282 // exit (any .rej files created). Don't change directory if we can't |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1283 // return to the current. |
7 | 1284 if (mch_dirname(dirbuf, MAXPATHL) != OK || mch_chdir((char *)dirbuf) != 0) |
1285 dirbuf[0] = NUL; | |
1286 else | |
1287 { | |
1288 # ifdef TEMPDIRNAMES | |
1289 if (vim_tempdir != NULL) | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14726
diff
changeset
|
1290 vim_ignored = mch_chdir((char *)vim_tempdir); |
7 | 1291 else |
1292 # endif | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14726
diff
changeset
|
1293 vim_ignored = mch_chdir("/tmp"); |
7 | 1294 shorten_fnames(TRUE); |
1295 } | |
1296 #endif | |
1297 | |
1298 #ifdef FEAT_EVAL | |
1299 if (*p_pex != NUL) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1300 // Use 'patchexpr' to generate the new file. |
7 | 1301 eval_patch(tmp_orig, |
1302 # ifdef UNIX | |
1303 fullname != NULL ? fullname : | |
1304 # endif | |
1305 eap->arg, tmp_new); | |
1306 else | |
1307 #endif | |
1308 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1309 // Build the patch command and execute it. Ignore errors. Switch to |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1310 // cooked mode to allow the user to respond to prompts. |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1311 vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s", |
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1312 tmp_new, tmp_orig, esc_name); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1313 block_autocmds(); // Avoid ShellCmdPost stuff |
7 | 1314 (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED); |
1410 | 1315 unblock_autocmds(); |
7 | 1316 } |
1317 | |
1318 #ifdef UNIX | |
1319 if (dirbuf[0] != NUL) | |
1320 { | |
1321 if (mch_chdir((char *)dirbuf) != 0) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26829
diff
changeset
|
1322 emsg(_(e_cannot_go_back_to_previous_directory)); |
7 | 1323 shorten_fnames(TRUE); |
1324 } | |
1325 #endif | |
1326 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1327 // patch probably has written over the screen |
7 | 1328 redraw_later(CLEAR); |
1329 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1330 // Delete any .orig or .rej file created. |
7 | 1331 STRCPY(buf, tmp_new); |
1332 STRCAT(buf, ".orig"); | |
1333 mch_remove(buf); | |
1334 STRCPY(buf, tmp_new); | |
1335 STRCAT(buf, ".rej"); | |
1336 mch_remove(buf); | |
1337 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1338 // Only continue if the output file was created. |
1942 | 1339 if (mch_stat((char *)tmp_new, &st) < 0 || st.st_size == 0) |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
1340 emsg(_(e_cannot_read_patch_output)); |
1942 | 1341 else |
7 | 1342 { |
1942 | 1343 if (curbuf->b_fname != NULL) |
1344 { | |
1345 newname = vim_strnsave(curbuf->b_fname, | |
20751
d9a2e5dcfd9f
patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
1346 STRLEN(curbuf->b_fname) + 4); |
1942 | 1347 if (newname != NULL) |
1348 STRCAT(newname, ".new"); | |
1349 } | |
7 | 1350 |
1351 #ifdef FEAT_GUI | |
1942 | 1352 need_mouse_correct = TRUE; |
7 | 1353 #endif |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1354 // don't use a new tab page, each tab page has its own diffs |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
1355 cmdmod.cmod_tab = 0; |
682 | 1356 |
1942 | 1357 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) |
1358 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1359 // Pretend it was a ":split fname" command |
1942 | 1360 eap->cmdidx = CMD_split; |
1361 eap->arg = tmp_new; | |
1362 do_exedit(eap, old_curwin); | |
7 | 1363 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1364 // check that split worked and editing tmp_new |
1942 | 1365 if (curwin != old_curwin && win_valid(old_curwin)) |
1366 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1367 // Set 'diff', 'scrollbind' on and 'wrap' off. |
1942 | 1368 diff_win_options(curwin, TRUE); |
1369 diff_win_options(old_curwin, TRUE); | |
7 | 1370 |
1942 | 1371 if (newname != NULL) |
1372 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1373 // do a ":file filename.new" on the patched buffer |
1942 | 1374 eap->arg = newname; |
1375 ex_file(eap); | |
7 | 1376 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1377 // Do filetype detection with the new name. |
1942 | 1378 if (au_has_group((char_u *)"filetypedetect")) |
1379 do_cmdline_cmd((char_u *)":doau filetypedetect BufRead"); | |
1380 } | |
7 | 1381 } |
1382 } | |
1383 } | |
1384 | |
1385 theend: | |
1386 if (tmp_orig != NULL) | |
1387 mch_remove(tmp_orig); | |
1388 vim_free(tmp_orig); | |
1389 if (tmp_new != NULL) | |
1390 mch_remove(tmp_new); | |
1391 vim_free(tmp_new); | |
1392 vim_free(newname); | |
1393 vim_free(buf); | |
1394 #ifdef UNIX | |
1395 vim_free(fullname); | |
1396 #endif | |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1397 vim_free(esc_name); |
7 | 1398 #ifdef FEAT_BROWSE |
1399 vim_free(browseFile); | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
1400 cmdmod.cmod_flags = save_cmod_flags; |
7 | 1401 #endif |
1402 } | |
1403 | |
1404 /* | |
1405 * Split the window and edit another file, setting options to show the diffs. | |
1406 */ | |
1407 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1408 ex_diffsplit(exarg_T *eap) |
7 | 1409 { |
1410 win_T *old_curwin = curwin; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1411 bufref_T old_curbuf; |
7 | 1412 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1413 set_bufref(&old_curbuf, curbuf); |
7 | 1414 #ifdef FEAT_GUI |
1415 need_mouse_correct = TRUE; | |
1416 #endif | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1417 // Need to compute w_fraction when no redraw happened yet. |
10013
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1418 validate_cursor(); |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1419 set_fraction(curwin); |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1420 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1421 // don't use a new tab page, each tab page has its own diffs |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
1422 cmdmod.cmod_tab = 0; |
682 | 1423 |
764 | 1424 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) |
7 | 1425 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1426 // Pretend it was a ":split fname" command |
7 | 1427 eap->cmdidx = CMD_split; |
449 | 1428 curwin->w_p_diff = TRUE; |
7 | 1429 do_exedit(eap, old_curwin); |
1430 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1431 if (curwin != old_curwin) // split must have worked |
7 | 1432 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1433 // Set 'diff', 'scrollbind' on and 'wrap' off. |
7 | 1434 diff_win_options(curwin, TRUE); |
7338
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1435 if (win_valid(old_curwin)) |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1436 { |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1437 diff_win_options(old_curwin, TRUE); |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1438 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1439 if (bufref_valid(&old_curbuf)) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1440 // Move the cursor position to that of the old window. |
7338
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1441 curwin->w_cursor.lnum = diff_get_corresponding_line( |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1442 old_curbuf.br_buf, old_curwin->w_cursor.lnum); |
7338
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1443 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1444 // Now that lines are folded scroll to show the cursor at the same |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1445 // relative position. |
10013
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1446 scroll_to_fraction(curwin, curwin->w_height); |
7 | 1447 } |
1448 } | |
1449 } | |
1450 | |
1451 /* | |
4352 | 1452 * Set options to show diffs for the current window. |
7 | 1453 */ |
1454 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1455 ex_diffthis(exarg_T *eap UNUSED) |
7 | 1456 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1457 // Set 'diff', 'scrollbind' on and 'wrap' off. |
7 | 1458 diff_win_options(curwin, TRUE); |
1459 } | |
1460 | |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1461 static void |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1462 set_diff_option(win_T *wp, int value) |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1463 { |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1464 win_T *old_curwin = curwin; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1465 |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1466 curwin = wp; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1467 curbuf = curwin->w_buffer; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1468 ++curbuf_lock; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1469 set_option_value((char_u *)"diff", (long)value, NULL, OPT_LOCAL); |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1470 --curbuf_lock; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1471 curwin = old_curwin; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1472 curbuf = curwin->w_buffer; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1473 } |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1474 |
7 | 1475 /* |
1476 * Set options in window "wp" for diff mode. | |
1477 */ | |
1478 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1479 diff_win_options( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1480 win_T *wp, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1481 int addbuf) // Add buffer to diff. |
7 | 1482 { |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1483 # ifdef FEAT_FOLDING |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1484 win_T *old_curwin = curwin; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1485 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1486 // close the manually opened folds |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1487 curwin = wp; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1488 newFoldLevel(); |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1489 curwin = old_curwin; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1490 # endif |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1491 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1492 // Use 'scrollbind' and 'cursorbind' when available |
6897 | 1493 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1494 wp->w_p_scb_save = wp->w_p_scb; |
2583 | 1495 wp->w_p_scb = TRUE; |
6897 | 1496 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1497 wp->w_p_crb_save = wp->w_p_crb; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
1498 wp->w_p_crb = TRUE; |
23895
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1499 if (!(diff_flags & DIFF_FOLLOWWRAP)) |
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1500 { |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1501 if (!wp->w_p_diff) |
23895
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1502 wp->w_p_wrap_save = wp->w_p_wrap; |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1503 wp->w_p_wrap = FALSE; |
23895
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1504 } |
7 | 1505 # ifdef FEAT_FOLDING |
6897 | 1506 if (!wp->w_p_diff) |
1507 { | |
1508 if (wp->w_p_diff_saved) | |
1509 free_string_option(wp->w_p_fdm_save); | |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1510 wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm); |
6897 | 1511 } |
16806
306766ed0f70
patch 8.1.1405: "highlight" option of popup windows not supported
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1512 set_string_option_direct_in_win(wp, (char_u *)"fdm", -1, (char_u *)"diff", |
694 | 1513 OPT_LOCAL|OPT_FREE, 0); |
6897 | 1514 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1515 { |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1516 wp->w_p_fdc_save = wp->w_p_fdc; |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1517 wp->w_p_fen_save = wp->w_p_fen; |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1518 wp->w_p_fdl_save = wp->w_p_fdl; |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1519 } |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1520 wp->w_p_fdc = diff_foldcolumn; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1521 wp->w_p_fen = TRUE; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1522 wp->w_p_fdl = 0; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1523 foldUpdateAll(wp); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1524 // make sure topline is not halfway a fold |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1525 changed_window_setting_win(wp); |
7 | 1526 # endif |
1527 if (vim_strchr(p_sbo, 'h') == NULL) | |
1528 do_cmdline_cmd((char_u *)"set sbo+=hor"); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1529 // Save the current values, to be restored in ex_diffoff(). |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1530 wp->w_p_diff_saved = TRUE; |
7 | 1531 |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1532 set_diff_option(wp, TRUE); |
6897 | 1533 |
7 | 1534 if (addbuf) |
1535 diff_buf_add(wp->w_buffer); | |
1536 redraw_win_later(wp, NOT_VALID); | |
1537 } | |
1538 | |
1539 /* | |
16 | 1540 * Set options not to show diffs. For the current window or all windows. |
671 | 1541 * Only in the current tab page. |
16 | 1542 */ |
1543 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1544 ex_diffoff(exarg_T *eap) |
16 | 1545 { |
1546 win_T *wp; | |
1547 int diffwin = FALSE; | |
1548 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1549 FOR_ALL_WINDOWS(wp) |
16 | 1550 { |
5358 | 1551 if (eap->forceit ? wp->w_p_diff : wp == curwin) |
16 | 1552 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1553 // Set 'diff' off. If option values were saved in |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1554 // diff_win_options(), restore the ones whose settings seem to have |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1555 // been left over from diff mode. |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1556 set_diff_option(wp, FALSE); |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1557 |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1558 if (wp->w_p_diff_saved) |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1559 { |
6897 | 1560 |
1561 if (wp->w_p_scb) | |
1562 wp->w_p_scb = wp->w_p_scb_save; | |
1563 if (wp->w_p_crb) | |
1564 wp->w_p_crb = wp->w_p_crb_save; | |
23895
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1565 if (!(diff_flags & DIFF_FOLLOWWRAP)) |
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1566 { |
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1567 if (!wp->w_p_wrap) |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1568 wp->w_p_wrap = wp->w_p_wrap_save; |
23895
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1569 } |
6897 | 1570 #ifdef FEAT_FOLDING |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1571 free_string_option(wp->w_p_fdm); |
11430
eba1a8c6e21d
patch 8.0.0599: diff mode is insufficiently tested
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1572 wp->w_p_fdm = vim_strsave( |
eba1a8c6e21d
patch 8.0.0599: diff mode is insufficiently tested
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1573 *wp->w_p_fdm_save ? wp->w_p_fdm_save : (char_u*)"manual"); |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1574 |
6897 | 1575 if (wp->w_p_fdc == diff_foldcolumn) |
1576 wp->w_p_fdc = wp->w_p_fdc_save; | |
1577 if (wp->w_p_fdl == 0) | |
1578 wp->w_p_fdl = wp->w_p_fdl_save; | |
1579 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1580 // Only restore 'foldenable' when 'foldmethod' is not |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1581 // "manual", otherwise we continue to show the diff folds. |
6897 | 1582 if (wp->w_p_fen) |
1583 wp->w_p_fen = foldmethodIsManual(wp) ? FALSE | |
1584 : wp->w_p_fen_save; | |
1585 | |
1586 foldUpdateAll(wp); | |
1587 #endif | |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1588 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1589 // remove filler lines |
10005
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1590 wp->w_topfill = 0; |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1591 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1592 // make sure topline is not halfway a fold and cursor is |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1593 // invalidated |
10005
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1594 changed_window_setting_win(wp); |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1595 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1596 // Note: 'sbo' is not restored, it's a global option. |
16 | 1597 diff_buf_adjust(wp); |
1598 } | |
1599 diffwin |= wp->w_p_diff; | |
1600 } | |
1601 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1602 // Also remove hidden buffers from the list. |
10821
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1603 if (eap->forceit) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1604 diff_buf_clear(); |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1605 |
18590
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1606 if (!diffwin) |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1607 { |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1608 diff_need_update = FALSE; |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1609 curtab->tp_diff_invalid = FALSE; |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1610 curtab->tp_diff_update = FALSE; |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1611 diff_clear(curtab); |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1612 } |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1613 |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1614 // Remove "hor" from 'scrollopt' if there are no diff windows left. |
16 | 1615 if (!diffwin && vim_strchr(p_sbo, 'h') != NULL) |
1616 do_cmdline_cmd((char_u *)"set sbo-=hor"); | |
1617 } | |
1618 | |
1619 /* | |
7 | 1620 * Read the diff output and add each entry to the diff list. |
1621 */ | |
1622 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1623 diff_read( |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1624 int idx_orig, // idx of original file |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1625 int idx_new, // idx of new file |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1626 diffio_T *dio) // diff output |
7 | 1627 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1628 FILE *fd = NULL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1629 int line_idx = 0; |
7 | 1630 diff_T *dprev = NULL; |
672 | 1631 diff_T *dp = curtab->tp_first_diff; |
7 | 1632 diff_T *dn, *dpl; |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1633 diffout_T *dout = &dio->dio_diff; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1634 char_u linebuf[LBUFLEN]; // only need to hold the diff line |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1635 char_u *line; |
7 | 1636 long off; |
1637 int i; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1638 int notset = TRUE; // block "*dp" not set yet |
26829
88a33cf5aeb6
patch 8.2.3943: compiler warning from gcc for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
26805
diff
changeset
|
1639 diffhunk_T *hunk = NULL; // init to avoid gcc warning |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1640 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1641 enum { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1642 DIFF_ED, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1643 DIFF_UNIFIED, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1644 DIFF_NONE |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1645 } diffstyle = DIFF_NONE; |
7 | 1646 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1647 if (dout->dout_fname == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1648 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1649 diffstyle = DIFF_UNIFIED; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1650 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1651 else |
7 | 1652 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1653 fd = mch_fopen((char *)dout->dout_fname, "r"); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1654 if (fd == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1655 { |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26044
diff
changeset
|
1656 emsg(_(e_cannot_read_diff_output)); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1657 return; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1658 } |
7 | 1659 } |
1660 | |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1661 if (!dio->dio_internal) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1662 { |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1663 hunk = ALLOC_ONE(diffhunk_T); |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1664 if (hunk == NULL) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1665 return; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1666 } |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1667 |
7 | 1668 for (;;) |
1669 { | |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1670 if (dio->dio_internal) |
7 | 1671 { |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1672 if (line_idx >= dout->dout_ga.ga_len) { |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1673 break; // did last line |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1674 } |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1675 hunk = ((diffhunk_T **)dout->dout_ga.ga_data)[line_idx++]; |
7 | 1676 } |
1677 else | |
1678 { | |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1679 if (fd == NULL) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1680 { |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1681 if (line_idx >= dout->dout_ga.ga_len) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1682 break; // did last line |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1683 line = ((char_u **)dout->dout_ga.ga_data)[line_idx++]; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1684 } |
14726
655f00c29c58
patch 8.1.0375: cannot use diff mode with Cygwin diff.exe
Christian Brabandt <cb@256bit.org>
parents:
14716
diff
changeset
|
1685 else |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1686 { |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1687 if (vim_fgets(linebuf, LBUFLEN, fd)) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1688 break; // end of file |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1689 line = linebuf; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1690 } |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1691 |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1692 if (diffstyle == DIFF_NONE) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1693 { |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1694 // Determine diff style. |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1695 // ed like diff looks like this: |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1696 // {first}[,{last}]c{first}[,{last}] |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1697 // {first}a{first}[,{last}] |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1698 // {first}[,{last}]d{first} |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1699 // |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1700 // unified diff looks like this: |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1701 // --- file1 2018-03-20 13:23:35.783153140 +0100 |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1702 // +++ file2 2018-03-20 13:23:41.183156066 +0100 |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1703 // @@ -1,3 +1,5 @@ |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1704 if (isdigit(*line)) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1705 diffstyle = DIFF_ED; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1706 else if ((STRNCMP(line, "@@ ", 3) == 0)) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1707 diffstyle = DIFF_UNIFIED; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1708 else if ((STRNCMP(line, "--- ", 4) == 0) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1709 && (vim_fgets(linebuf, LBUFLEN, fd) == 0) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1710 && (STRNCMP(line, "+++ ", 4) == 0) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1711 && (vim_fgets(linebuf, LBUFLEN, fd) == 0) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1712 && (STRNCMP(line, "@@ ", 3) == 0)) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1713 diffstyle = DIFF_UNIFIED; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1714 else |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1715 // Format not recognized yet, skip over this line. Cygwin |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1716 // diff may put a warning at the start of the file. |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1717 continue; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1718 } |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1719 |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1720 if (diffstyle == DIFF_ED) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1721 { |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1722 if (!isdigit(*line)) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1723 continue; // not the start of a diff block |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1724 if (parse_diff_ed(line, hunk) == FAIL) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1725 continue; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1726 } |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1727 else if (diffstyle == DIFF_UNIFIED) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1728 { |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1729 if (STRNCMP(line, "@@ ", 3) != 0) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1730 continue; // not the start of a diff block |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1731 if (parse_diff_unified(line, hunk) == FAIL) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1732 continue; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1733 } |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1734 else |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1735 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
1736 emsg(_(e_invalid_diff_format)); |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1737 break; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1738 } |
7 | 1739 } |
1740 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1741 // Go over blocks before the change, for which orig and new are equal. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1742 // Copy blocks from orig to new. |
7 | 1743 while (dp != NULL |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1744 && hunk->lnum_orig > dp->df_lnum[idx_orig] |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1745 + dp->df_count[idx_orig]) |
7 | 1746 { |
1747 if (notset) | |
1748 diff_copy_entry(dprev, dp, idx_orig, idx_new); | |
1749 dprev = dp; | |
1750 dp = dp->df_next; | |
1751 notset = TRUE; | |
1752 } | |
1753 | |
1754 if (dp != NULL | |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1755 && hunk->lnum_orig <= dp->df_lnum[idx_orig] |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1756 + dp->df_count[idx_orig] |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1757 && hunk->lnum_orig + hunk->count_orig >= dp->df_lnum[idx_orig]) |
7 | 1758 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1759 // New block overlaps with existing block(s). |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1760 // First find last block that overlaps. |
7 | 1761 for (dpl = dp; dpl->df_next != NULL; dpl = dpl->df_next) |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1762 if (hunk->lnum_orig + hunk->count_orig |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1763 < dpl->df_next->df_lnum[idx_orig]) |
7 | 1764 break; |
1765 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1766 // If the newly found block starts before the old one, set the |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1767 // start back a number of lines. |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1768 off = dp->df_lnum[idx_orig] - hunk->lnum_orig; |
7 | 1769 if (off > 0) |
1770 { | |
1771 for (i = idx_orig; i < idx_new; ++i) | |
672 | 1772 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1773 dp->df_lnum[i] -= off; |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1774 dp->df_lnum[idx_new] = hunk->lnum_new; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1775 dp->df_count[idx_new] = hunk->count_new; |
7 | 1776 } |
1777 else if (notset) | |
1778 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1779 // new block inside existing one, adjust new block |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1780 dp->df_lnum[idx_new] = hunk->lnum_new + off; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1781 dp->df_count[idx_new] = hunk->count_new - off; |
7 | 1782 } |
1783 else | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1784 // second overlap of new block with existing block |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1785 dp->df_count[idx_new] += hunk->count_new - hunk->count_orig |
1519 | 1786 + dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig] |
1787 - (dp->df_lnum[idx_orig] + dp->df_count[idx_orig]); | |
7 | 1788 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1789 // Adjust the size of the block to include all the lines to the |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1790 // end of the existing block or the new diff, whatever ends last. |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1791 off = (hunk->lnum_orig + hunk->count_orig) |
7 | 1792 - (dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig]); |
1793 if (off < 0) | |
1794 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1795 // new change ends in existing block, adjust the end if not |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1796 // done already |
7 | 1797 if (notset) |
1798 dp->df_count[idx_new] += -off; | |
1799 off = 0; | |
1800 } | |
1428 | 1801 for (i = idx_orig; i < idx_new; ++i) |
672 | 1802 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1803 dp->df_count[i] = dpl->df_lnum[i] + dpl->df_count[i] |
1804 - dp->df_lnum[i] + off; | |
1805 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1806 // Delete the diff blocks that have been merged into one. |
7 | 1807 dn = dp->df_next; |
1808 dp->df_next = dpl->df_next; | |
1809 while (dn != dp->df_next) | |
1810 { | |
1811 dpl = dn->df_next; | |
1812 vim_free(dn); | |
1813 dn = dpl; | |
1814 } | |
1815 } | |
1816 else | |
1817 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1818 // Allocate a new diffblock. |
672 | 1819 dp = diff_alloc_new(curtab, dprev, dp); |
7 | 1820 if (dp == NULL) |
840 | 1821 goto done; |
7 | 1822 |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1823 dp->df_lnum[idx_orig] = hunk->lnum_orig; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1824 dp->df_count[idx_orig] = hunk->count_orig; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1825 dp->df_lnum[idx_new] = hunk->lnum_new; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1826 dp->df_count[idx_new] = hunk->count_new; |
7 | 1827 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1828 // Set values for other buffers, these must be equal to the |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1829 // original buffer, otherwise there would have been a change |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1830 // already. |
7 | 1831 for (i = idx_orig + 1; i < idx_new; ++i) |
672 | 1832 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1833 diff_copy_entry(dprev, dp, idx_orig, i); |
1834 } | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1835 notset = FALSE; // "*dp" has been set |
7 | 1836 } |
1837 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1838 // for remaining diff blocks orig and new are equal |
7 | 1839 while (dp != NULL) |
1840 { | |
1841 if (notset) | |
1842 diff_copy_entry(dprev, dp, idx_orig, idx_new); | |
1843 dprev = dp; | |
1844 dp = dp->df_next; | |
1845 notset = TRUE; | |
1846 } | |
1847 | |
840 | 1848 done: |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1849 if (!dio->dio_internal) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1850 vim_free(hunk); |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1851 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1852 if (fd != NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1853 fclose(fd); |
7 | 1854 } |
1855 | |
1856 /* | |
1857 * Copy an entry at "dp" from "idx_orig" to "idx_new". | |
1858 */ | |
1859 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1860 diff_copy_entry( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1861 diff_T *dprev, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1862 diff_T *dp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1863 int idx_orig, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1864 int idx_new) |
7 | 1865 { |
1866 long off; | |
1867 | |
1868 if (dprev == NULL) | |
1869 off = 0; | |
1870 else | |
1871 off = (dprev->df_lnum[idx_orig] + dprev->df_count[idx_orig]) | |
1872 - (dprev->df_lnum[idx_new] + dprev->df_count[idx_new]); | |
1873 dp->df_lnum[idx_new] = dp->df_lnum[idx_orig] - off; | |
1874 dp->df_count[idx_new] = dp->df_count[idx_orig]; | |
1875 } | |
1876 | |
1877 /* | |
672 | 1878 * Clear the list of diffblocks for tab page "tp". |
7 | 1879 */ |
358 | 1880 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1881 diff_clear(tabpage_T *tp) |
7 | 1882 { |
1883 diff_T *p, *next_p; | |
1884 | |
672 | 1885 for (p = tp->tp_first_diff; p != NULL; p = next_p) |
7 | 1886 { |
1887 next_p = p->df_next; | |
1888 vim_free(p); | |
1889 } | |
672 | 1890 tp->tp_first_diff = NULL; |
7 | 1891 } |
1892 | |
1893 /* | |
1894 * Check diff status for line "lnum" in buffer "buf": | |
1895 * Returns 0 for nothing special | |
1896 * Returns -1 for a line that should be highlighted as changed. | |
1897 * Returns -2 for a line that should be highlighted as added/deleted. | |
1898 * Returns > 0 for inserting that many filler lines above it (never happens | |
1899 * when 'diffopt' doesn't contain "filler"). | |
1900 * This should only be used for windows where 'diff' is set. | |
1901 */ | |
1902 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1903 diff_check(win_T *wp, linenr_T lnum) |
7 | 1904 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1905 int idx; // index in tp_diffbuf[] for this buffer |
7 | 1906 diff_T *dp; |
1907 int maxcount; | |
1908 int i; | |
1909 buf_T *buf = wp->w_buffer; | |
1910 int cmp; | |
1911 | |
672 | 1912 if (curtab->tp_diff_invalid) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1913 ex_diffupdate(NULL); // update after a big change |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1914 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1915 if (curtab->tp_first_diff == NULL || !wp->w_p_diff) // no diffs at all |
7 | 1916 return 0; |
1917 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1918 // safety check: "lnum" must be a buffer line |
7 | 1919 if (lnum < 1 || lnum > buf->b_ml.ml_line_count + 1) |
1920 return 0; | |
1921 | |
1922 idx = diff_buf_idx(buf); | |
1923 if (idx == DB_COUNT) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1924 return 0; // no diffs for buffer "buf" |
7 | 1925 |
1926 #ifdef FEAT_FOLDING | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1927 // A closed fold never has filler lines. |
7 | 1928 if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) |
1929 return 0; | |
1930 #endif | |
1931 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1932 // search for a change that includes "lnum" in the list of diffblocks. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
1933 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
7 | 1934 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
1935 break; | |
1936 if (dp == NULL || lnum < dp->df_lnum[idx]) | |
1937 return 0; | |
1938 | |
1939 if (lnum < dp->df_lnum[idx] + dp->df_count[idx]) | |
1940 { | |
1941 int zero = FALSE; | |
1942 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1943 // Changed or inserted line. If the other buffers have a count of |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1944 // zero, the lines were inserted. If the other buffers have the same |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1945 // count, check if the lines are identical. |
7 | 1946 cmp = FALSE; |
1947 for (i = 0; i < DB_COUNT; ++i) | |
672 | 1948 if (i != idx && curtab->tp_diffbuf[i] != NULL) |
7 | 1949 { |
1950 if (dp->df_count[i] == 0) | |
1951 zero = TRUE; | |
1952 else | |
1953 { | |
1954 if (dp->df_count[i] != dp->df_count[idx]) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1955 return -1; // nr of lines changed. |
7 | 1956 cmp = TRUE; |
1957 } | |
1958 } | |
1959 if (cmp) | |
1960 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1961 // Compare all lines. If they are equal the lines were inserted |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1962 // in some buffers, deleted in others, but not changed. |
7 | 1963 for (i = 0; i < DB_COUNT; ++i) |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1964 if (i != idx && curtab->tp_diffbuf[i] != NULL |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1965 && dp->df_count[i] != 0) |
7 | 1966 if (!diff_equal_entry(dp, idx, i)) |
1967 return -1; | |
1968 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1969 // If there is no buffer with zero lines then there is no difference |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1970 // any longer. Happens when making a change (or undo) that removes |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1971 // the difference. Can't remove the entry here, we might be halfway |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1972 // updating the window. Just report the text as unchanged. Other |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1973 // windows might still show the change though. |
7 | 1974 if (zero == FALSE) |
1975 return 0; | |
1976 return -2; | |
1977 } | |
1978 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1979 // If 'diffopt' doesn't contain "filler", return 0. |
7 | 1980 if (!(diff_flags & DIFF_FILLER)) |
1981 return 0; | |
1982 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1983 // Insert filler lines above the line just below the change. Will return |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1984 // 0 when this buf had the max count. |
7 | 1985 maxcount = 0; |
1986 for (i = 0; i < DB_COUNT; ++i) | |
672 | 1987 if (curtab->tp_diffbuf[i] != NULL && dp->df_count[i] > maxcount) |
7 | 1988 maxcount = dp->df_count[i]; |
1989 return maxcount - dp->df_count[idx]; | |
1990 } | |
1991 | |
1992 /* | |
1993 * Compare two entries in diff "*dp" and return TRUE if they are equal. | |
1994 */ | |
1995 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1996 diff_equal_entry(diff_T *dp, int idx1, int idx2) |
7 | 1997 { |
1998 int i; | |
1999 char_u *line; | |
2000 int cmp; | |
2001 | |
2002 if (dp->df_count[idx1] != dp->df_count[idx2]) | |
2003 return FALSE; | |
672 | 2004 if (diff_check_sanity(curtab, dp) == FAIL) |
7 | 2005 return FALSE; |
2006 for (i = 0; i < dp->df_count[idx1]; ++i) | |
2007 { | |
672 | 2008 line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], |
7 | 2009 dp->df_lnum[idx1] + i, FALSE)); |
2010 if (line == NULL) | |
2011 return FALSE; | |
672 | 2012 cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], |
7 | 2013 dp->df_lnum[idx2] + i, FALSE)); |
2014 vim_free(line); | |
2015 if (cmp != 0) | |
2016 return FALSE; | |
2017 } | |
2018 return TRUE; | |
2019 } | |
2020 | |
2021 /* | |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2022 * Compare the characters at "p1" and "p2". If they are equal (possibly |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2023 * ignoring case) return TRUE and set "len" to the number of bytes. |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2024 */ |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2025 static int |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2026 diff_equal_char(char_u *p1, char_u *p2, int *len) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2027 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2028 int l = (*mb_ptr2len)(p1); |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2029 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2030 if (l != (*mb_ptr2len)(p2)) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2031 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2032 if (l > 1) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2033 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2034 if (STRNCMP(p1, p2, l) != 0 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2035 && (!enc_utf8 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2036 || !(diff_flags & DIFF_ICASE) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2037 || utf_fold(utf_ptr2char(p1)) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2038 != utf_fold(utf_ptr2char(p2)))) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2039 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2040 *len = l; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2041 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2042 else |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2043 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2044 if ((*p1 != *p2) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2045 && (!(diff_flags & DIFF_ICASE) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2046 || TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2))) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2047 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2048 *len = 1; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2049 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2050 return TRUE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2051 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2052 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2053 /* |
7 | 2054 * Compare strings "s1" and "s2" according to 'diffopt'. |
2055 * Return non-zero when they are different. | |
2056 */ | |
2057 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2058 diff_cmp(char_u *s1, char_u *s2) |
7 | 2059 { |
2060 char_u *p1, *p2; | |
2061 int l; | |
2062 | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2063 if ((diff_flags & DIFF_IBLANK) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2064 && (*skipwhite(s1) == NUL || *skipwhite(s2) == NUL)) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2065 return 0; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2066 |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2067 if ((diff_flags & (DIFF_ICASE | ALL_WHITE_DIFF)) == 0) |
7 | 2068 return STRCMP(s1, s2); |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2069 if ((diff_flags & DIFF_ICASE) && !(diff_flags & ALL_WHITE_DIFF)) |
7 | 2070 return MB_STRICMP(s1, s2); |
2071 | |
2072 p1 = s1; | |
2073 p2 = s2; | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2074 |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2075 // Ignore white space changes and possibly ignore case. |
7 | 2076 while (*p1 != NUL && *p2 != NUL) |
2077 { | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2078 if (((diff_flags & DIFF_IWHITE) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2079 && VIM_ISWHITE(*p1) && VIM_ISWHITE(*p2)) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2080 || ((diff_flags & DIFF_IWHITEALL) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2081 && (VIM_ISWHITE(*p1) || VIM_ISWHITE(*p2)))) |
7 | 2082 { |
2083 p1 = skipwhite(p1); | |
2084 p2 = skipwhite(p2); | |
2085 } | |
2086 else | |
2087 { | |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2088 if (!diff_equal_char(p1, p2, &l)) |
7 | 2089 break; |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2090 p1 += l; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2091 p2 += l; |
7 | 2092 } |
2093 } | |
2094 | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2095 // Ignore trailing white space. |
7 | 2096 p1 = skipwhite(p1); |
2097 p2 = skipwhite(p2); | |
2098 if (*p1 != NUL || *p2 != NUL) | |
2099 return 1; | |
2100 return 0; | |
2101 } | |
2102 | |
2103 /* | |
2104 * Return the number of filler lines above "lnum". | |
2105 */ | |
2106 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2107 diff_check_fill(win_T *wp, linenr_T lnum) |
7 | 2108 { |
2109 int n; | |
2110 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2111 // be quick when there are no filler lines |
7 | 2112 if (!(diff_flags & DIFF_FILLER)) |
2113 return 0; | |
2114 n = diff_check(wp, lnum); | |
2115 if (n <= 0) | |
2116 return 0; | |
2117 return n; | |
2118 } | |
2119 | |
2120 /* | |
2121 * Set the topline of "towin" to match the position in "fromwin", so that they | |
2122 * show the same diff'ed lines. | |
2123 */ | |
2124 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2125 diff_set_topline(win_T *fromwin, win_T *towin) |
7 | 2126 { |
1519 | 2127 buf_T *frombuf = fromwin->w_buffer; |
7 | 2128 linenr_T lnum = fromwin->w_topline; |
1519 | 2129 int fromidx; |
2130 int toidx; | |
7 | 2131 diff_T *dp; |
1519 | 2132 int max_count; |
7 | 2133 int i; |
2134 | |
1519 | 2135 fromidx = diff_buf_idx(frombuf); |
2136 if (fromidx == DB_COUNT) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2137 return; // safety check |
7 | 2138 |
672 | 2139 if (curtab->tp_diff_invalid) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2140 ex_diffupdate(NULL); // update after a big change |
7 | 2141 |
2142 towin->w_topfill = 0; | |
2143 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2144 // search for a change that includes "lnum" in the list of diffblocks. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
2145 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
1519 | 2146 if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
7 | 2147 break; |
2148 if (dp == NULL) | |
2149 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2150 // After last change, compute topline relative to end of file; no |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2151 // filler lines. |
7 | 2152 towin->w_topline = towin->w_buffer->b_ml.ml_line_count |
1519 | 2153 - (frombuf->b_ml.ml_line_count - lnum); |
7 | 2154 } |
2155 else | |
2156 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2157 // Find index for "towin". |
1519 | 2158 toidx = diff_buf_idx(towin->w_buffer); |
2159 if (toidx == DB_COUNT) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2160 return; // safety check |
7 | 2161 |
1519 | 2162 towin->w_topline = lnum + (dp->df_lnum[toidx] - dp->df_lnum[fromidx]); |
2163 if (lnum >= dp->df_lnum[fromidx]) | |
7 | 2164 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2165 // Inside a change: compute filler lines. With three or more |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2166 // buffers we need to know the largest count. |
1519 | 2167 max_count = 0; |
2168 for (i = 0; i < DB_COUNT; ++i) | |
2169 if (curtab->tp_diffbuf[i] != NULL | |
2170 && max_count < dp->df_count[i]) | |
2171 max_count = dp->df_count[i]; | |
2172 | |
2173 if (dp->df_count[toidx] == dp->df_count[fromidx]) | |
2174 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2175 // same number of lines: use same filler count |
7 | 2176 towin->w_topfill = fromwin->w_topfill; |
1519 | 2177 } |
2178 else if (dp->df_count[toidx] > dp->df_count[fromidx]) | |
7 | 2179 { |
1519 | 2180 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
2181 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2182 // more lines in towin and fromwin doesn't show diff |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2183 // lines, only filler lines |
1519 | 2184 if (max_count - fromwin->w_topfill >= dp->df_count[toidx]) |
2185 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2186 // towin also only shows filler lines |
1519 | 2187 towin->w_topline = dp->df_lnum[toidx] |
2188 + dp->df_count[toidx]; | |
2189 towin->w_topfill = fromwin->w_topfill; | |
2190 } | |
2191 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2192 // towin still has some diff lines to show |
1519 | 2193 towin->w_topline = dp->df_lnum[toidx] |
2194 + max_count - fromwin->w_topfill; | |
2195 } | |
7 | 2196 } |
1519 | 2197 else if (towin->w_topline >= dp->df_lnum[toidx] |
2198 + dp->df_count[toidx]) | |
7 | 2199 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2200 // less lines in towin and no diff lines to show: compute |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2201 // filler lines |
1519 | 2202 towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; |
2203 if (diff_flags & DIFF_FILLER) | |
7 | 2204 { |
1519 | 2205 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2206 // fromwin is also out of diff lines |
1519 | 2207 towin->w_topfill = fromwin->w_topfill; |
2208 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2209 // fromwin has some diff lines |
1519 | 2210 towin->w_topfill = dp->df_lnum[fromidx] |
2211 + max_count - lnum; | |
7 | 2212 } |
2213 } | |
2214 } | |
2215 } | |
2216 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2217 // safety check (if diff info gets outdated strange things may happen) |
7 | 2218 towin->w_botfill = FALSE; |
2219 if (towin->w_topline > towin->w_buffer->b_ml.ml_line_count) | |
2220 { | |
2221 towin->w_topline = towin->w_buffer->b_ml.ml_line_count; | |
2222 towin->w_botfill = TRUE; | |
2223 } | |
2224 if (towin->w_topline < 1) | |
2225 { | |
2226 towin->w_topline = 1; | |
2227 towin->w_topfill = 0; | |
2228 } | |
2229 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2230 // When w_topline changes need to recompute w_botline and cursor position |
7 | 2231 invalidate_botline_win(towin); |
2232 changed_line_abv_curs_win(towin); | |
2233 | |
2234 check_topfill(towin, FALSE); | |
2235 #ifdef FEAT_FOLDING | |
2236 (void)hasFoldingWin(towin, towin->w_topline, &towin->w_topline, | |
2237 NULL, TRUE, NULL); | |
2238 #endif | |
2239 } | |
2240 | |
2241 /* | |
2242 * This is called when 'diffopt' is changed. | |
2243 */ | |
2244 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2245 diffopt_changed(void) |
7 | 2246 { |
2247 char_u *p; | |
2248 int diff_context_new = 6; | |
2249 int diff_flags_new = 0; | |
764 | 2250 int diff_foldcolumn_new = 2; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2251 long diff_algorithm_new = 0; |
15103
9339601e7a31
patch 8.1.0562: parsing of 'diffopt' is slightly wrong
Bram Moolenaar <Bram@vim.org>
parents:
15004
diff
changeset
|
2252 long diff_indent_heuristic = 0; |
672 | 2253 tabpage_T *tp; |
7 | 2254 |
2255 p = p_dip; | |
2256 while (*p != NUL) | |
2257 { | |
2258 if (STRNCMP(p, "filler", 6) == 0) | |
2259 { | |
2260 p += 6; | |
2261 diff_flags_new |= DIFF_FILLER; | |
2262 } | |
2263 else if (STRNCMP(p, "context:", 8) == 0 && VIM_ISDIGIT(p[8])) | |
2264 { | |
2265 p += 8; | |
2266 diff_context_new = getdigits(&p); | |
2267 } | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2268 else if (STRNCMP(p, "iblank", 6) == 0) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2269 { |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2270 p += 6; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2271 diff_flags_new |= DIFF_IBLANK; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2272 } |
7 | 2273 else if (STRNCMP(p, "icase", 5) == 0) |
2274 { | |
2275 p += 5; | |
2276 diff_flags_new |= DIFF_ICASE; | |
2277 } | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2278 else if (STRNCMP(p, "iwhiteall", 9) == 0) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2279 { |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2280 p += 9; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2281 diff_flags_new |= DIFF_IWHITEALL; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2282 } |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2283 else if (STRNCMP(p, "iwhiteeol", 9) == 0) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2284 { |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2285 p += 9; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2286 diff_flags_new |= DIFF_IWHITEEOL; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2287 } |
7 | 2288 else if (STRNCMP(p, "iwhite", 6) == 0) |
2289 { | |
2290 p += 6; | |
2291 diff_flags_new |= DIFF_IWHITE; | |
2292 } | |
764 | 2293 else if (STRNCMP(p, "horizontal", 10) == 0) |
2294 { | |
2295 p += 10; | |
2296 diff_flags_new |= DIFF_HORIZONTAL; | |
2297 } | |
2298 else if (STRNCMP(p, "vertical", 8) == 0) | |
2299 { | |
2300 p += 8; | |
2301 diff_flags_new |= DIFF_VERTICAL; | |
2302 } | |
2303 else if (STRNCMP(p, "foldcolumn:", 11) == 0 && VIM_ISDIGIT(p[11])) | |
2304 { | |
2305 p += 11; | |
2306 diff_foldcolumn_new = getdigits(&p); | |
2307 } | |
12971
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2308 else if (STRNCMP(p, "hiddenoff", 9) == 0) |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2309 { |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2310 p += 9; |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2311 diff_flags_new |= DIFF_HIDDEN_OFF; |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2312 } |
18590
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2313 else if (STRNCMP(p, "closeoff", 8) == 0) |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2314 { |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2315 p += 8; |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2316 diff_flags_new |= DIFF_CLOSE_OFF; |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2317 } |
23895
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
2318 else if (STRNCMP(p, "followwrap", 10) == 0) |
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
2319 { |
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
2320 p += 10; |
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
2321 diff_flags_new |= DIFF_FOLLOWWRAP; |
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
2322 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2323 else if (STRNCMP(p, "indent-heuristic", 16) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2324 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2325 p += 16; |
15103
9339601e7a31
patch 8.1.0562: parsing of 'diffopt' is slightly wrong
Bram Moolenaar <Bram@vim.org>
parents:
15004
diff
changeset
|
2326 diff_indent_heuristic = XDF_INDENT_HEURISTIC; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2327 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2328 else if (STRNCMP(p, "internal", 8) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2329 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2330 p += 8; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2331 diff_flags_new |= DIFF_INTERNAL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2332 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2333 else if (STRNCMP(p, "algorithm:", 10) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2334 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2335 p += 10; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2336 if (STRNCMP(p, "myers", 5) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2337 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2338 p += 5; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2339 diff_algorithm_new = 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2340 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2341 else if (STRNCMP(p, "minimal", 7) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2342 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2343 p += 7; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2344 diff_algorithm_new = XDF_NEED_MINIMAL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2345 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2346 else if (STRNCMP(p, "patience", 8) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2347 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2348 p += 8; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2349 diff_algorithm_new = XDF_PATIENCE_DIFF; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2350 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2351 else if (STRNCMP(p, "histogram", 9) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2352 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2353 p += 9; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2354 diff_algorithm_new = XDF_HISTOGRAM_DIFF; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2355 } |
15004
9c2352253376
patch 8.1.0513: no error for set diffopt+=algorithm:
Bram Moolenaar <Bram@vim.org>
parents:
14982
diff
changeset
|
2356 else |
9c2352253376
patch 8.1.0513: no error for set diffopt+=algorithm:
Bram Moolenaar <Bram@vim.org>
parents:
14982
diff
changeset
|
2357 return FAIL; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2358 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2359 |
7 | 2360 if (*p != ',' && *p != NUL) |
2361 return FAIL; | |
2362 if (*p == ',') | |
2363 ++p; | |
2364 } | |
2365 | |
15103
9339601e7a31
patch 8.1.0562: parsing of 'diffopt' is slightly wrong
Bram Moolenaar <Bram@vim.org>
parents:
15004
diff
changeset
|
2366 diff_algorithm_new |= diff_indent_heuristic; |
9339601e7a31
patch 8.1.0562: parsing of 'diffopt' is slightly wrong
Bram Moolenaar <Bram@vim.org>
parents:
15004
diff
changeset
|
2367 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2368 // Can't have both "horizontal" and "vertical". |
764 | 2369 if ((diff_flags_new & DIFF_HORIZONTAL) && (diff_flags_new & DIFF_VERTICAL)) |
2370 return FAIL; | |
2371 | |
14780
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2372 // If flags were added or removed, or the algorithm was changed, need to |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2373 // update the diff. |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2374 if (diff_flags != diff_flags_new || diff_algorithm != diff_algorithm_new) |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2375 FOR_ALL_TABPAGES(tp) |
672 | 2376 tp->tp_diff_invalid = TRUE; |
7 | 2377 |
2378 diff_flags = diff_flags_new; | |
15900
360c93a884d0
patch 8.1.0956: using context:0 in 'diffopt' does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
2379 diff_context = diff_context_new == 0 ? 1 : diff_context_new; |
764 | 2380 diff_foldcolumn = diff_foldcolumn_new; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2381 diff_algorithm = diff_algorithm_new; |
7 | 2382 |
2383 diff_redraw(TRUE); | |
2384 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2385 // recompute the scroll binding with the new option value, may |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2386 // remove or add filler lines |
7 | 2387 check_scrollbind((linenr_T)0, 0L); |
2388 | |
2389 return OK; | |
2390 } | |
2391 | |
2392 /* | |
764 | 2393 * Return TRUE if 'diffopt' contains "horizontal". |
2394 */ | |
2395 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2396 diffopt_horizontal(void) |
764 | 2397 { |
2398 return (diff_flags & DIFF_HORIZONTAL) != 0; | |
2399 } | |
2400 | |
2401 /* | |
12971
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2402 * Return TRUE if 'diffopt' contains "hiddenoff". |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2403 */ |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2404 int |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2405 diffopt_hiddenoff(void) |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2406 { |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2407 return (diff_flags & DIFF_HIDDEN_OFF) != 0; |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2408 } |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2409 |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2410 /* |
18590
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2411 * Return TRUE if 'diffopt' contains "closeoff". |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2412 */ |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2413 int |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2414 diffopt_closeoff(void) |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2415 { |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2416 return (diff_flags & DIFF_CLOSE_OFF) != 0; |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2417 } |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2418 |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2419 /* |
7 | 2420 * Find the difference within a changed line. |
2421 * Returns TRUE if the line was added, no other buffer has it. | |
2422 */ | |
2423 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2424 diff_find_change( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2425 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2426 linenr_T lnum, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2427 int *startp, // first char of the change |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2428 int *endp) // last char of the change |
7 | 2429 { |
2430 char_u *line_org; | |
2431 char_u *line_new; | |
2432 int i; | |
829 | 2433 int si_org, si_new; |
2434 int ei_org, ei_new; | |
7 | 2435 diff_T *dp; |
2436 int idx; | |
2437 int off; | |
2438 int added = TRUE; | |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2439 char_u *p1, *p2; |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2440 int l; |
7 | 2441 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2442 // Make a copy of the line, the next ml_get() will invalidate it. |
7 | 2443 line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); |
2444 if (line_org == NULL) | |
2445 return FALSE; | |
2446 | |
2447 idx = diff_buf_idx(wp->w_buffer); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2448 if (idx == DB_COUNT) // cannot happen |
1074 | 2449 { |
2450 vim_free(line_org); | |
7 | 2451 return FALSE; |
1074 | 2452 } |
7 | 2453 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2454 // search for a change that includes "lnum" in the list of diffblocks. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
2455 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
7 | 2456 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
2457 break; | |
672 | 2458 if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL) |
1074 | 2459 { |
2460 vim_free(line_org); | |
7 | 2461 return FALSE; |
1074 | 2462 } |
7 | 2463 |
2464 off = lnum - dp->df_lnum[idx]; | |
2465 | |
2466 for (i = 0; i < DB_COUNT; ++i) | |
672 | 2467 if (curtab->tp_diffbuf[i] != NULL && i != idx) |
7 | 2468 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2469 // Skip lines that are not in the other change (filler lines). |
7 | 2470 if (off >= dp->df_count[i]) |
2471 continue; | |
2472 added = FALSE; | |
829 | 2473 line_new = ml_get_buf(curtab->tp_diffbuf[i], |
2474 dp->df_lnum[i] + off, FALSE); | |
7 | 2475 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2476 // Search for start of difference |
829 | 2477 si_org = si_new = 0; |
2478 while (line_org[si_org] != NUL) | |
2479 { | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2480 if (((diff_flags & DIFF_IWHITE) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2481 && VIM_ISWHITE(line_org[si_org]) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2482 && VIM_ISWHITE(line_new[si_new])) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2483 || ((diff_flags & DIFF_IWHITEALL) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2484 && (VIM_ISWHITE(line_org[si_org]) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2485 || VIM_ISWHITE(line_new[si_new])))) |
829 | 2486 { |
835 | 2487 si_org = (int)(skipwhite(line_org + si_org) - line_org); |
2488 si_new = (int)(skipwhite(line_new + si_new) - line_new); | |
829 | 2489 } |
2490 else | |
2491 { | |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2492 if (!diff_equal_char(line_org + si_org, line_new + si_new, |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2493 &l)) |
829 | 2494 break; |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2495 si_org += l; |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2496 si_new += l; |
829 | 2497 } |
2498 } | |
7 | 2499 if (has_mbyte) |
2500 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2501 // Move back to first byte of character in both lines (may |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2502 // have "nn^" in line_org and "n^ in line_new). |
829 | 2503 si_org -= (*mb_head_off)(line_org, line_org + si_org); |
2504 si_new -= (*mb_head_off)(line_new, line_new + si_new); | |
7 | 2505 } |
829 | 2506 if (*startp > si_org) |
2507 *startp = si_org; | |
7 | 2508 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2509 // Search for end of difference, if any. |
829 | 2510 if (line_org[si_org] != NUL || line_new[si_new] != NUL) |
7 | 2511 { |
2512 ei_org = (int)STRLEN(line_org); | |
2513 ei_new = (int)STRLEN(line_new); | |
829 | 2514 while (ei_org >= *startp && ei_new >= si_new |
2515 && ei_org >= 0 && ei_new >= 0) | |
7 | 2516 { |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2517 if (((diff_flags & DIFF_IWHITE) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2518 && VIM_ISWHITE(line_org[ei_org]) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2519 && VIM_ISWHITE(line_new[ei_new])) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2520 || ((diff_flags & DIFF_IWHITEALL) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2521 && (VIM_ISWHITE(line_org[ei_org]) |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2522 || VIM_ISWHITE(line_new[ei_new])))) |
829 | 2523 { |
2524 while (ei_org >= *startp | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2525 && VIM_ISWHITE(line_org[ei_org])) |
829 | 2526 --ei_org; |
2527 while (ei_new >= si_new | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2528 && VIM_ISWHITE(line_new[ei_new])) |
829 | 2529 --ei_new; |
2530 } | |
2531 else | |
2532 { | |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2533 p1 = line_org + ei_org; |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2534 p2 = line_new + ei_new; |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2535 p1 -= (*mb_head_off)(line_org, p1); |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2536 p2 -= (*mb_head_off)(line_new, p2); |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2537 if (!diff_equal_char(p1, p2, &l)) |
829 | 2538 break; |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2539 ei_org -= l; |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2540 ei_new -= l; |
829 | 2541 } |
7 | 2542 } |
2543 if (*endp < ei_org) | |
2544 *endp = ei_org; | |
2545 } | |
2546 } | |
2547 | |
2548 vim_free(line_org); | |
2549 return added; | |
2550 } | |
2551 | |
2552 #if defined(FEAT_FOLDING) || defined(PROTO) | |
2553 /* | |
2554 * Return TRUE if line "lnum" is not close to a diff block, this line should | |
2555 * be in a fold. | |
2556 * Return FALSE if there are no diff blocks at all in this window. | |
2557 */ | |
2558 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2559 diff_infold(win_T *wp, linenr_T lnum) |
7 | 2560 { |
2561 int i; | |
2562 int idx = -1; | |
2563 int other = FALSE; | |
2564 diff_T *dp; | |
2565 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2566 // Return if 'diff' isn't set. |
7 | 2567 if (!wp->w_p_diff) |
2568 return FALSE; | |
2569 | |
2570 for (i = 0; i < DB_COUNT; ++i) | |
2571 { | |
672 | 2572 if (curtab->tp_diffbuf[i] == wp->w_buffer) |
7 | 2573 idx = i; |
672 | 2574 else if (curtab->tp_diffbuf[i] != NULL) |
7 | 2575 other = TRUE; |
2576 } | |
2577 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2578 // return here if there are no diffs in the window |
7 | 2579 if (idx == -1 || !other) |
2580 return FALSE; | |
2581 | |
672 | 2582 if (curtab->tp_diff_invalid) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2583 ex_diffupdate(NULL); // update after a big change |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2584 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2585 // Return if there are no diff blocks. All lines will be folded. |
672 | 2586 if (curtab->tp_first_diff == NULL) |
7 | 2587 return TRUE; |
2588 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
2589 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
7 | 2590 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2591 // If this change is below the line there can't be any further match. |
7 | 2592 if (dp->df_lnum[idx] - diff_context > lnum) |
2593 break; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2594 // If this change ends before the line we have a match. |
7 | 2595 if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) |
2596 return FALSE; | |
2597 } | |
2598 return TRUE; | |
2599 } | |
2600 #endif | |
2601 | |
2602 /* | |
2603 * "dp" and "do" commands. | |
2604 */ | |
2605 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2606 nv_diffgetput(int put, long count) |
7 | 2607 { |
2608 exarg_T ea; | |
6314 | 2609 char_u buf[30]; |
7 | 2610 |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2611 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2612 if (bt_prompt(curbuf)) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2613 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2614 vim_beep(BO_OPER); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2615 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2616 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2617 #endif |
6314 | 2618 if (count == 0) |
2619 ea.arg = (char_u *)""; | |
2620 else | |
2621 { | |
2622 vim_snprintf((char *)buf, 30, "%ld", count); | |
2623 ea.arg = buf; | |
2624 } | |
7 | 2625 if (put) |
2626 ea.cmdidx = CMD_diffput; | |
2627 else | |
2628 ea.cmdidx = CMD_diffget; | |
2629 ea.addr_count = 0; | |
2630 ea.line1 = curwin->w_cursor.lnum; | |
2631 ea.line2 = curwin->w_cursor.lnum; | |
2632 ex_diffgetput(&ea); | |
2633 } | |
2634 | |
2635 /* | |
2636 * ":diffget" | |
2637 * ":diffput" | |
2638 */ | |
2639 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2640 ex_diffgetput(exarg_T *eap) |
7 | 2641 { |
2642 linenr_T lnum; | |
2643 int count; | |
2644 linenr_T off = 0; | |
2645 diff_T *dp; | |
2646 diff_T *dprev; | |
2647 diff_T *dfree; | |
2648 int idx_cur; | |
2649 int idx_other; | |
2650 int idx_from; | |
2651 int idx_to; | |
2652 int i; | |
2653 int added; | |
2654 char_u *p; | |
2655 aco_save_T aco; | |
2656 buf_T *buf; | |
2657 int start_skip, end_skip; | |
2658 int new_count; | |
648 | 2659 int buf_empty; |
1075 | 2660 int found_not_ma = FALSE; |
7 | 2661 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2662 // Find the current buffer in the list of diff buffers. |
7 | 2663 idx_cur = diff_buf_idx(curbuf); |
2664 if (idx_cur == DB_COUNT) | |
2665 { | |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26044
diff
changeset
|
2666 emsg(_(e_current_buffer_is_not_in_diff_mode)); |
7 | 2667 return; |
2668 } | |
2669 | |
2670 if (*eap->arg == NUL) | |
2671 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2672 // No argument: Find the other buffer in the list of diff buffers. |
7 | 2673 for (idx_other = 0; idx_other < DB_COUNT; ++idx_other) |
672 | 2674 if (curtab->tp_diffbuf[idx_other] != curbuf |
1075 | 2675 && curtab->tp_diffbuf[idx_other] != NULL) |
2676 { | |
2677 if (eap->cmdidx != CMD_diffput | |
2678 || curtab->tp_diffbuf[idx_other]->b_p_ma) | |
2679 break; | |
2680 found_not_ma = TRUE; | |
2681 } | |
7 | 2682 if (idx_other == DB_COUNT) |
2683 { | |
1075 | 2684 if (found_not_ma) |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
2685 emsg(_(e_no_other_buffer_in_diff_mode_is_modifiable)); |
1075 | 2686 else |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26044
diff
changeset
|
2687 emsg(_(e_no_other_buffer_in_diff_mode)); |
7 | 2688 return; |
2689 } | |
2690 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2691 // Check that there isn't a third buffer in the list |
7 | 2692 for (i = idx_other + 1; i < DB_COUNT; ++i) |
672 | 2693 if (curtab->tp_diffbuf[i] != curbuf |
2694 && curtab->tp_diffbuf[i] != NULL | |
2695 && (eap->cmdidx != CMD_diffput || curtab->tp_diffbuf[i]->b_p_ma)) | |
7 | 2696 { |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26044
diff
changeset
|
2697 emsg(_(e_more_than_two_buffers_in_diff_mode_dont_know_which_one_to_use)); |
7 | 2698 return; |
2699 } | |
2700 } | |
2701 else | |
2702 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2703 // Buffer number or pattern given. Ignore trailing white space. |
7 | 2704 p = eap->arg + STRLEN(eap->arg); |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2705 while (p > eap->arg && VIM_ISWHITE(p[-1])) |
7 | 2706 --p; |
2707 for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i) | |
2708 ; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2709 if (eap->arg + i == p) // digits only |
7 | 2710 i = atol((char *)eap->arg); |
2711 else | |
2712 { | |
4236 | 2713 i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE); |
7 | 2714 if (i < 0) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2715 return; // error message already given |
7 | 2716 } |
2717 buf = buflist_findnr(i); | |
2718 if (buf == NULL) | |
2719 { | |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26044
diff
changeset
|
2720 semsg(_(e_cant_find_buffer_str), eap->arg); |
7 | 2721 return; |
2722 } | |
1788 | 2723 if (buf == curbuf) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2724 return; // nothing to do |
7 | 2725 idx_other = diff_buf_idx(buf); |
2726 if (idx_other == DB_COUNT) | |
2727 { | |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26044
diff
changeset
|
2728 semsg(_(e_buffer_str_is_not_in_diff_mode), eap->arg); |
7 | 2729 return; |
2730 } | |
2731 } | |
2732 | |
2733 diff_busy = TRUE; | |
2734 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2735 // When no range given include the line above or below the cursor. |
7 | 2736 if (eap->addr_count == 0) |
2737 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2738 // Make it possible that ":diffget" on the last line gets line below |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2739 // the cursor line when there is no difference above the cursor. |
7 | 2740 if (eap->cmdidx == CMD_diffget |
2741 && eap->line1 == curbuf->b_ml.ml_line_count | |
2742 && diff_check(curwin, eap->line1) == 0 | |
2743 && (eap->line1 == 1 || diff_check(curwin, eap->line1 - 1) == 0)) | |
2744 ++eap->line2; | |
2745 else if (eap->line1 > 0) | |
2746 --eap->line1; | |
2747 } | |
2748 | |
2749 if (eap->cmdidx == CMD_diffget) | |
2750 { | |
2751 idx_from = idx_other; | |
2752 idx_to = idx_cur; | |
2753 } | |
2754 else | |
2755 { | |
2756 idx_from = idx_cur; | |
2757 idx_to = idx_other; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2758 // Need to make the other buffer the current buffer to be able to make |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2759 // changes in it. |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2760 // set curwin/curbuf to buf and save a few things |
672 | 2761 aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]); |
7 | 2762 } |
2763 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2764 // May give the warning for a changed buffer here, which can trigger the |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2765 // FileChangedRO autocommand, which may do nasty things and mess |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2766 // everything up. |
819 | 2767 if (!curbuf->b_changed) |
2768 { | |
2769 change_warning(0); | |
2770 if (diff_buf_idx(curbuf) != idx_to) | |
2771 { | |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
2772 emsg(_(e_buffer_changed_unexpectedly)); |
14776
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
2773 goto theend; |
819 | 2774 } |
2775 } | |
2776 | |
7 | 2777 dprev = NULL; |
672 | 2778 for (dp = curtab->tp_first_diff; dp != NULL; ) |
7 | 2779 { |
2780 if (dp->df_lnum[idx_cur] > eap->line2 + off) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2781 break; // past the range that was specified |
7 | 2782 |
2783 dfree = NULL; | |
2784 lnum = dp->df_lnum[idx_to]; | |
2785 count = dp->df_count[idx_to]; | |
2786 if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off | |
2787 && u_save(lnum - 1, lnum + count) != FAIL) | |
2788 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2789 // Inside the specified range and saving for undo worked. |
7 | 2790 start_skip = 0; |
2791 end_skip = 0; | |
2792 if (eap->addr_count > 0) | |
2793 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2794 // A range was specified: check if lines need to be skipped. |
7 | 2795 start_skip = eap->line1 + off - dp->df_lnum[idx_cur]; |
2796 if (start_skip > 0) | |
2797 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2798 // range starts below start of current diff block |
7 | 2799 if (start_skip > count) |
2800 { | |
2801 lnum += count; | |
2802 count = 0; | |
2803 } | |
2804 else | |
2805 { | |
2806 count -= start_skip; | |
2807 lnum += start_skip; | |
2808 } | |
2809 } | |
2810 else | |
2811 start_skip = 0; | |
2812 | |
2813 end_skip = dp->df_lnum[idx_cur] + dp->df_count[idx_cur] - 1 | |
2814 - (eap->line2 + off); | |
2815 if (end_skip > 0) | |
2816 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2817 // range ends above end of current/from diff block |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2818 if (idx_cur == idx_from) // :diffput |
7 | 2819 { |
2820 i = dp->df_count[idx_cur] - start_skip - end_skip; | |
2821 if (count > i) | |
2822 count = i; | |
2823 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2824 else // :diffget |
7 | 2825 { |
2826 count -= end_skip; | |
2827 end_skip = dp->df_count[idx_from] - start_skip - count; | |
2828 if (end_skip < 0) | |
2829 end_skip = 0; | |
2830 } | |
2831 } | |
2832 else | |
2833 end_skip = 0; | |
2834 } | |
2835 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11113
diff
changeset
|
2836 buf_empty = BUFEMPTY(); |
7 | 2837 added = 0; |
2838 for (i = 0; i < count; ++i) | |
2839 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2840 // remember deleting the last line of the buffer |
648 | 2841 buf_empty = curbuf->b_ml.ml_line_count == 1; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2842 ml_delete(lnum); |
7 | 2843 --added; |
2844 } | |
2845 for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i) | |
2846 { | |
2847 linenr_T nr; | |
2848 | |
2849 nr = dp->df_lnum[idx_from] + start_skip + i; | |
672 | 2850 if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) |
7 | 2851 break; |
819 | 2852 p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], |
2853 nr, FALSE)); | |
7 | 2854 if (p != NULL) |
2855 { | |
2856 ml_append(lnum + i - 1, p, 0, FALSE); | |
2857 vim_free(p); | |
2858 ++added; | |
648 | 2859 if (buf_empty && curbuf->b_ml.ml_line_count == 2) |
2860 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2861 // Added the first line into an empty buffer, need to |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2862 // delete the dummy empty line. |
648 | 2863 buf_empty = FALSE; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2864 ml_delete((linenr_T)2); |
648 | 2865 } |
7 | 2866 } |
2867 } | |
2868 new_count = dp->df_count[idx_to] + added; | |
2869 dp->df_count[idx_to] = new_count; | |
2870 | |
2871 if (start_skip == 0 && end_skip == 0) | |
2872 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2873 // Check if there are any other buffers and if the diff is |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2874 // equal in them. |
7 | 2875 for (i = 0; i < DB_COUNT; ++i) |
819 | 2876 if (curtab->tp_diffbuf[i] != NULL && i != idx_from |
2877 && i != idx_to | |
7 | 2878 && !diff_equal_entry(dp, idx_from, i)) |
2879 break; | |
2880 if (i == DB_COUNT) | |
2881 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2882 // delete the diff entry, the buffers are now equal here |
7 | 2883 dfree = dp; |
2884 dp = dp->df_next; | |
2885 if (dprev == NULL) | |
672 | 2886 curtab->tp_first_diff = dp; |
7 | 2887 else |
2888 dprev->df_next = dp; | |
2889 } | |
2890 } | |
2891 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2892 // Adjust marks. This will change the following entries! |
7 | 2893 if (added != 0) |
2894 { | |
2895 mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added); | |
2896 if (curwin->w_cursor.lnum >= lnum) | |
2897 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2898 // Adjust the cursor position if it's in/after the changed |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2899 // lines. |
7 | 2900 if (curwin->w_cursor.lnum >= lnum + count) |
2901 curwin->w_cursor.lnum += added; | |
2902 else if (added < 0) | |
2903 curwin->w_cursor.lnum = lnum; | |
2904 } | |
2905 } | |
2906 changed_lines(lnum, 0, lnum + count, (long)added); | |
2907 | |
2908 if (dfree != NULL) | |
2909 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2910 // Diff is deleted, update folds in other windows. |
7 | 2911 #ifdef FEAT_FOLDING |
2912 diff_fold_update(dfree, idx_to); | |
2913 #endif | |
2914 vim_free(dfree); | |
2915 } | |
2916 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2917 // mark_adjust() may have changed the count in a wrong way |
7 | 2918 dp->df_count[idx_to] = new_count; |
2919 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2920 // When changing the current buffer, keep track of line numbers |
7 | 2921 if (idx_cur == idx_to) |
2922 off += added; | |
2923 } | |
2924 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2925 // If before the range or not deleted, go to next diff. |
7 | 2926 if (dfree == NULL) |
2927 { | |
2928 dprev = dp; | |
2929 dp = dp->df_next; | |
2930 } | |
2931 } | |
2932 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2933 // restore curwin/curbuf and a few other things |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2934 if (eap->cmdidx != CMD_diffget) |
7 | 2935 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2936 // Syncing undo only works for the current buffer, but we change |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2937 // another buffer. Sync undo if the command was typed. This isn't |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2938 // 100% right when ":diffput" is used in a function or mapping. |
7 | 2939 if (KeyTyped) |
825 | 2940 u_sync(FALSE); |
7 | 2941 aucmd_restbuf(&aco); |
2942 } | |
2943 | |
14776
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
2944 theend: |
7 | 2945 diff_busy = FALSE; |
14776
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
2946 if (diff_need_update) |
14893
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2947 ex_diffupdate(NULL); |
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2948 |
14972
5d52b21b2e7f
patch 8.1.0497: :%diffput changes order of lines
Bram Moolenaar <Bram@vim.org>
parents:
14893
diff
changeset
|
2949 // Check that the cursor is on a valid character and update its |
14893
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2950 // position. When there were filler lines the topline has become |
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2951 // invalid. |
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2952 check_cursor(); |
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2953 changed_line_abv_curs(); |
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2954 |
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2955 if (diff_need_update) |
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2956 // redraw already done by ex_diffupdate() |
14776
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
2957 diff_need_update = FALSE; |
14780
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2958 else |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2959 { |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2960 // Also need to redraw the other buffers. |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2961 diff_redraw(FALSE); |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2962 apply_autocmds(EVENT_DIFFUPDATED, NULL, NULL, FALSE, curbuf); |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2963 } |
7 | 2964 } |
2965 | |
2966 #ifdef FEAT_FOLDING | |
2967 /* | |
2968 * Update folds for all diff buffers for entry "dp". | |
2969 * Skip buffer with index "skip_idx". | |
2970 * When there are no diffs, all folds are removed. | |
2971 */ | |
2972 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2973 diff_fold_update(diff_T *dp, int skip_idx) |
7 | 2974 { |
2975 int i; | |
2976 win_T *wp; | |
2977 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2978 FOR_ALL_WINDOWS(wp) |
7 | 2979 for (i = 0; i < DB_COUNT; ++i) |
672 | 2980 if (curtab->tp_diffbuf[i] == wp->w_buffer && i != skip_idx) |
7 | 2981 foldUpdate(wp, dp->df_lnum[i], |
2982 dp->df_lnum[i] + dp->df_count[i]); | |
2983 } | |
2984 #endif | |
2985 | |
2986 /* | |
2987 * Return TRUE if buffer "buf" is in diff-mode. | |
2988 */ | |
2989 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2990 diff_mode_buf(buf_T *buf) |
7 | 2991 { |
672 | 2992 tabpage_T *tp; |
2993 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2994 FOR_ALL_TABPAGES(tp) |
672 | 2995 if (diff_buf_idx_tp(buf, tp) != DB_COUNT) |
2996 return TRUE; | |
2997 return FALSE; | |
7 | 2998 } |
2999 | |
3000 /* | |
3001 * Move "count" times in direction "dir" to the next diff block. | |
3002 * Return FAIL if there isn't such a diff block. | |
3003 */ | |
3004 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3005 diff_move_to(int dir, long count) |
7 | 3006 { |
3007 int idx; | |
3008 linenr_T lnum = curwin->w_cursor.lnum; | |
3009 diff_T *dp; | |
3010 | |
3011 idx = diff_buf_idx(curbuf); | |
672 | 3012 if (idx == DB_COUNT || curtab->tp_first_diff == NULL) |
7 | 3013 return FAIL; |
3014 | |
672 | 3015 if (curtab->tp_diff_invalid) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3016 ex_diffupdate(NULL); // update after a big change |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3017 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3018 if (curtab->tp_first_diff == NULL) // no diffs today |
7 | 3019 return FAIL; |
3020 | |
3021 while (--count >= 0) | |
3022 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3023 // Check if already before first diff. |
672 | 3024 if (dir == BACKWARD && lnum <= curtab->tp_first_diff->df_lnum[idx]) |
7 | 3025 break; |
3026 | |
672 | 3027 for (dp = curtab->tp_first_diff; ; dp = dp->df_next) |
7 | 3028 { |
3029 if (dp == NULL) | |
3030 break; | |
3031 if ((dir == FORWARD && lnum < dp->df_lnum[idx]) | |
3032 || (dir == BACKWARD | |
3033 && (dp->df_next == NULL | |
3034 || lnum <= dp->df_next->df_lnum[idx]))) | |
3035 { | |
3036 lnum = dp->df_lnum[idx]; | |
3037 break; | |
3038 } | |
3039 } | |
3040 } | |
3041 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3042 // don't end up past the end of the file |
7 | 3043 if (lnum > curbuf->b_ml.ml_line_count) |
3044 lnum = curbuf->b_ml.ml_line_count; | |
3045 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3046 // When the cursor didn't move at all we fail. |
7 | 3047 if (lnum == curwin->w_cursor.lnum) |
3048 return FAIL; | |
3049 | |
3050 setpcmark(); | |
3051 curwin->w_cursor.lnum = lnum; | |
3052 curwin->w_cursor.col = 0; | |
3053 | |
3054 return OK; | |
3055 } | |
3056 | |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3057 /* |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3058 * Return the line number in the current window that is closest to "lnum1" in |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3059 * "buf1" in diff mode. |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3060 */ |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3061 static linenr_T |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3062 diff_get_corresponding_line_int( |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3063 buf_T *buf1, |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3064 linenr_T lnum1) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3065 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3066 int idx1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3067 int idx2; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3068 diff_T *dp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3069 int baseline = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3070 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3071 idx1 = diff_buf_idx(buf1); |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3072 idx2 = diff_buf_idx(curbuf); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3073 if (idx1 == DB_COUNT || idx2 == DB_COUNT || curtab->tp_first_diff == NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3074 return lnum1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3075 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3076 if (curtab->tp_diff_invalid) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3077 ex_diffupdate(NULL); // update after a big change |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3078 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3079 if (curtab->tp_first_diff == NULL) // no diffs today |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3080 return lnum1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3081 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
3082 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3083 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3084 if (dp->df_lnum[idx1] > lnum1) |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3085 return lnum1 - baseline; |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3086 if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3087 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3088 // Inside the diffblock |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3089 baseline = lnum1 - dp->df_lnum[idx1]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3090 if (baseline > dp->df_count[idx2]) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3091 baseline = dp->df_count[idx2]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3092 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3093 return dp->df_lnum[idx2] + baseline; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3094 } |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3095 if ( (dp->df_lnum[idx1] == lnum1) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3096 && (dp->df_count[idx1] == 0) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3097 && (dp->df_lnum[idx2] <= curwin->w_cursor.lnum) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3098 && ((dp->df_lnum[idx2] + dp->df_count[idx2]) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3099 > curwin->w_cursor.lnum)) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3100 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3101 * Special case: if the cursor is just after a zero-count |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3102 * block (i.e. all filler) and the target cursor is already |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3103 * inside the corresponding block, leave the target cursor |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3104 * unmoved. This makes repeated CTRL-W W operations work |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3105 * as expected. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3106 */ |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3107 return curwin->w_cursor.lnum; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3108 baseline = (dp->df_lnum[idx1] + dp->df_count[idx1]) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3109 - (dp->df_lnum[idx2] + dp->df_count[idx2]); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3110 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3111 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3112 // If we get here then the cursor is after the last diff |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3113 return lnum1 - baseline; |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3114 } |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3115 |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3116 /* |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3117 * Return the line number in the current window that is closest to "lnum1" in |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3118 * "buf1" in diff mode. Checks the line number to be valid. |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3119 */ |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3120 linenr_T |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3121 diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3122 { |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3123 linenr_T lnum = diff_get_corresponding_line_int(buf1, lnum1); |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3124 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3125 // don't end up past the end of the file |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3126 if (lnum > curbuf->b_ml.ml_line_count) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3127 return curbuf->b_ml.ml_line_count; |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3128 return lnum; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3129 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3130 |
7 | 3131 /* |
3132 * For line "lnum" in the current window find the equivalent lnum in window | |
3133 * "wp", compensating for inserted/deleted lines. | |
3134 */ | |
3135 linenr_T | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3136 diff_lnum_win(linenr_T lnum, win_T *wp) |
7 | 3137 { |
3138 diff_T *dp; | |
3139 int idx; | |
3140 int i; | |
3141 linenr_T n; | |
3142 | |
3143 idx = diff_buf_idx(curbuf); | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3144 if (idx == DB_COUNT) // safety check |
7 | 3145 return (linenr_T)0; |
3146 | |
672 | 3147 if (curtab->tp_diff_invalid) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3148 ex_diffupdate(NULL); // update after a big change |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3149 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3150 // search for a change that includes "lnum" in the list of diffblocks. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
3151 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
7 | 3152 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
3153 break; | |
3154 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3155 // When after the last change, compute relative to the last line number. |
7 | 3156 if (dp == NULL) |
3157 return wp->w_buffer->b_ml.ml_line_count | |
3158 - (curbuf->b_ml.ml_line_count - lnum); | |
3159 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3160 // Find index for "wp". |
7 | 3161 i = diff_buf_idx(wp->w_buffer); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3162 if (i == DB_COUNT) // safety check |
7 | 3163 return (linenr_T)0; |
3164 | |
3165 n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]); | |
3166 if (n > dp->df_lnum[i] + dp->df_count[i]) | |
3167 n = dp->df_lnum[i] + dp->df_count[i]; | |
3168 return n; | |
3169 } | |
3170 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3171 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3172 * Handle an ED style diff line. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3173 * Return FAIL if the line does not contain diff info. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3174 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3175 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3176 parse_diff_ed( |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3177 char_u *line, |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3178 diffhunk_T *hunk) |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3179 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3180 char_u *p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3181 long f1, l1, f2, l2; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3182 int difftype; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3183 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3184 // The line must be one of three formats: |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3185 // change: {first}[,{last}]c{first}[,{last}] |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3186 // append: {first}a{first}[,{last}] |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3187 // delete: {first}[,{last}]d{first} |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3188 p = line; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3189 f1 = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3190 if (*p == ',') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3191 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3192 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3193 l1 = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3194 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3195 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3196 l1 = f1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3197 if (*p != 'a' && *p != 'c' && *p != 'd') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3198 return FAIL; // invalid diff format |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3199 difftype = *p++; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3200 f2 = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3201 if (*p == ',') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3202 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3203 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3204 l2 = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3205 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3206 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3207 l2 = f2; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3208 if (l1 < f1 || l2 < f2) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3209 return FAIL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3210 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3211 if (difftype == 'a') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3212 { |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3213 hunk->lnum_orig = f1 + 1; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3214 hunk->count_orig = 0; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3215 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3216 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3217 { |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3218 hunk->lnum_orig = f1; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3219 hunk->count_orig = l1 - f1 + 1; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3220 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3221 if (difftype == 'd') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3222 { |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3223 hunk->lnum_new = f2 + 1; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3224 hunk->count_new = 0; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3225 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3226 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3227 { |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3228 hunk->lnum_new = f2; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3229 hunk->count_new = l2 - f2 + 1; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3230 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3231 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3232 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3233 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3234 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3235 * Parses unified diff with zero(!) context lines. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3236 * Return FAIL if there is no diff information in "line". |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3237 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3238 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3239 parse_diff_unified( |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3240 char_u *line, |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3241 diffhunk_T *hunk) |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3242 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3243 char_u *p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3244 long oldline, oldcount, newline, newcount; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3245 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3246 // Parse unified diff hunk header: |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3247 // @@ -oldline,oldcount +newline,newcount @@ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3248 p = line; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3249 if (*p++ == '@' && *p++ == '@' && *p++ == ' ' && *p++ == '-') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3250 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3251 oldline = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3252 if (*p == ',') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3253 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3254 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3255 oldcount = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3256 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3257 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3258 oldcount = 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3259 if (*p++ == ' ' && *p++ == '+') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3260 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3261 newline = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3262 if (*p == ',') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3263 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3264 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3265 newcount = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3266 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3267 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3268 newcount = 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3269 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3270 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3271 return FAIL; // invalid diff format |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3272 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3273 if (oldcount == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3274 oldline += 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3275 if (newcount == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3276 newline += 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3277 if (newline == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3278 newline = 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3279 |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3280 hunk->lnum_orig = oldline; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3281 hunk->count_orig = oldcount; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3282 hunk->lnum_new = newline; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3283 hunk->count_new = newcount; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3284 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3285 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3286 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3287 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3288 return FAIL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3289 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3290 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3291 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3292 * Callback function for the xdl_diff() function. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3293 * Stores the diff output in a grow array. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3294 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3295 static int |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3296 xdiff_out( |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3297 long start_a, |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3298 long count_a, |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3299 long start_b, |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3300 long count_b, |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3301 void *priv) |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3302 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3303 diffout_T *dout = (diffout_T *)priv; |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3304 diffhunk_T *p = ALLOC_ONE(diffhunk_T); |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3305 |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3306 if (p == NULL) |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3307 return -1; |
14982
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3308 |
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3309 if (ga_grow(&dout->dout_ga, 1) == FAIL) |
26805
77ff030699d2
patch 8.2.3931: Coverity reports a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
26794
diff
changeset
|
3310 { |
77ff030699d2
patch 8.2.3931: Coverity reports a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
26794
diff
changeset
|
3311 vim_free(p); |
14982
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3312 return -1; |
26805
77ff030699d2
patch 8.2.3931: Coverity reports a memory leak
Bram Moolenaar <Bram@vim.org>
parents:
26794
diff
changeset
|
3313 } |
26786
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3314 |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3315 p->lnum_orig = start_a + 1; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3316 p->count_orig = count_a; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3317 p->lnum_new = start_b + 1; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3318 p->count_new = count_b; |
b802798e4a26
patch 8.2.3921: the way xdiff is used is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
3319 ((diffhunk_T **)dout->dout_ga.ga_data)[dout->dout_ga.ga_len++] = p; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3320 return 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3321 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3322 |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3323 #endif // FEAT_DIFF |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3324 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3325 #if defined(FEAT_EVAL) || defined(PROTO) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3326 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3327 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3328 * "diff_filler()" function |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3329 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3330 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3331 f_diff_filler(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3332 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3333 #ifdef FEAT_DIFF |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
3334 if (in_vim9script() && check_for_lnum_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
3335 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
3336 |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3337 rettv->vval.v_number = diff_check_fill(curwin, tv_get_lnum(argvars)); |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3338 #endif |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3339 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3340 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3341 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3342 * "diff_hlID()" function |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3343 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3344 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3345 f_diff_hlID(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3346 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3347 #ifdef FEAT_DIFF |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24683
diff
changeset
|
3348 linenr_T lnum; |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3349 static linenr_T prev_lnum = 0; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3350 static varnumber_T changedtick = 0; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3351 static int fnum = 0; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3352 static int change_start = 0; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3353 static int change_end = 0; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3354 static hlf_T hlID = (hlf_T)0; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3355 int filler_lines; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3356 int col; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3357 |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24683
diff
changeset
|
3358 if (in_vim9script() |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
3359 && (check_for_lnum_arg(argvars,0) == FAIL |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24683
diff
changeset
|
3360 || check_for_number_arg(argvars, 1) == FAIL)) |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24683
diff
changeset
|
3361 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24683
diff
changeset
|
3362 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24683
diff
changeset
|
3363 lnum = tv_get_lnum(argvars); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3364 if (lnum < 0) // ignore type error in {lnum} arg |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3365 lnum = 0; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3366 if (lnum != prev_lnum |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3367 || changedtick != CHANGEDTICK(curbuf) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3368 || fnum != curbuf->b_fnum) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3369 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3370 // New line, buffer, change: need to get the values. |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3371 filler_lines = diff_check(curwin, lnum); |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3372 if (filler_lines < 0) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3373 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3374 if (filler_lines == -1) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3375 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3376 change_start = MAXCOL; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3377 change_end = -1; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3378 if (diff_find_change(curwin, lnum, &change_start, &change_end)) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3379 hlID = HLF_ADD; // added line |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3380 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3381 hlID = HLF_CHD; // changed line |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3382 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3383 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3384 hlID = HLF_ADD; // added line |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3385 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3386 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3387 hlID = (hlf_T)0; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3388 prev_lnum = lnum; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3389 changedtick = CHANGEDTICK(curbuf); |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3390 fnum = curbuf->b_fnum; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3391 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3392 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3393 if (hlID == HLF_CHD || hlID == HLF_TXD) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3394 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3395 col = tv_get_number(&argvars[1]) - 1; // ignore type error in {col} |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3396 if (col >= change_start && col <= change_end) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3397 hlID = HLF_TXD; // changed text |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3398 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3399 hlID = HLF_CHD; // changed line |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3400 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3401 rettv->vval.v_number = hlID == (hlf_T)0 ? 0 : (int)hlID; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3402 #endif |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3403 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3404 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3405 #endif |