Mercurial > vim
annotate src/diff.c @ 14152:b9e6127eafbd
Added tag v8.1.0093 for changeset 2404459a8639520c39a212092c78086f2c7631f2
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 21 Jun 2018 20:45:06 +0200 |
parents | dc67449d648c |
children | 195e8b1fcbbf |
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. |
7 | 12 */ |
13 | |
14 #include "vim.h" | |
15 | |
16 #if defined(FEAT_DIFF) || defined(PROTO) | |
17 | |
18 static int diff_busy = FALSE; /* ex_diffgetput() is busy */ | |
19 | |
20 /* flags obtained from the 'diffopt' option */ | |
21 #define DIFF_FILLER 1 /* display filler lines */ | |
22 #define DIFF_ICASE 2 /* ignore case */ | |
23 #define DIFF_IWHITE 4 /* ignore change in white space */ | |
764 | 24 #define DIFF_HORIZONTAL 8 /* horizontal splits */ |
25 #define DIFF_VERTICAL 16 /* vertical splits */ | |
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
|
26 #define DIFF_HIDDEN_OFF 32 /* diffoff when hidden */ |
7 | 27 static int diff_flags = DIFF_FILLER; |
28 | |
29 #define LBUFLEN 50 /* length of line in diff file */ | |
30 | |
31 static int diff_a_works = MAYBE; /* TRUE when "diff -a" works, FALSE when it | |
32 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
|
33 #if defined(MSWIN) |
7 | 34 static int diff_bin_works = MAYBE; /* TRUE when "diff --binary" works, FALSE |
35 when it doesn't work, MAYBE when not | |
36 checked yet */ | |
37 #endif | |
38 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 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
|
43 static int diff_check_sanity(tabpage_T *tp, diff_T *dp); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
44 static void diff_redraw(int dofold); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
45 static int diff_write(buf_T *buf, char_u *fname); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
46 static void diff_file(char_u *tmp_orig, char_u *tmp_new, char_u *tmp_diff); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
47 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
|
48 static int diff_cmp(char_u *s1, char_u *s2); |
7 | 49 #ifdef FEAT_FOLDING |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
50 static void diff_fold_update(diff_T *dp, int skip_idx); |
7 | 51 #endif |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
52 static void diff_read(int idx_orig, int idx_new, char_u *fname); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
53 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
|
54 static diff_T *diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp); |
7 | 55 |
56 #ifndef USE_CR | |
57 # define tag_fgets vim_fgets | |
58 #endif | |
59 | |
60 /* | |
61 * Called when deleting or unloading a buffer: No longer make a diff with it. | |
62 */ | |
63 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
64 diff_buf_delete(buf_T *buf) |
7 | 65 { |
66 int i; | |
672 | 67 tabpage_T *tp; |
7 | 68 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
69 FOR_ALL_TABPAGES(tp) |
7 | 70 { |
672 | 71 i = diff_buf_idx_tp(buf, tp); |
72 if (i != DB_COUNT) | |
73 { | |
74 tp->tp_diffbuf[i] = NULL; | |
75 tp->tp_diff_invalid = TRUE; | |
1761 | 76 if (tp == curtab) |
77 diff_redraw(TRUE); | |
672 | 78 } |
7 | 79 } |
80 } | |
81 | |
82 /* | |
16 | 83 * Check if the current buffer should be added to or removed from the list of |
84 * diff buffers. | |
85 */ | |
86 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
87 diff_buf_adjust(win_T *win) |
16 | 88 { |
89 win_T *wp; | |
672 | 90 int i; |
16 | 91 |
92 if (!win->w_p_diff) | |
93 { | |
94 /* When there is no window showing a diff for this buffer, remove | |
95 * it from the diffs. */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
96 FOR_ALL_WINDOWS(wp) |
16 | 97 if (wp->w_buffer == win->w_buffer && wp->w_p_diff) |
98 break; | |
99 if (wp == NULL) | |
672 | 100 { |
101 i = diff_buf_idx(win->w_buffer); | |
102 if (i != DB_COUNT) | |
103 { | |
104 curtab->tp_diffbuf[i] = NULL; | |
105 curtab->tp_diff_invalid = TRUE; | |
1761 | 106 diff_redraw(TRUE); |
672 | 107 } |
108 } | |
16 | 109 } |
110 else | |
111 diff_buf_add(win->w_buffer); | |
112 } | |
113 | |
114 /* | |
7 | 115 * Add a buffer to make diffs for. |
672 | 116 * Call this when a new buffer is being edited in the current window where |
117 * 'diff' is set. | |
1788 | 118 * Marks the current buffer as being part of the diff and requiring updating. |
672 | 119 * This must be done before any autocmd, because a command may use info |
120 * about the screen contents. | |
7 | 121 */ |
122 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
123 diff_buf_add(buf_T *buf) |
7 | 124 { |
125 int i; | |
126 | |
127 if (diff_buf_idx(buf) != DB_COUNT) | |
128 return; /* It's already there. */ | |
129 | |
130 for (i = 0; i < DB_COUNT; ++i) | |
672 | 131 if (curtab->tp_diffbuf[i] == NULL) |
7 | 132 { |
672 | 133 curtab->tp_diffbuf[i] = buf; |
134 curtab->tp_diff_invalid = TRUE; | |
1761 | 135 diff_redraw(TRUE); |
7 | 136 return; |
137 } | |
138 | |
9719
219dbe63ad2a
commit https://github.com/vim/vim/commit/89eaa4185efacab253b23a182c1c8a7bbf1096c9
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
139 EMSGN(_("E96: Cannot diff more than %ld buffers"), DB_COUNT); |
7 | 140 } |
141 | |
142 /* | |
10821
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
143 * 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
|
144 */ |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
145 static void |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
146 diff_buf_clear(void) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
147 { |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
148 int i; |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
149 |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
150 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
|
151 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
|
152 { |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
153 curtab->tp_diffbuf[i] = NULL; |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
154 curtab->tp_diff_invalid = TRUE; |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
155 diff_redraw(TRUE); |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
156 } |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
157 } |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
158 |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
159 /* |
672 | 160 * Find buffer "buf" in the list of diff buffers for the current tab page. |
7 | 161 * Return its index or DB_COUNT if not found. |
162 */ | |
163 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
164 diff_buf_idx(buf_T *buf) |
7 | 165 { |
166 int idx; | |
167 | |
168 for (idx = 0; idx < DB_COUNT; ++idx) | |
672 | 169 if (curtab->tp_diffbuf[idx] == buf) |
170 break; | |
171 return idx; | |
172 } | |
173 | |
174 /* | |
175 * Find buffer "buf" in the list of diff buffers for tab page "tp". | |
176 * Return its index or DB_COUNT if not found. | |
177 */ | |
178 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
179 diff_buf_idx_tp(buf_T *buf, tabpage_T *tp) |
672 | 180 { |
181 int idx; | |
182 | |
183 for (idx = 0; idx < DB_COUNT; ++idx) | |
184 if (tp->tp_diffbuf[idx] == buf) | |
7 | 185 break; |
186 return idx; | |
187 } | |
188 | |
189 /* | |
672 | 190 * Mark the diff info involving buffer "buf" as invalid, it will be updated |
191 * when info is requested. | |
7 | 192 */ |
193 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
194 diff_invalidate(buf_T *buf) |
7 | 195 { |
672 | 196 tabpage_T *tp; |
197 int i; | |
198 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
199 FOR_ALL_TABPAGES(tp) |
7 | 200 { |
672 | 201 i = diff_buf_idx_tp(buf, tp); |
202 if (i != DB_COUNT) | |
203 { | |
204 tp->tp_diff_invalid = TRUE; | |
205 if (tp == curtab) | |
206 diff_redraw(TRUE); | |
207 } | |
7 | 208 } |
209 } | |
210 | |
211 /* | |
672 | 212 * Called by mark_adjust(): update line numbers in "curbuf". |
7 | 213 */ |
214 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
215 diff_mark_adjust( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
216 linenr_T line1, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
217 linenr_T line2, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
218 long amount, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
219 long amount_after) |
7 | 220 { |
672 | 221 int idx; |
222 tabpage_T *tp; | |
223 | |
224 /* 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
|
225 FOR_ALL_TABPAGES(tp) |
672 | 226 { |
227 idx = diff_buf_idx_tp(curbuf, tp); | |
228 if (idx != DB_COUNT) | |
229 diff_mark_adjust_tp(tp, idx, line1, line2, amount, amount_after); | |
230 } | |
231 } | |
232 | |
233 /* | |
234 * Update line numbers in tab page "tp" for "curbuf" with index "idx". | |
235 * This attempts to update the changes as much as possible: | |
236 * When inserting/deleting lines outside of existing change blocks, create a | |
237 * new change block and update the line numbers in following blocks. | |
238 * When inserting/deleting lines in existing change blocks, update them. | |
239 */ | |
240 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
241 diff_mark_adjust_tp( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
242 tabpage_T *tp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
243 int idx, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
244 linenr_T line1, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
245 linenr_T line2, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
246 long amount, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
247 long amount_after) |
672 | 248 { |
7 | 249 diff_T *dp; |
250 diff_T *dprev; | |
251 diff_T *dnext; | |
252 int i; | |
253 int inserted, deleted; | |
254 int n, off; | |
255 linenr_T last; | |
256 linenr_T lnum_deleted = line1; /* lnum of remaining deletion */ | |
257 int check_unchanged; | |
258 | |
259 if (line2 == MAXLNUM) | |
260 { | |
261 /* mark_adjust(99, MAXLNUM, 9, 0): insert lines */ | |
262 inserted = amount; | |
263 deleted = 0; | |
264 } | |
265 else if (amount_after > 0) | |
266 { | |
267 /* mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines*/ | |
268 inserted = amount_after; | |
269 deleted = 0; | |
270 } | |
271 else | |
272 { | |
273 /* mark_adjust(98, 99, MAXLNUM, -2): delete lines */ | |
274 inserted = 0; | |
275 deleted = -amount_after; | |
276 } | |
277 | |
278 dprev = NULL; | |
672 | 279 dp = tp->tp_first_diff; |
7 | 280 for (;;) |
281 { | |
282 /* If the change is after the previous diff block and before the next | |
283 * diff block, thus not touching an existing change, create a new diff | |
284 * block. Don't do this when ex_diffgetput() is busy. */ | |
285 if ((dp == NULL || dp->df_lnum[idx] - 1 > line2 | |
286 || (line2 == MAXLNUM && dp->df_lnum[idx] > line1)) | |
287 && (dprev == NULL | |
288 || dprev->df_lnum[idx] + dprev->df_count[idx] < line1) | |
289 && !diff_busy) | |
290 { | |
672 | 291 dnext = diff_alloc_new(tp, dprev, dp); |
7 | 292 if (dnext == NULL) |
293 return; | |
294 | |
295 dnext->df_lnum[idx] = line1; | |
296 dnext->df_count[idx] = inserted; | |
297 for (i = 0; i < DB_COUNT; ++i) | |
672 | 298 if (tp->tp_diffbuf[i] != NULL && i != idx) |
7 | 299 { |
300 if (dprev == NULL) | |
301 dnext->df_lnum[i] = line1; | |
302 else | |
303 dnext->df_lnum[i] = line1 | |
304 + (dprev->df_lnum[i] + dprev->df_count[i]) | |
305 - (dprev->df_lnum[idx] + dprev->df_count[idx]); | |
306 dnext->df_count[i] = deleted; | |
307 } | |
308 } | |
309 | |
310 /* if at end of the list, quit */ | |
311 if (dp == NULL) | |
312 break; | |
313 | |
314 /* | |
315 * Check for these situations: | |
316 * 1 2 3 | |
317 * 1 2 3 | |
318 * line1 2 3 4 5 | |
319 * 2 3 4 5 | |
320 * 2 3 4 5 | |
321 * line2 2 3 4 5 | |
322 * 3 5 6 | |
323 * 3 5 6 | |
324 */ | |
325 /* compute last line of this change */ | |
326 last = dp->df_lnum[idx] + dp->df_count[idx] - 1; | |
327 | |
328 /* 1. change completely above line1: nothing to do */ | |
329 if (last >= line1 - 1) | |
330 { | |
331 /* 6. change below line2: only adjust for amount_after; also when | |
332 * "deleted" became zero when deleted all lines between two diffs */ | |
333 if (dp->df_lnum[idx] - (deleted + inserted != 0) > line2) | |
334 { | |
335 if (amount_after == 0) | |
336 break; /* nothing left to change */ | |
337 dp->df_lnum[idx] += amount_after; | |
338 } | |
339 else | |
340 { | |
341 check_unchanged = FALSE; | |
342 | |
343 /* 2. 3. 4. 5.: inserted/deleted lines touching this diff. */ | |
344 if (deleted > 0) | |
345 { | |
346 if (dp->df_lnum[idx] >= line1) | |
347 { | |
348 off = dp->df_lnum[idx] - lnum_deleted; | |
349 if (last <= line2) | |
350 { | |
351 /* 4. delete all lines of diff */ | |
352 if (dp->df_next != NULL | |
353 && dp->df_next->df_lnum[idx] - 1 <= line2) | |
354 { | |
355 /* delete continues in next diff, only do | |
356 * lines until that one */ | |
357 n = dp->df_next->df_lnum[idx] - lnum_deleted; | |
358 deleted -= n; | |
359 n -= dp->df_count[idx]; | |
360 lnum_deleted = dp->df_next->df_lnum[idx]; | |
361 } | |
362 else | |
363 n = deleted - dp->df_count[idx]; | |
364 dp->df_count[idx] = 0; | |
365 } | |
366 else | |
367 { | |
368 /* 5. delete lines at or just before top of diff */ | |
369 n = off; | |
370 dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1; | |
371 check_unchanged = TRUE; | |
372 } | |
373 dp->df_lnum[idx] = line1; | |
374 } | |
375 else | |
376 { | |
377 off = 0; | |
378 if (last < line2) | |
379 { | |
380 /* 2. delete at end of of diff */ | |
381 dp->df_count[idx] -= last - lnum_deleted + 1; | |
382 if (dp->df_next != NULL | |
383 && dp->df_next->df_lnum[idx] - 1 <= line2) | |
384 { | |
385 /* delete continues in next diff, only do | |
386 * lines until that one */ | |
387 n = dp->df_next->df_lnum[idx] - 1 - last; | |
388 deleted -= dp->df_next->df_lnum[idx] | |
389 - lnum_deleted; | |
390 lnum_deleted = dp->df_next->df_lnum[idx]; | |
391 } | |
392 else | |
393 n = line2 - last; | |
394 check_unchanged = TRUE; | |
395 } | |
396 else | |
397 { | |
398 /* 3. delete lines inside the diff */ | |
399 n = 0; | |
400 dp->df_count[idx] -= deleted; | |
401 } | |
402 } | |
403 | |
404 for (i = 0; i < DB_COUNT; ++i) | |
672 | 405 if (tp->tp_diffbuf[i] != NULL && i != idx) |
7 | 406 { |
407 dp->df_lnum[i] -= off; | |
408 dp->df_count[i] += n; | |
409 } | |
410 } | |
411 else | |
412 { | |
413 if (dp->df_lnum[idx] <= line1) | |
414 { | |
415 /* inserted lines somewhere in this diff */ | |
416 dp->df_count[idx] += inserted; | |
417 check_unchanged = TRUE; | |
418 } | |
419 else | |
420 /* inserted lines somewhere above this diff */ | |
421 dp->df_lnum[idx] += inserted; | |
422 } | |
423 | |
424 if (check_unchanged) | |
425 /* Check if inserted lines are equal, may reduce the | |
426 * size of the diff. TODO: also check for equal lines | |
427 * in the middle and perhaps split the block. */ | |
672 | 428 diff_check_unchanged(tp, dp); |
7 | 429 } |
430 } | |
431 | |
432 /* check if this block touches the previous one, may merge them. */ | |
433 if (dprev != NULL && dprev->df_lnum[idx] + dprev->df_count[idx] | |
434 == dp->df_lnum[idx]) | |
435 { | |
436 for (i = 0; i < DB_COUNT; ++i) | |
672 | 437 if (tp->tp_diffbuf[i] != NULL) |
7 | 438 dprev->df_count[i] += dp->df_count[i]; |
439 dprev->df_next = dp->df_next; | |
440 vim_free(dp); | |
441 dp = dprev->df_next; | |
442 } | |
443 else | |
444 { | |
445 /* Advance to next entry. */ | |
446 dprev = dp; | |
447 dp = dp->df_next; | |
448 } | |
449 } | |
450 | |
451 dprev = NULL; | |
672 | 452 dp = tp->tp_first_diff; |
7 | 453 while (dp != NULL) |
454 { | |
455 /* All counts are zero, remove this entry. */ | |
456 for (i = 0; i < DB_COUNT; ++i) | |
672 | 457 if (tp->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) |
7 | 458 break; |
459 if (i == DB_COUNT) | |
460 { | |
461 dnext = dp->df_next; | |
462 vim_free(dp); | |
463 dp = dnext; | |
464 if (dprev == NULL) | |
672 | 465 tp->tp_first_diff = dnext; |
7 | 466 else |
467 dprev->df_next = dnext; | |
468 } | |
469 else | |
470 { | |
471 /* Advance to next entry. */ | |
472 dprev = dp; | |
473 dp = dp->df_next; | |
474 } | |
475 | |
476 } | |
672 | 477 |
478 if (tp == curtab) | |
479 { | |
480 diff_redraw(TRUE); | |
7 | 481 |
672 | 482 /* Need to recompute the scroll binding, may remove or add filler |
483 * lines (e.g., when adding lines above w_topline). But it's slow when | |
484 * making many changes, postpone until redrawing. */ | |
485 diff_need_scrollbind = TRUE; | |
486 } | |
7 | 487 } |
488 | |
489 /* | |
490 * Allocate a new diff block and link it between "dprev" and "dp". | |
491 */ | |
492 static diff_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
493 diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) |
7 | 494 { |
495 diff_T *dnew; | |
496 | |
497 dnew = (diff_T *)alloc((unsigned)sizeof(diff_T)); | |
498 if (dnew != NULL) | |
499 { | |
500 dnew->df_next = dp; | |
501 if (dprev == NULL) | |
672 | 502 tp->tp_first_diff = dnew; |
7 | 503 else |
504 dprev->df_next = dnew; | |
505 } | |
506 return dnew; | |
507 } | |
508 | |
509 /* | |
510 * Check if the diff block "dp" can be made smaller for lines at the start and | |
511 * end that are equal. Called after inserting lines. | |
512 * This may result in a change where all buffers have zero lines, the caller | |
513 * must take care of removing it. | |
514 */ | |
515 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
516 diff_check_unchanged(tabpage_T *tp, diff_T *dp) |
7 | 517 { |
518 int i_org; | |
519 int i_new; | |
520 int off_org, off_new; | |
521 char_u *line_org; | |
522 int dir = FORWARD; | |
523 | |
524 /* Find the first buffers, use it as the original, compare the other | |
525 * buffer lines against this one. */ | |
526 for (i_org = 0; i_org < DB_COUNT; ++i_org) | |
672 | 527 if (tp->tp_diffbuf[i_org] != NULL) |
7 | 528 break; |
529 if (i_org == DB_COUNT) /* safety check */ | |
530 return; | |
531 | |
672 | 532 if (diff_check_sanity(tp, dp) == FAIL) |
7 | 533 return; |
534 | |
535 /* First check lines at the top, then at the bottom. */ | |
536 off_org = 0; | |
537 off_new = 0; | |
538 for (;;) | |
539 { | |
540 /* Repeat until a line is found which is different or the number of | |
541 * lines has become zero. */ | |
542 while (dp->df_count[i_org] > 0) | |
543 { | |
544 /* Copy the line, the next ml_get() will invalidate it. */ | |
545 if (dir == BACKWARD) | |
546 off_org = dp->df_count[i_org] - 1; | |
672 | 547 line_org = vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], |
7 | 548 dp->df_lnum[i_org] + off_org, FALSE)); |
549 if (line_org == NULL) | |
550 return; | |
551 for (i_new = i_org + 1; i_new < DB_COUNT; ++i_new) | |
552 { | |
672 | 553 if (tp->tp_diffbuf[i_new] == NULL) |
7 | 554 continue; |
555 if (dir == BACKWARD) | |
556 off_new = dp->df_count[i_new] - 1; | |
557 /* if other buffer doesn't have this line, it was inserted */ | |
558 if (off_new < 0 || off_new >= dp->df_count[i_new]) | |
559 break; | |
672 | 560 if (diff_cmp(line_org, ml_get_buf(tp->tp_diffbuf[i_new], |
7 | 561 dp->df_lnum[i_new] + off_new, FALSE)) != 0) |
562 break; | |
563 } | |
564 vim_free(line_org); | |
565 | |
566 /* Stop when a line isn't equal in all diff buffers. */ | |
567 if (i_new != DB_COUNT) | |
568 break; | |
569 | |
570 /* Line matched in all buffers, remove it from the diff. */ | |
571 for (i_new = i_org; i_new < DB_COUNT; ++i_new) | |
672 | 572 if (tp->tp_diffbuf[i_new] != NULL) |
7 | 573 { |
574 if (dir == FORWARD) | |
575 ++dp->df_lnum[i_new]; | |
576 --dp->df_count[i_new]; | |
577 } | |
578 } | |
579 if (dir == BACKWARD) | |
580 break; | |
581 dir = BACKWARD; | |
582 } | |
583 } | |
584 | |
585 /* | |
586 * Check if a diff block doesn't contain invalid line numbers. | |
587 * This can happen when the diff program returns invalid results. | |
588 */ | |
589 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
590 diff_check_sanity(tabpage_T *tp, diff_T *dp) |
7 | 591 { |
592 int i; | |
593 | |
594 for (i = 0; i < DB_COUNT; ++i) | |
672 | 595 if (tp->tp_diffbuf[i] != NULL) |
7 | 596 if (dp->df_lnum[i] + dp->df_count[i] - 1 |
672 | 597 > tp->tp_diffbuf[i]->b_ml.ml_line_count) |
7 | 598 return FAIL; |
599 return OK; | |
600 } | |
601 | |
602 /* | |
672 | 603 * Mark all diff buffers in the current tab page for redraw. |
7 | 604 */ |
605 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
606 diff_redraw( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
607 int dofold) /* also recompute the folds */ |
7 | 608 { |
609 win_T *wp; | |
610 int n; | |
611 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
612 FOR_ALL_WINDOWS(wp) |
7 | 613 if (wp->w_p_diff) |
614 { | |
738 | 615 redraw_win_later(wp, SOME_VALID); |
7 | 616 #ifdef FEAT_FOLDING |
617 if (dofold && foldmethodIsDiff(wp)) | |
618 foldUpdateAll(wp); | |
619 #endif | |
620 /* A change may have made filler lines invalid, need to take care | |
621 * of that for other windows. */ | |
3904 | 622 n = diff_check(wp, wp->w_topline); |
623 if ((wp != curwin && wp->w_topfill > 0) || n > 0) | |
7 | 624 { |
625 if (wp->w_topfill > n) | |
626 wp->w_topfill = (n < 0 ? 0 : n); | |
3904 | 627 else if (n > 0 && n > wp->w_topfill) |
628 wp->w_topfill = n; | |
5934 | 629 check_topfill(wp, FALSE); |
7 | 630 } |
631 } | |
632 } | |
633 | |
634 /* | |
635 * Write buffer "buf" to file "name". | |
636 * Always use 'fileformat' set to "unix". | |
637 * Return FAIL for failure | |
638 */ | |
639 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
640 diff_write(buf_T *buf, char_u *fname) |
7 | 641 { |
642 int r; | |
643 char_u *save_ff; | |
644 | |
645 save_ff = buf->b_p_ff; | |
646 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); | |
647 r = buf_write(buf, fname, NULL, (linenr_T)1, buf->b_ml.ml_line_count, | |
648 NULL, FALSE, FALSE, FALSE, TRUE); | |
649 free_string_option(buf->b_p_ff); | |
650 buf->b_p_ff = save_ff; | |
651 return r; | |
652 } | |
653 | |
654 /* | |
655 * Completely update the diffs for the buffers involved. | |
656 * This uses the ordinary "diff" command. | |
657 * The buffers are written to a file, also for unmodified buffers (the file | |
658 * could have been produced by autocommands, e.g. the netrw plugin). | |
659 */ | |
660 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
661 ex_diffupdate( |
8368
db2a07b710ed
commit https://github.com/vim/vim/commit/f1d2501ebe33e148886c2914acd33140e20ee222
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
662 exarg_T *eap) /* can be NULL */ |
7 | 663 { |
664 buf_T *buf; | |
665 int idx_orig; | |
666 int idx_new; | |
667 char_u *tmp_orig; | |
668 char_u *tmp_new; | |
669 char_u *tmp_diff; | |
670 FILE *fd; | |
671 int ok; | |
1757 | 672 int io_error = FALSE; |
7 | 673 |
674 /* Delete all diffblocks. */ | |
672 | 675 diff_clear(curtab); |
676 curtab->tp_diff_invalid = FALSE; | |
7 | 677 |
678 /* Use the first buffer as the original text. */ | |
679 for (idx_orig = 0; idx_orig < DB_COUNT; ++idx_orig) | |
672 | 680 if (curtab->tp_diffbuf[idx_orig] != NULL) |
7 | 681 break; |
682 if (idx_orig == DB_COUNT) | |
683 return; | |
684 | |
685 /* Only need to do something when there is another buffer. */ | |
686 for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) | |
672 | 687 if (curtab->tp_diffbuf[idx_new] != NULL) |
7 | 688 break; |
689 if (idx_new == DB_COUNT) | |
690 return; | |
691 | |
692 /* We need three temp file names. */ | |
6721 | 693 tmp_orig = vim_tempname('o', TRUE); |
694 tmp_new = vim_tempname('n', TRUE); | |
695 tmp_diff = vim_tempname('d', TRUE); | |
7 | 696 if (tmp_orig == NULL || tmp_new == NULL || tmp_diff == NULL) |
697 goto theend; | |
698 | |
699 /* | |
700 * Do a quick test if "diff" really works. Otherwise it looks like there | |
701 * are no differences. Can't use the return value, it's non-zero when | |
702 * there are differences. | |
703 * May try twice, first with "-a" and then without. | |
704 */ | |
705 for (;;) | |
706 { | |
707 ok = FALSE; | |
531 | 708 fd = mch_fopen((char *)tmp_orig, "w"); |
1757 | 709 if (fd == NULL) |
710 io_error = TRUE; | |
711 else | |
7 | 712 { |
1757 | 713 if (fwrite("line1\n", (size_t)6, (size_t)1, fd) != 1) |
714 io_error = TRUE; | |
7 | 715 fclose(fd); |
531 | 716 fd = mch_fopen((char *)tmp_new, "w"); |
1757 | 717 if (fd == NULL) |
718 io_error = TRUE; | |
719 else | |
7 | 720 { |
1757 | 721 if (fwrite("line2\n", (size_t)6, (size_t)1, fd) != 1) |
722 io_error = TRUE; | |
7 | 723 fclose(fd); |
724 diff_file(tmp_orig, tmp_new, tmp_diff); | |
531 | 725 fd = mch_fopen((char *)tmp_diff, "r"); |
1757 | 726 if (fd == NULL) |
727 io_error = TRUE; | |
728 else | |
7 | 729 { |
730 char_u linebuf[LBUFLEN]; | |
731 | |
732 for (;;) | |
733 { | |
734 /* There must be a line that contains "1c1". */ | |
735 if (tag_fgets(linebuf, LBUFLEN, fd)) | |
736 break; | |
737 if (STRNCMP(linebuf, "1c1", 3) == 0) | |
738 ok = TRUE; | |
739 } | |
740 fclose(fd); | |
741 } | |
742 mch_remove(tmp_diff); | |
743 mch_remove(tmp_new); | |
744 } | |
745 mch_remove(tmp_orig); | |
746 } | |
747 | |
748 #ifdef FEAT_EVAL | |
749 /* When using 'diffexpr' break here. */ | |
750 if (*p_dex != NUL) | |
751 break; | |
752 #endif | |
753 | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
754 #if defined(MSWIN) |
7 | 755 /* If the "-a" argument works, also check if "--binary" works. */ |
756 if (ok && diff_a_works == MAYBE && diff_bin_works == MAYBE) | |
757 { | |
758 diff_a_works = TRUE; | |
759 diff_bin_works = TRUE; | |
760 continue; | |
761 } | |
762 if (!ok && diff_a_works == TRUE && diff_bin_works == TRUE) | |
763 { | |
764 /* Tried --binary, but it failed. "-a" works though. */ | |
765 diff_bin_works = FALSE; | |
766 ok = TRUE; | |
767 } | |
768 #endif | |
769 | |
770 /* If we checked if "-a" works already, break here. */ | |
771 if (diff_a_works != MAYBE) | |
772 break; | |
773 diff_a_works = ok; | |
774 | |
775 /* If "-a" works break here, otherwise retry without "-a". */ | |
776 if (ok) | |
777 break; | |
778 } | |
779 if (!ok) | |
780 { | |
1757 | 781 if (io_error) |
782 EMSG(_("E810: Cannot read or write temp files")); | |
7 | 783 EMSG(_("E97: Cannot create diffs")); |
784 diff_a_works = MAYBE; | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
785 #if defined(MSWIN) |
7 | 786 diff_bin_works = MAYBE; |
787 #endif | |
788 goto theend; | |
789 } | |
790 | |
3524 | 791 /* :diffupdate! */ |
792 if (eap != NULL && eap->forceit) | |
793 for (idx_new = idx_orig; idx_new < DB_COUNT; ++idx_new) | |
794 { | |
795 buf = curtab->tp_diffbuf[idx_new]; | |
796 if (buf_valid(buf)) | |
797 buf_check_timestamp(buf, FALSE); | |
798 } | |
799 | |
7 | 800 /* Write the first buffer to a tempfile. */ |
672 | 801 buf = curtab->tp_diffbuf[idx_orig]; |
7 | 802 if (diff_write(buf, tmp_orig) == FAIL) |
803 goto theend; | |
804 | |
805 /* Make a difference between the first buffer and every other. */ | |
806 for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) | |
807 { | |
672 | 808 buf = curtab->tp_diffbuf[idx_new]; |
6985 | 809 if (buf == NULL || buf->b_ml.ml_mfp == NULL) |
810 continue; /* skip buffer that isn't loaded */ | |
7 | 811 if (diff_write(buf, tmp_new) == FAIL) |
812 continue; | |
813 diff_file(tmp_orig, tmp_new, tmp_diff); | |
814 | |
815 /* Read the diff output and add each entry to the diff list. */ | |
816 diff_read(idx_orig, idx_new, tmp_diff); | |
817 mch_remove(tmp_diff); | |
818 mch_remove(tmp_new); | |
819 } | |
820 mch_remove(tmp_orig); | |
821 | |
1429 | 822 /* force updating cursor position on screen */ |
823 curwin->w_valid_cursor.lnum = 0; | |
824 | |
7 | 825 diff_redraw(TRUE); |
826 | |
827 theend: | |
828 vim_free(tmp_orig); | |
829 vim_free(tmp_new); | |
830 vim_free(tmp_diff); | |
831 } | |
832 | |
833 /* | |
834 * Make a diff between files "tmp_orig" and "tmp_new", results in "tmp_diff". | |
835 */ | |
836 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
837 diff_file( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
838 char_u *tmp_orig, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
839 char_u *tmp_new, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
840 char_u *tmp_diff) |
7 | 841 { |
842 char_u *cmd; | |
1872 | 843 size_t len; |
7 | 844 |
845 #ifdef FEAT_EVAL | |
846 if (*p_dex != NUL) | |
847 /* Use 'diffexpr' to generate the diff file. */ | |
848 eval_diff(tmp_orig, tmp_new, tmp_diff); | |
849 else | |
850 #endif | |
851 { | |
1872 | 852 len = STRLEN(tmp_orig) + STRLEN(tmp_new) |
853 + STRLEN(tmp_diff) + STRLEN(p_srr) + 27; | |
854 cmd = alloc((unsigned)len); | |
7 | 855 if (cmd != NULL) |
856 { | |
193 | 857 /* We don't want $DIFF_OPTIONS to get in the way. */ |
858 if (getenv("DIFF_OPTIONS")) | |
859 vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)""); | |
860 | |
7 | 861 /* Build the diff command and execute it. Always use -a, binary |
862 * differences are of no use. Ignore errors, diff returns | |
863 * non-zero when differences have been found. */ | |
1872 | 864 vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s %s", |
7 | 865 diff_a_works == FALSE ? "" : "-a ", |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
866 #if defined(MSWIN) |
7 | 867 diff_bin_works == TRUE ? "--binary " : "", |
868 #else | |
869 "", | |
870 #endif | |
871 (diff_flags & DIFF_IWHITE) ? "-b " : "", | |
872 (diff_flags & DIFF_ICASE) ? "-i " : "", | |
873 tmp_orig, tmp_new); | |
1872 | 874 append_redir(cmd, (int)len, p_srr, tmp_diff); |
1410 | 875 block_autocmds(); /* Avoid ShellCmdPost stuff */ |
7 | 876 (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT); |
1410 | 877 unblock_autocmds(); |
7 | 878 vim_free(cmd); |
879 } | |
880 } | |
881 } | |
882 | |
883 /* | |
884 * Create a new version of a file from the current buffer and a diff file. | |
885 * The buffer is written to a file, also for unmodified buffers (the file | |
886 * could have been produced by autocommands, e.g. the netrw plugin). | |
887 */ | |
888 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
889 ex_diffpatch(exarg_T *eap) |
7 | 890 { |
891 char_u *tmp_orig; /* name of original temp file */ | |
892 char_u *tmp_new; /* name of patched temp file */ | |
893 char_u *buf = NULL; | |
1872 | 894 size_t buflen; |
7 | 895 win_T *old_curwin = curwin; |
896 char_u *newname = NULL; /* name of patched file buffer */ | |
897 #ifdef UNIX | |
898 char_u dirbuf[MAXPATHL]; | |
899 char_u *fullname = NULL; | |
900 #endif | |
901 #ifdef FEAT_BROWSE | |
902 char_u *browseFile = NULL; | |
903 int browse_flag = cmdmod.browse; | |
904 #endif | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
905 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
|
906 char_u *esc_name = NULL; |
7 | 907 |
908 #ifdef FEAT_BROWSE | |
909 if (cmdmod.browse) | |
910 { | |
28 | 911 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
|
912 eap->arg, NULL, NULL, |
378f9f8e6d8f
patch 8.0.1773: dialog messages are not translated
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
913 (char_u *)_(BROWSE_FILTER_ALL_FILES), NULL); |
7 | 914 if (browseFile == NULL) |
915 return; /* operation cancelled */ | |
916 eap->arg = browseFile; | |
917 cmdmod.browse = FALSE; /* don't let do_ecmd() browse again */ | |
918 } | |
919 #endif | |
920 | |
921 /* We need two temp file names. */ | |
6721 | 922 tmp_orig = vim_tempname('o', FALSE); |
923 tmp_new = vim_tempname('n', FALSE); | |
7 | 924 if (tmp_orig == NULL || tmp_new == NULL) |
925 goto theend; | |
926 | |
927 /* Write the current buffer to "tmp_orig". */ | |
928 if (buf_write(curbuf, tmp_orig, NULL, | |
929 (linenr_T)1, curbuf->b_ml.ml_line_count, | |
930 NULL, FALSE, FALSE, FALSE, TRUE) == FAIL) | |
931 goto theend; | |
932 | |
933 #ifdef UNIX | |
934 /* Get the absolute path of the patchfile, changing directory below. */ | |
935 fullname = FullName_save(eap->arg, FALSE); | |
936 #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
|
937 esc_name = vim_strsave_shellescape( |
7 | 938 # 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
|
939 fullname != NULL ? fullname : |
7 | 940 # 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
|
941 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
|
942 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
|
943 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
|
944 buflen = STRLEN(tmp_orig) + STRLEN(esc_name) + STRLEN(tmp_new) + 16; |
1872 | 945 buf = alloc((unsigned)buflen); |
7 | 946 if (buf == NULL) |
947 goto theend; | |
948 | |
949 #ifdef UNIX | |
1788 | 950 /* Temporarily chdir to /tmp, to avoid patching files in the current |
7 | 951 * directory when the patch file contains more than one patch. When we |
952 * have our own temp dir use that instead, it will be cleaned up when we | |
953 * exit (any .rej files created). Don't change directory if we can't | |
954 * return to the current. */ | |
955 if (mch_dirname(dirbuf, MAXPATHL) != OK || mch_chdir((char *)dirbuf) != 0) | |
956 dirbuf[0] = NUL; | |
957 else | |
958 { | |
959 # ifdef TEMPDIRNAMES | |
960 if (vim_tempdir != NULL) | |
1757 | 961 ignored = mch_chdir((char *)vim_tempdir); |
7 | 962 else |
963 # endif | |
1757 | 964 ignored = mch_chdir("/tmp"); |
7 | 965 shorten_fnames(TRUE); |
966 } | |
967 #endif | |
968 | |
969 #ifdef FEAT_EVAL | |
970 if (*p_pex != NUL) | |
971 /* Use 'patchexpr' to generate the new file. */ | |
972 eval_patch(tmp_orig, | |
973 # ifdef UNIX | |
974 fullname != NULL ? fullname : | |
975 # endif | |
976 eap->arg, tmp_new); | |
977 else | |
978 #endif | |
979 { | |
980 /* Build the patch command and execute it. Ignore errors. Switch to | |
981 * 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
|
982 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
|
983 tmp_new, tmp_orig, esc_name); |
1410 | 984 block_autocmds(); /* Avoid ShellCmdPost stuff */ |
7 | 985 (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED); |
1410 | 986 unblock_autocmds(); |
7 | 987 } |
988 | |
989 #ifdef UNIX | |
990 if (dirbuf[0] != NUL) | |
991 { | |
992 if (mch_chdir((char *)dirbuf) != 0) | |
993 EMSG(_(e_prev_dir)); | |
994 shorten_fnames(TRUE); | |
995 } | |
996 #endif | |
997 | |
998 /* patch probably has written over the screen */ | |
999 redraw_later(CLEAR); | |
1000 | |
1001 /* Delete any .orig or .rej file created. */ | |
1002 STRCPY(buf, tmp_new); | |
1003 STRCAT(buf, ".orig"); | |
1004 mch_remove(buf); | |
1005 STRCPY(buf, tmp_new); | |
1006 STRCAT(buf, ".rej"); | |
1007 mch_remove(buf); | |
1008 | |
1942 | 1009 /* Only continue if the output file was created. */ |
1010 if (mch_stat((char *)tmp_new, &st) < 0 || st.st_size == 0) | |
1011 EMSG(_("E816: Cannot read patch output")); | |
1012 else | |
7 | 1013 { |
1942 | 1014 if (curbuf->b_fname != NULL) |
1015 { | |
1016 newname = vim_strnsave(curbuf->b_fname, | |
7 | 1017 (int)(STRLEN(curbuf->b_fname) + 4)); |
1942 | 1018 if (newname != NULL) |
1019 STRCAT(newname, ".new"); | |
1020 } | |
7 | 1021 |
1022 #ifdef FEAT_GUI | |
1942 | 1023 need_mouse_correct = TRUE; |
7 | 1024 #endif |
1942 | 1025 /* don't use a new tab page, each tab page has its own diffs */ |
1026 cmdmod.tab = 0; | |
682 | 1027 |
1942 | 1028 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) |
1029 { | |
1030 /* Pretend it was a ":split fname" command */ | |
1031 eap->cmdidx = CMD_split; | |
1032 eap->arg = tmp_new; | |
1033 do_exedit(eap, old_curwin); | |
7 | 1034 |
1942 | 1035 /* check that split worked and editing tmp_new */ |
1036 if (curwin != old_curwin && win_valid(old_curwin)) | |
1037 { | |
1038 /* Set 'diff', 'scrollbind' on and 'wrap' off. */ | |
1039 diff_win_options(curwin, TRUE); | |
1040 diff_win_options(old_curwin, TRUE); | |
7 | 1041 |
1942 | 1042 if (newname != NULL) |
1043 { | |
1044 /* do a ":file filename.new" on the patched buffer */ | |
1045 eap->arg = newname; | |
1046 ex_file(eap); | |
7 | 1047 |
1942 | 1048 /* Do filetype detection with the new name. */ |
1049 if (au_has_group((char_u *)"filetypedetect")) | |
1050 do_cmdline_cmd((char_u *)":doau filetypedetect BufRead"); | |
1051 } | |
7 | 1052 } |
1053 } | |
1054 } | |
1055 | |
1056 theend: | |
1057 if (tmp_orig != NULL) | |
1058 mch_remove(tmp_orig); | |
1059 vim_free(tmp_orig); | |
1060 if (tmp_new != NULL) | |
1061 mch_remove(tmp_new); | |
1062 vim_free(tmp_new); | |
1063 vim_free(newname); | |
1064 vim_free(buf); | |
1065 #ifdef UNIX | |
1066 vim_free(fullname); | |
1067 #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
|
1068 vim_free(esc_name); |
7 | 1069 #ifdef FEAT_BROWSE |
1070 vim_free(browseFile); | |
1071 cmdmod.browse = browse_flag; | |
1072 #endif | |
1073 } | |
1074 | |
1075 /* | |
1076 * Split the window and edit another file, setting options to show the diffs. | |
1077 */ | |
1078 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1079 ex_diffsplit(exarg_T *eap) |
7 | 1080 { |
1081 win_T *old_curwin = curwin; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1082 bufref_T old_curbuf; |
7 | 1083 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1084 set_bufref(&old_curbuf, curbuf); |
7 | 1085 #ifdef FEAT_GUI |
1086 need_mouse_correct = TRUE; | |
1087 #endif | |
10013
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1088 /* Need to compute w_fraction when no redraw happened yet. */ |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1089 validate_cursor(); |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1090 set_fraction(curwin); |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1091 |
682 | 1092 /* don't use a new tab page, each tab page has its own diffs */ |
1093 cmdmod.tab = 0; | |
1094 | |
764 | 1095 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) |
7 | 1096 { |
1097 /* Pretend it was a ":split fname" command */ | |
1098 eap->cmdidx = CMD_split; | |
449 | 1099 curwin->w_p_diff = TRUE; |
7 | 1100 do_exedit(eap, old_curwin); |
1101 | |
1102 if (curwin != old_curwin) /* split must have worked */ | |
1103 { | |
1104 /* Set 'diff', 'scrollbind' on and 'wrap' off. */ | |
1105 diff_win_options(curwin, TRUE); | |
7338
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1106 if (win_valid(old_curwin)) |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1107 { |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1108 diff_win_options(old_curwin, TRUE); |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1109 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1110 if (bufref_valid(&old_curbuf)) |
7338
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1111 /* Move the cursor position to that of the old window. */ |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1112 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
|
1113 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
|
1114 } |
10013
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1115 /* Now that lines are folded scroll to show the cursor at the same |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1116 * relative position. */ |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1117 scroll_to_fraction(curwin, curwin->w_height); |
7 | 1118 } |
1119 } | |
1120 } | |
1121 | |
1122 /* | |
4352 | 1123 * Set options to show diffs for the current window. |
7 | 1124 */ |
1125 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1126 ex_diffthis(exarg_T *eap UNUSED) |
7 | 1127 { |
1128 /* Set 'diff', 'scrollbind' on and 'wrap' off. */ | |
1129 diff_win_options(curwin, TRUE); | |
1130 } | |
1131 | |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1132 static void |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1133 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
|
1134 { |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1135 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
|
1136 |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1137 curwin = wp; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1138 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
|
1139 ++curbuf_lock; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1140 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
|
1141 --curbuf_lock; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1142 curwin = old_curwin; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1143 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
|
1144 } |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1145 |
7 | 1146 /* |
1147 * Set options in window "wp" for diff mode. | |
1148 */ | |
1149 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1150 diff_win_options( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1151 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1152 int addbuf) /* Add buffer to diff. */ |
7 | 1153 { |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1154 # ifdef FEAT_FOLDING |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1155 win_T *old_curwin = curwin; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1156 |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1157 /* close the manually opened folds */ |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1158 curwin = wp; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1159 newFoldLevel(); |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1160 curwin = old_curwin; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1161 # endif |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1162 |
2583 | 1163 /* Use 'scrollbind' and 'cursorbind' when available */ |
6897 | 1164 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1165 wp->w_p_scb_save = wp->w_p_scb; |
2583 | 1166 wp->w_p_scb = TRUE; |
6897 | 1167 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1168 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
|
1169 wp->w_p_crb = TRUE; |
6897 | 1170 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1171 wp->w_p_wrap_save = wp->w_p_wrap; |
7 | 1172 wp->w_p_wrap = FALSE; |
1173 # ifdef FEAT_FOLDING | |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1174 curwin = wp; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1175 curbuf = curwin->w_buffer; |
6897 | 1176 if (!wp->w_p_diff) |
1177 { | |
1178 if (wp->w_p_diff_saved) | |
1179 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
|
1180 wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm); |
6897 | 1181 } |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1182 set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff", |
694 | 1183 OPT_LOCAL|OPT_FREE, 0); |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1184 curwin = old_curwin; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1185 curbuf = curwin->w_buffer; |
6897 | 1186 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1187 { |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1188 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
|
1189 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
|
1190 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
|
1191 } |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1192 wp->w_p_fdc = diff_foldcolumn; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1193 wp->w_p_fen = TRUE; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1194 wp->w_p_fdl = 0; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1195 foldUpdateAll(wp); |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1196 /* make sure topline is not halfway a fold */ |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1197 changed_window_setting_win(wp); |
7 | 1198 # endif |
1199 if (vim_strchr(p_sbo, 'h') == NULL) | |
1200 do_cmdline_cmd((char_u *)"set sbo+=hor"); | |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1201 /* 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
|
1202 wp->w_p_diff_saved = TRUE; |
7 | 1203 |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1204 set_diff_option(wp, TRUE); |
6897 | 1205 |
7 | 1206 if (addbuf) |
1207 diff_buf_add(wp->w_buffer); | |
1208 redraw_win_later(wp, NOT_VALID); | |
1209 } | |
1210 | |
1211 /* | |
16 | 1212 * Set options not to show diffs. For the current window or all windows. |
671 | 1213 * Only in the current tab page. |
16 | 1214 */ |
1215 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1216 ex_diffoff(exarg_T *eap) |
16 | 1217 { |
1218 win_T *wp; | |
1219 int diffwin = FALSE; | |
1220 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1221 FOR_ALL_WINDOWS(wp) |
16 | 1222 { |
5358 | 1223 if (eap->forceit ? wp->w_p_diff : wp == curwin) |
16 | 1224 { |
6897 | 1225 /* Set 'diff' off. If option values were saved in |
1226 * diff_win_options(), restore the ones whose settings seem to have | |
1227 * 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
|
1228 set_diff_option(wp, FALSE); |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1229 |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1230 if (wp->w_p_diff_saved) |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1231 { |
6897 | 1232 |
1233 if (wp->w_p_scb) | |
1234 wp->w_p_scb = wp->w_p_scb_save; | |
1235 if (wp->w_p_crb) | |
1236 wp->w_p_crb = wp->w_p_crb_save; | |
1237 if (!wp->w_p_wrap) | |
1238 wp->w_p_wrap = wp->w_p_wrap_save; | |
1239 #ifdef FEAT_FOLDING | |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1240 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
|
1241 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
|
1242 *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
|
1243 |
6897 | 1244 if (wp->w_p_fdc == diff_foldcolumn) |
1245 wp->w_p_fdc = wp->w_p_fdc_save; | |
1246 if (wp->w_p_fdl == 0) | |
1247 wp->w_p_fdl = wp->w_p_fdl_save; | |
1248 | |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1249 /* Only restore 'foldenable' when 'foldmethod' is not |
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1250 * "manual", otherwise we continue to show the diff folds. */ |
6897 | 1251 if (wp->w_p_fen) |
1252 wp->w_p_fen = foldmethodIsManual(wp) ? FALSE | |
1253 : wp->w_p_fen_save; | |
1254 | |
1255 foldUpdateAll(wp); | |
1256 #endif | |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1257 } |
10005
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1258 /* remove filler lines */ |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1259 wp->w_topfill = 0; |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1260 |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1261 /* make sure topline is not halfway a fold and cursor is |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1262 * invalidated */ |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1263 changed_window_setting_win(wp); |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1264 |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1265 /* Note: 'sbo' is not restored, it's a global option. */ |
16 | 1266 diff_buf_adjust(wp); |
1267 } | |
1268 diffwin |= wp->w_p_diff; | |
1269 } | |
1270 | |
10821
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1271 /* Also remove hidden buffers from the list. */ |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1272 if (eap->forceit) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1273 diff_buf_clear(); |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1274 |
16 | 1275 /* Remove "hor" from from 'scrollopt' if there are no diff windows left. */ |
1276 if (!diffwin && vim_strchr(p_sbo, 'h') != NULL) | |
1277 do_cmdline_cmd((char_u *)"set sbo-=hor"); | |
1278 } | |
1279 | |
1280 /* | |
7 | 1281 * Read the diff output and add each entry to the diff list. |
1282 */ | |
1283 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1284 diff_read( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1285 int idx_orig, /* idx of original file */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1286 int idx_new, /* idx of new file */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1287 char_u *fname) /* name of diff output file */ |
7 | 1288 { |
1289 FILE *fd; | |
1290 diff_T *dprev = NULL; | |
672 | 1291 diff_T *dp = curtab->tp_first_diff; |
7 | 1292 diff_T *dn, *dpl; |
1293 long f1, l1, f2, l2; | |
1294 char_u linebuf[LBUFLEN]; /* only need to hold the diff line */ | |
1295 int difftype; | |
1296 char_u *p; | |
1297 long off; | |
1298 int i; | |
1299 linenr_T lnum_orig, lnum_new; | |
1300 long count_orig, count_new; | |
1301 int notset = TRUE; /* block "*dp" not set yet */ | |
1302 | |
531 | 1303 fd = mch_fopen((char *)fname, "r"); |
7 | 1304 if (fd == NULL) |
1305 { | |
1306 EMSG(_("E98: Cannot read diff output")); | |
1307 return; | |
1308 } | |
1309 | |
1310 for (;;) | |
1311 { | |
1312 if (tag_fgets(linebuf, LBUFLEN, fd)) | |
1313 break; /* end of file */ | |
1314 if (!isdigit(*linebuf)) | |
1315 continue; /* not the start of a diff block */ | |
1316 | |
1317 /* This line must be one of three formats: | |
1318 * {first}[,{last}]c{first}[,{last}] | |
1319 * {first}a{first}[,{last}] | |
1320 * {first}[,{last}]d{first} | |
1321 */ | |
1322 p = linebuf; | |
1323 f1 = getdigits(&p); | |
1324 if (*p == ',') | |
1325 { | |
1326 ++p; | |
1327 l1 = getdigits(&p); | |
1328 } | |
1329 else | |
1330 l1 = f1; | |
1331 if (*p != 'a' && *p != 'c' && *p != 'd') | |
1332 continue; /* invalid diff format */ | |
1333 difftype = *p++; | |
1334 f2 = getdigits(&p); | |
1335 if (*p == ',') | |
1336 { | |
1337 ++p; | |
1338 l2 = getdigits(&p); | |
1339 } | |
1340 else | |
1341 l2 = f2; | |
1342 if (l1 < f1 || l2 < f2) | |
1343 continue; /* invalid line range */ | |
1344 | |
1345 if (difftype == 'a') | |
1346 { | |
1347 lnum_orig = f1 + 1; | |
1348 count_orig = 0; | |
1349 } | |
1350 else | |
1351 { | |
1352 lnum_orig = f1; | |
1353 count_orig = l1 - f1 + 1; | |
1354 } | |
1355 if (difftype == 'd') | |
1356 { | |
1357 lnum_new = f2 + 1; | |
1358 count_new = 0; | |
1359 } | |
1360 else | |
1361 { | |
1362 lnum_new = f2; | |
1363 count_new = l2 - f2 + 1; | |
1364 } | |
1365 | |
1366 /* Go over blocks before the change, for which orig and new are equal. | |
1367 * Copy blocks from orig to new. */ | |
1368 while (dp != NULL | |
1369 && lnum_orig > dp->df_lnum[idx_orig] + dp->df_count[idx_orig]) | |
1370 { | |
1371 if (notset) | |
1372 diff_copy_entry(dprev, dp, idx_orig, idx_new); | |
1373 dprev = dp; | |
1374 dp = dp->df_next; | |
1375 notset = TRUE; | |
1376 } | |
1377 | |
1378 if (dp != NULL | |
1379 && lnum_orig <= dp->df_lnum[idx_orig] + dp->df_count[idx_orig] | |
1380 && lnum_orig + count_orig >= dp->df_lnum[idx_orig]) | |
1381 { | |
1382 /* New block overlaps with existing block(s). | |
1383 * First find last block that overlaps. */ | |
1384 for (dpl = dp; dpl->df_next != NULL; dpl = dpl->df_next) | |
1385 if (lnum_orig + count_orig < dpl->df_next->df_lnum[idx_orig]) | |
1386 break; | |
1387 | |
1388 /* If the newly found block starts before the old one, set the | |
1389 * start back a number of lines. */ | |
1390 off = dp->df_lnum[idx_orig] - lnum_orig; | |
1391 if (off > 0) | |
1392 { | |
1393 for (i = idx_orig; i < idx_new; ++i) | |
672 | 1394 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1395 dp->df_lnum[i] -= off; |
1396 dp->df_lnum[idx_new] = lnum_new; | |
1397 dp->df_count[idx_new] = count_new; | |
1398 } | |
1399 else if (notset) | |
1400 { | |
1401 /* new block inside existing one, adjust new block */ | |
1402 dp->df_lnum[idx_new] = lnum_new + off; | |
1403 dp->df_count[idx_new] = count_new - off; | |
1404 } | |
1405 else | |
1406 /* second overlap of new block with existing block */ | |
1519 | 1407 dp->df_count[idx_new] += count_new - count_orig |
1408 + dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig] | |
1409 - (dp->df_lnum[idx_orig] + dp->df_count[idx_orig]); | |
7 | 1410 |
1411 /* Adjust the size of the block to include all the lines to the | |
1412 * end of the existing block or the new diff, whatever ends last. */ | |
1413 off = (lnum_orig + count_orig) | |
1414 - (dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig]); | |
1415 if (off < 0) | |
1416 { | |
1417 /* new change ends in existing block, adjust the end if not | |
1418 * done already */ | |
1419 if (notset) | |
1420 dp->df_count[idx_new] += -off; | |
1421 off = 0; | |
1422 } | |
1428 | 1423 for (i = idx_orig; i < idx_new; ++i) |
672 | 1424 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1425 dp->df_count[i] = dpl->df_lnum[i] + dpl->df_count[i] |
1426 - dp->df_lnum[i] + off; | |
1427 | |
1428 /* Delete the diff blocks that have been merged into one. */ | |
1429 dn = dp->df_next; | |
1430 dp->df_next = dpl->df_next; | |
1431 while (dn != dp->df_next) | |
1432 { | |
1433 dpl = dn->df_next; | |
1434 vim_free(dn); | |
1435 dn = dpl; | |
1436 } | |
1437 } | |
1438 else | |
1439 { | |
1440 /* Allocate a new diffblock. */ | |
672 | 1441 dp = diff_alloc_new(curtab, dprev, dp); |
7 | 1442 if (dp == NULL) |
840 | 1443 goto done; |
7 | 1444 |
1445 dp->df_lnum[idx_orig] = lnum_orig; | |
1446 dp->df_count[idx_orig] = count_orig; | |
1447 dp->df_lnum[idx_new] = lnum_new; | |
1448 dp->df_count[idx_new] = count_new; | |
1449 | |
1450 /* Set values for other buffers, these must be equal to the | |
1451 * original buffer, otherwise there would have been a change | |
1452 * already. */ | |
1453 for (i = idx_orig + 1; i < idx_new; ++i) | |
672 | 1454 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1455 diff_copy_entry(dprev, dp, idx_orig, i); |
1456 } | |
1457 notset = FALSE; /* "*dp" has been set */ | |
1458 } | |
1459 | |
1460 /* for remaining diff blocks orig and new are equal */ | |
1461 while (dp != NULL) | |
1462 { | |
1463 if (notset) | |
1464 diff_copy_entry(dprev, dp, idx_orig, idx_new); | |
1465 dprev = dp; | |
1466 dp = dp->df_next; | |
1467 notset = TRUE; | |
1468 } | |
1469 | |
840 | 1470 done: |
7 | 1471 fclose(fd); |
1472 } | |
1473 | |
1474 /* | |
1475 * Copy an entry at "dp" from "idx_orig" to "idx_new". | |
1476 */ | |
1477 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1478 diff_copy_entry( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1479 diff_T *dprev, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1480 diff_T *dp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1481 int idx_orig, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1482 int idx_new) |
7 | 1483 { |
1484 long off; | |
1485 | |
1486 if (dprev == NULL) | |
1487 off = 0; | |
1488 else | |
1489 off = (dprev->df_lnum[idx_orig] + dprev->df_count[idx_orig]) | |
1490 - (dprev->df_lnum[idx_new] + dprev->df_count[idx_new]); | |
1491 dp->df_lnum[idx_new] = dp->df_lnum[idx_orig] - off; | |
1492 dp->df_count[idx_new] = dp->df_count[idx_orig]; | |
1493 } | |
1494 | |
1495 /* | |
672 | 1496 * Clear the list of diffblocks for tab page "tp". |
7 | 1497 */ |
358 | 1498 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1499 diff_clear(tabpage_T *tp) |
7 | 1500 { |
1501 diff_T *p, *next_p; | |
1502 | |
672 | 1503 for (p = tp->tp_first_diff; p != NULL; p = next_p) |
7 | 1504 { |
1505 next_p = p->df_next; | |
1506 vim_free(p); | |
1507 } | |
672 | 1508 tp->tp_first_diff = NULL; |
7 | 1509 } |
1510 | |
1511 /* | |
1512 * Check diff status for line "lnum" in buffer "buf": | |
1513 * Returns 0 for nothing special | |
1514 * Returns -1 for a line that should be highlighted as changed. | |
1515 * Returns -2 for a line that should be highlighted as added/deleted. | |
1516 * Returns > 0 for inserting that many filler lines above it (never happens | |
1517 * when 'diffopt' doesn't contain "filler"). | |
1518 * This should only be used for windows where 'diff' is set. | |
1519 */ | |
1520 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1521 diff_check(win_T *wp, linenr_T lnum) |
7 | 1522 { |
672 | 1523 int idx; /* index in tp_diffbuf[] for this buffer */ |
7 | 1524 diff_T *dp; |
1525 int maxcount; | |
1526 int i; | |
1527 buf_T *buf = wp->w_buffer; | |
1528 int cmp; | |
1529 | |
672 | 1530 if (curtab->tp_diff_invalid) |
7 | 1531 ex_diffupdate(NULL); /* update after a big change */ |
1532 | |
672 | 1533 if (curtab->tp_first_diff == NULL || !wp->w_p_diff) /* no diffs at all */ |
7 | 1534 return 0; |
1535 | |
1536 /* safety check: "lnum" must be a buffer line */ | |
1537 if (lnum < 1 || lnum > buf->b_ml.ml_line_count + 1) | |
1538 return 0; | |
1539 | |
1540 idx = diff_buf_idx(buf); | |
1541 if (idx == DB_COUNT) | |
1542 return 0; /* no diffs for buffer "buf" */ | |
1543 | |
1544 #ifdef FEAT_FOLDING | |
1545 /* A closed fold never has filler lines. */ | |
1546 if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) | |
1547 return 0; | |
1548 #endif | |
1549 | |
1550 /* search for a change that includes "lnum" in the list of diffblocks. */ | |
672 | 1551 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
7 | 1552 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
1553 break; | |
1554 if (dp == NULL || lnum < dp->df_lnum[idx]) | |
1555 return 0; | |
1556 | |
1557 if (lnum < dp->df_lnum[idx] + dp->df_count[idx]) | |
1558 { | |
1559 int zero = FALSE; | |
1560 | |
1561 /* Changed or inserted line. If the other buffers have a count of | |
1562 * zero, the lines were inserted. If the other buffers have the same | |
1563 * count, check if the lines are identical. */ | |
1564 cmp = FALSE; | |
1565 for (i = 0; i < DB_COUNT; ++i) | |
672 | 1566 if (i != idx && curtab->tp_diffbuf[i] != NULL) |
7 | 1567 { |
1568 if (dp->df_count[i] == 0) | |
1569 zero = TRUE; | |
1570 else | |
1571 { | |
1572 if (dp->df_count[i] != dp->df_count[idx]) | |
1573 return -1; /* nr of lines changed. */ | |
1574 cmp = TRUE; | |
1575 } | |
1576 } | |
1577 if (cmp) | |
1578 { | |
1579 /* Compare all lines. If they are equal the lines were inserted | |
1580 * in some buffers, deleted in others, but not changed. */ | |
1581 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
|
1582 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
|
1583 && dp->df_count[i] != 0) |
7 | 1584 if (!diff_equal_entry(dp, idx, i)) |
1585 return -1; | |
1586 } | |
1587 /* If there is no buffer with zero lines then there is no difference | |
1588 * any longer. Happens when making a change (or undo) that removes | |
1589 * the difference. Can't remove the entry here, we might be halfway | |
1590 * updating the window. Just report the text as unchanged. Other | |
1591 * windows might still show the change though. */ | |
1592 if (zero == FALSE) | |
1593 return 0; | |
1594 return -2; | |
1595 } | |
1596 | |
1597 /* If 'diffopt' doesn't contain "filler", return 0. */ | |
1598 if (!(diff_flags & DIFF_FILLER)) | |
1599 return 0; | |
1600 | |
1601 /* Insert filler lines above the line just below the change. Will return | |
1602 * 0 when this buf had the max count. */ | |
1603 maxcount = 0; | |
1604 for (i = 0; i < DB_COUNT; ++i) | |
672 | 1605 if (curtab->tp_diffbuf[i] != NULL && dp->df_count[i] > maxcount) |
7 | 1606 maxcount = dp->df_count[i]; |
1607 return maxcount - dp->df_count[idx]; | |
1608 } | |
1609 | |
1610 /* | |
1611 * Compare two entries in diff "*dp" and return TRUE if they are equal. | |
1612 */ | |
1613 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1614 diff_equal_entry(diff_T *dp, int idx1, int idx2) |
7 | 1615 { |
1616 int i; | |
1617 char_u *line; | |
1618 int cmp; | |
1619 | |
1620 if (dp->df_count[idx1] != dp->df_count[idx2]) | |
1621 return FALSE; | |
672 | 1622 if (diff_check_sanity(curtab, dp) == FAIL) |
7 | 1623 return FALSE; |
1624 for (i = 0; i < dp->df_count[idx1]; ++i) | |
1625 { | |
672 | 1626 line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], |
7 | 1627 dp->df_lnum[idx1] + i, FALSE)); |
1628 if (line == NULL) | |
1629 return FALSE; | |
672 | 1630 cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], |
7 | 1631 dp->df_lnum[idx2] + i, FALSE)); |
1632 vim_free(line); | |
1633 if (cmp != 0) | |
1634 return FALSE; | |
1635 } | |
1636 return TRUE; | |
1637 } | |
1638 | |
1639 /* | |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1640 * 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
|
1641 * 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
|
1642 */ |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1643 static int |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1644 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
|
1645 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1646 #ifdef FEAT_MBYTE |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1647 int l = (*mb_ptr2len)(p1); |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1648 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1649 if (l != (*mb_ptr2len)(p2)) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1650 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1651 if (l > 1) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1652 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1653 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
|
1654 && (!enc_utf8 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1655 || !(diff_flags & DIFF_ICASE) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1656 || utf_fold(utf_ptr2char(p1)) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1657 != utf_fold(utf_ptr2char(p2)))) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1658 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1659 *len = l; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1660 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1661 else |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1662 #endif |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1663 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1664 if ((*p1 != *p2) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1665 && (!(diff_flags & DIFF_ICASE) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1666 || 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
|
1667 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1668 *len = 1; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1669 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1670 return TRUE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1671 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1672 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1673 /* |
7 | 1674 * Compare strings "s1" and "s2" according to 'diffopt'. |
1675 * Return non-zero when they are different. | |
1676 */ | |
1677 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1678 diff_cmp(char_u *s1, char_u *s2) |
7 | 1679 { |
1680 char_u *p1, *p2; | |
1681 int l; | |
1682 | |
1683 if ((diff_flags & (DIFF_ICASE | DIFF_IWHITE)) == 0) | |
1684 return STRCMP(s1, s2); | |
1685 if ((diff_flags & DIFF_ICASE) && !(diff_flags & DIFF_IWHITE)) | |
1686 return MB_STRICMP(s1, s2); | |
1687 | |
1688 /* Ignore white space changes and possibly ignore case. */ | |
1689 p1 = s1; | |
1690 p2 = s2; | |
1691 while (*p1 != NUL && *p2 != NUL) | |
1692 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1693 if (VIM_ISWHITE(*p1) && VIM_ISWHITE(*p2)) |
7 | 1694 { |
1695 p1 = skipwhite(p1); | |
1696 p2 = skipwhite(p2); | |
1697 } | |
1698 else | |
1699 { | |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1700 if (!diff_equal_char(p1, p2, &l)) |
7 | 1701 break; |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1702 p1 += l; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1703 p2 += l; |
7 | 1704 } |
1705 } | |
1706 | |
1707 /* Ignore trailing white space. */ | |
1708 p1 = skipwhite(p1); | |
1709 p2 = skipwhite(p2); | |
1710 if (*p1 != NUL || *p2 != NUL) | |
1711 return 1; | |
1712 return 0; | |
1713 } | |
1714 | |
1715 /* | |
1716 * Return the number of filler lines above "lnum". | |
1717 */ | |
1718 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1719 diff_check_fill(win_T *wp, linenr_T lnum) |
7 | 1720 { |
1721 int n; | |
1722 | |
1723 /* be quick when there are no filler lines */ | |
1724 if (!(diff_flags & DIFF_FILLER)) | |
1725 return 0; | |
1726 n = diff_check(wp, lnum); | |
1727 if (n <= 0) | |
1728 return 0; | |
1729 return n; | |
1730 } | |
1731 | |
1732 /* | |
1733 * Set the topline of "towin" to match the position in "fromwin", so that they | |
1734 * show the same diff'ed lines. | |
1735 */ | |
1736 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1737 diff_set_topline(win_T *fromwin, win_T *towin) |
7 | 1738 { |
1519 | 1739 buf_T *frombuf = fromwin->w_buffer; |
7 | 1740 linenr_T lnum = fromwin->w_topline; |
1519 | 1741 int fromidx; |
1742 int toidx; | |
7 | 1743 diff_T *dp; |
1519 | 1744 int max_count; |
7 | 1745 int i; |
1746 | |
1519 | 1747 fromidx = diff_buf_idx(frombuf); |
1748 if (fromidx == DB_COUNT) | |
7 | 1749 return; /* safety check */ |
1750 | |
672 | 1751 if (curtab->tp_diff_invalid) |
7 | 1752 ex_diffupdate(NULL); /* update after a big change */ |
1753 | |
1754 towin->w_topfill = 0; | |
1755 | |
1756 /* search for a change that includes "lnum" in the list of diffblocks. */ | |
672 | 1757 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
1519 | 1758 if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
7 | 1759 break; |
1760 if (dp == NULL) | |
1761 { | |
1762 /* After last change, compute topline relative to end of file; no | |
1763 * filler lines. */ | |
1764 towin->w_topline = towin->w_buffer->b_ml.ml_line_count | |
1519 | 1765 - (frombuf->b_ml.ml_line_count - lnum); |
7 | 1766 } |
1767 else | |
1768 { | |
1769 /* Find index for "towin". */ | |
1519 | 1770 toidx = diff_buf_idx(towin->w_buffer); |
1771 if (toidx == DB_COUNT) | |
7 | 1772 return; /* safety check */ |
1773 | |
1519 | 1774 towin->w_topline = lnum + (dp->df_lnum[toidx] - dp->df_lnum[fromidx]); |
1775 if (lnum >= dp->df_lnum[fromidx]) | |
7 | 1776 { |
1519 | 1777 /* Inside a change: compute filler lines. With three or more |
1778 * buffers we need to know the largest count. */ | |
1779 max_count = 0; | |
1780 for (i = 0; i < DB_COUNT; ++i) | |
1781 if (curtab->tp_diffbuf[i] != NULL | |
1782 && max_count < dp->df_count[i]) | |
1783 max_count = dp->df_count[i]; | |
1784 | |
1785 if (dp->df_count[toidx] == dp->df_count[fromidx]) | |
1786 { | |
1787 /* same number of lines: use same filler count */ | |
7 | 1788 towin->w_topfill = fromwin->w_topfill; |
1519 | 1789 } |
1790 else if (dp->df_count[toidx] > dp->df_count[fromidx]) | |
7 | 1791 { |
1519 | 1792 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
1793 { | |
1794 /* more lines in towin and fromwin doesn't show diff | |
1795 * lines, only filler lines */ | |
1796 if (max_count - fromwin->w_topfill >= dp->df_count[toidx]) | |
1797 { | |
1798 /* towin also only shows filler lines */ | |
1799 towin->w_topline = dp->df_lnum[toidx] | |
1800 + dp->df_count[toidx]; | |
1801 towin->w_topfill = fromwin->w_topfill; | |
1802 } | |
1803 else | |
1804 /* towin still has some diff lines to show */ | |
1805 towin->w_topline = dp->df_lnum[toidx] | |
1806 + max_count - fromwin->w_topfill; | |
1807 } | |
7 | 1808 } |
1519 | 1809 else if (towin->w_topline >= dp->df_lnum[toidx] |
1810 + dp->df_count[toidx]) | |
7 | 1811 { |
1519 | 1812 /* less lines in towin and no diff lines to show: compute |
1813 * filler lines */ | |
1814 towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; | |
1815 if (diff_flags & DIFF_FILLER) | |
7 | 1816 { |
1519 | 1817 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
1818 /* fromwin is also out of diff lines */ | |
1819 towin->w_topfill = fromwin->w_topfill; | |
1820 else | |
1821 /* fromwin has some diff lines */ | |
1822 towin->w_topfill = dp->df_lnum[fromidx] | |
1823 + max_count - lnum; | |
7 | 1824 } |
1825 } | |
1826 } | |
1827 } | |
1828 | |
1829 /* safety check (if diff info gets outdated strange things may happen) */ | |
1830 towin->w_botfill = FALSE; | |
1831 if (towin->w_topline > towin->w_buffer->b_ml.ml_line_count) | |
1832 { | |
1833 towin->w_topline = towin->w_buffer->b_ml.ml_line_count; | |
1834 towin->w_botfill = TRUE; | |
1835 } | |
1836 if (towin->w_topline < 1) | |
1837 { | |
1838 towin->w_topline = 1; | |
1839 towin->w_topfill = 0; | |
1840 } | |
1841 | |
1842 /* When w_topline changes need to recompute w_botline and cursor position */ | |
1843 invalidate_botline_win(towin); | |
1844 changed_line_abv_curs_win(towin); | |
1845 | |
1846 check_topfill(towin, FALSE); | |
1847 #ifdef FEAT_FOLDING | |
1848 (void)hasFoldingWin(towin, towin->w_topline, &towin->w_topline, | |
1849 NULL, TRUE, NULL); | |
1850 #endif | |
1851 } | |
1852 | |
1853 /* | |
1854 * This is called when 'diffopt' is changed. | |
1855 */ | |
1856 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1857 diffopt_changed(void) |
7 | 1858 { |
1859 char_u *p; | |
1860 int diff_context_new = 6; | |
1861 int diff_flags_new = 0; | |
764 | 1862 int diff_foldcolumn_new = 2; |
672 | 1863 tabpage_T *tp; |
7 | 1864 |
1865 p = p_dip; | |
1866 while (*p != NUL) | |
1867 { | |
1868 if (STRNCMP(p, "filler", 6) == 0) | |
1869 { | |
1870 p += 6; | |
1871 diff_flags_new |= DIFF_FILLER; | |
1872 } | |
1873 else if (STRNCMP(p, "context:", 8) == 0 && VIM_ISDIGIT(p[8])) | |
1874 { | |
1875 p += 8; | |
1876 diff_context_new = getdigits(&p); | |
1877 } | |
1878 else if (STRNCMP(p, "icase", 5) == 0) | |
1879 { | |
1880 p += 5; | |
1881 diff_flags_new |= DIFF_ICASE; | |
1882 } | |
1883 else if (STRNCMP(p, "iwhite", 6) == 0) | |
1884 { | |
1885 p += 6; | |
1886 diff_flags_new |= DIFF_IWHITE; | |
1887 } | |
764 | 1888 else if (STRNCMP(p, "horizontal", 10) == 0) |
1889 { | |
1890 p += 10; | |
1891 diff_flags_new |= DIFF_HORIZONTAL; | |
1892 } | |
1893 else if (STRNCMP(p, "vertical", 8) == 0) | |
1894 { | |
1895 p += 8; | |
1896 diff_flags_new |= DIFF_VERTICAL; | |
1897 } | |
1898 else if (STRNCMP(p, "foldcolumn:", 11) == 0 && VIM_ISDIGIT(p[11])) | |
1899 { | |
1900 p += 11; | |
1901 diff_foldcolumn_new = getdigits(&p); | |
1902 } | |
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
|
1903 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
|
1904 { |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
1905 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
|
1906 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
|
1907 } |
7 | 1908 if (*p != ',' && *p != NUL) |
1909 return FAIL; | |
1910 if (*p == ',') | |
1911 ++p; | |
1912 } | |
1913 | |
764 | 1914 /* Can't have both "horizontal" and "vertical". */ |
1915 if ((diff_flags_new & DIFF_HORIZONTAL) && (diff_flags_new & DIFF_VERTICAL)) | |
1916 return FAIL; | |
1917 | |
7 | 1918 /* If "icase" or "iwhite" was added or removed, need to update the diff. */ |
1919 if (diff_flags != diff_flags_new) | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1920 FOR_ALL_TABPAGES(tp) |
672 | 1921 tp->tp_diff_invalid = TRUE; |
7 | 1922 |
1923 diff_flags = diff_flags_new; | |
1924 diff_context = diff_context_new; | |
764 | 1925 diff_foldcolumn = diff_foldcolumn_new; |
7 | 1926 |
1927 diff_redraw(TRUE); | |
1928 | |
1929 /* recompute the scroll binding with the new option value, may | |
1930 * remove or add filler lines */ | |
1931 check_scrollbind((linenr_T)0, 0L); | |
1932 | |
1933 return OK; | |
1934 } | |
1935 | |
1936 /* | |
764 | 1937 * Return TRUE if 'diffopt' contains "horizontal". |
1938 */ | |
1939 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1940 diffopt_horizontal(void) |
764 | 1941 { |
1942 return (diff_flags & DIFF_HORIZONTAL) != 0; | |
1943 } | |
1944 | |
1945 /* | |
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
|
1946 * 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
|
1947 */ |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
1948 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
|
1949 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
|
1950 { |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
1951 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
|
1952 } |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
1953 |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
1954 /* |
7 | 1955 * Find the difference within a changed line. |
1956 * Returns TRUE if the line was added, no other buffer has it. | |
1957 */ | |
1958 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1959 diff_find_change( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1960 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1961 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1962 int *startp, /* first char of the change */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1963 int *endp) /* last char of the change */ |
7 | 1964 { |
1965 char_u *line_org; | |
1966 char_u *line_new; | |
1967 int i; | |
829 | 1968 int si_org, si_new; |
1969 int ei_org, ei_new; | |
7 | 1970 diff_T *dp; |
1971 int idx; | |
1972 int off; | |
1973 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
|
1974 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
|
1975 int l; |
7 | 1976 |
1977 /* Make a copy of the line, the next ml_get() will invalidate it. */ | |
1978 line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); | |
1979 if (line_org == NULL) | |
1980 return FALSE; | |
1981 | |
1982 idx = diff_buf_idx(wp->w_buffer); | |
1983 if (idx == DB_COUNT) /* cannot happen */ | |
1074 | 1984 { |
1985 vim_free(line_org); | |
7 | 1986 return FALSE; |
1074 | 1987 } |
7 | 1988 |
1989 /* search for a change that includes "lnum" in the list of diffblocks. */ | |
672 | 1990 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
7 | 1991 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
1992 break; | |
672 | 1993 if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL) |
1074 | 1994 { |
1995 vim_free(line_org); | |
7 | 1996 return FALSE; |
1074 | 1997 } |
7 | 1998 |
1999 off = lnum - dp->df_lnum[idx]; | |
2000 | |
2001 for (i = 0; i < DB_COUNT; ++i) | |
672 | 2002 if (curtab->tp_diffbuf[i] != NULL && i != idx) |
7 | 2003 { |
2004 /* Skip lines that are not in the other change (filler lines). */ | |
2005 if (off >= dp->df_count[i]) | |
2006 continue; | |
2007 added = FALSE; | |
829 | 2008 line_new = ml_get_buf(curtab->tp_diffbuf[i], |
2009 dp->df_lnum[i] + off, FALSE); | |
7 | 2010 |
2011 /* Search for start of difference */ | |
829 | 2012 si_org = si_new = 0; |
2013 while (line_org[si_org] != NUL) | |
2014 { | |
2015 if ((diff_flags & DIFF_IWHITE) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2016 && VIM_ISWHITE(line_org[si_org]) |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2017 && VIM_ISWHITE(line_new[si_new])) |
829 | 2018 { |
835 | 2019 si_org = (int)(skipwhite(line_org + si_org) - line_org); |
2020 si_new = (int)(skipwhite(line_new + si_new) - line_new); | |
829 | 2021 } |
2022 else | |
2023 { | |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2024 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
|
2025 &l)) |
829 | 2026 break; |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2027 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
|
2028 si_new += l; |
829 | 2029 } |
2030 } | |
7 | 2031 #ifdef FEAT_MBYTE |
2032 if (has_mbyte) | |
2033 { | |
2034 /* Move back to first byte of character in both lines (may | |
2035 * have "nn^" in line_org and "n^ in line_new). */ | |
829 | 2036 si_org -= (*mb_head_off)(line_org, line_org + si_org); |
2037 si_new -= (*mb_head_off)(line_new, line_new + si_new); | |
7 | 2038 } |
2039 #endif | |
829 | 2040 if (*startp > si_org) |
2041 *startp = si_org; | |
7 | 2042 |
2043 /* Search for end of difference, if any. */ | |
829 | 2044 if (line_org[si_org] != NUL || line_new[si_new] != NUL) |
7 | 2045 { |
2046 ei_org = (int)STRLEN(line_org); | |
2047 ei_new = (int)STRLEN(line_new); | |
829 | 2048 while (ei_org >= *startp && ei_new >= si_new |
2049 && ei_org >= 0 && ei_new >= 0) | |
7 | 2050 { |
829 | 2051 if ((diff_flags & DIFF_IWHITE) |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2052 && VIM_ISWHITE(line_org[ei_org]) |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2053 && VIM_ISWHITE(line_new[ei_new])) |
829 | 2054 { |
2055 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
|
2056 && VIM_ISWHITE(line_org[ei_org])) |
829 | 2057 --ei_org; |
2058 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
|
2059 && VIM_ISWHITE(line_new[ei_new])) |
829 | 2060 --ei_new; |
2061 } | |
2062 else | |
2063 { | |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2064 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
|
2065 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
|
2066 #ifdef FEAT_MBYTE |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2067 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
|
2068 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
|
2069 #endif |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2070 if (!diff_equal_char(p1, p2, &l)) |
829 | 2071 break; |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2072 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
|
2073 ei_new -= l; |
829 | 2074 } |
7 | 2075 } |
2076 if (*endp < ei_org) | |
2077 *endp = ei_org; | |
2078 } | |
2079 } | |
2080 | |
2081 vim_free(line_org); | |
2082 return added; | |
2083 } | |
2084 | |
2085 #if defined(FEAT_FOLDING) || defined(PROTO) | |
2086 /* | |
2087 * Return TRUE if line "lnum" is not close to a diff block, this line should | |
2088 * be in a fold. | |
2089 * Return FALSE if there are no diff blocks at all in this window. | |
2090 */ | |
2091 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2092 diff_infold(win_T *wp, linenr_T lnum) |
7 | 2093 { |
2094 int i; | |
2095 int idx = -1; | |
2096 int other = FALSE; | |
2097 diff_T *dp; | |
2098 | |
2099 /* Return if 'diff' isn't set. */ | |
2100 if (!wp->w_p_diff) | |
2101 return FALSE; | |
2102 | |
2103 for (i = 0; i < DB_COUNT; ++i) | |
2104 { | |
672 | 2105 if (curtab->tp_diffbuf[i] == wp->w_buffer) |
7 | 2106 idx = i; |
672 | 2107 else if (curtab->tp_diffbuf[i] != NULL) |
7 | 2108 other = TRUE; |
2109 } | |
2110 | |
2111 /* return here if there are no diffs in the window */ | |
2112 if (idx == -1 || !other) | |
2113 return FALSE; | |
2114 | |
672 | 2115 if (curtab->tp_diff_invalid) |
7 | 2116 ex_diffupdate(NULL); /* update after a big change */ |
2117 | |
2118 /* Return if there are no diff blocks. All lines will be folded. */ | |
672 | 2119 if (curtab->tp_first_diff == NULL) |
7 | 2120 return TRUE; |
2121 | |
672 | 2122 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
7 | 2123 { |
2124 /* If this change is below the line there can't be any further match. */ | |
2125 if (dp->df_lnum[idx] - diff_context > lnum) | |
2126 break; | |
2127 /* If this change ends before the line we have a match. */ | |
2128 if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) | |
2129 return FALSE; | |
2130 } | |
2131 return TRUE; | |
2132 } | |
2133 #endif | |
2134 | |
2135 /* | |
2136 * "dp" and "do" commands. | |
2137 */ | |
2138 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2139 nv_diffgetput(int put, long count) |
7 | 2140 { |
2141 exarg_T ea; | |
6314 | 2142 char_u buf[30]; |
7 | 2143 |
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
|
2144 #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
|
2145 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
|
2146 { |
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
|
2147 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
|
2148 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
|
2149 } |
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
|
2150 #endif |
6314 | 2151 if (count == 0) |
2152 ea.arg = (char_u *)""; | |
2153 else | |
2154 { | |
2155 vim_snprintf((char *)buf, 30, "%ld", count); | |
2156 ea.arg = buf; | |
2157 } | |
7 | 2158 if (put) |
2159 ea.cmdidx = CMD_diffput; | |
2160 else | |
2161 ea.cmdidx = CMD_diffget; | |
2162 ea.addr_count = 0; | |
2163 ea.line1 = curwin->w_cursor.lnum; | |
2164 ea.line2 = curwin->w_cursor.lnum; | |
2165 ex_diffgetput(&ea); | |
2166 } | |
2167 | |
2168 /* | |
2169 * ":diffget" | |
2170 * ":diffput" | |
2171 */ | |
2172 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2173 ex_diffgetput(exarg_T *eap) |
7 | 2174 { |
2175 linenr_T lnum; | |
2176 int count; | |
2177 linenr_T off = 0; | |
2178 diff_T *dp; | |
2179 diff_T *dprev; | |
2180 diff_T *dfree; | |
2181 int idx_cur; | |
2182 int idx_other; | |
2183 int idx_from; | |
2184 int idx_to; | |
2185 int i; | |
2186 int added; | |
2187 char_u *p; | |
2188 aco_save_T aco; | |
2189 buf_T *buf; | |
2190 int start_skip, end_skip; | |
2191 int new_count; | |
648 | 2192 int buf_empty; |
1075 | 2193 int found_not_ma = FALSE; |
7 | 2194 |
2195 /* Find the current buffer in the list of diff buffers. */ | |
2196 idx_cur = diff_buf_idx(curbuf); | |
2197 if (idx_cur == DB_COUNT) | |
2198 { | |
2199 EMSG(_("E99: Current buffer is not in diff mode")); | |
2200 return; | |
2201 } | |
2202 | |
2203 if (*eap->arg == NUL) | |
2204 { | |
2205 /* No argument: Find the other buffer in the list of diff buffers. */ | |
2206 for (idx_other = 0; idx_other < DB_COUNT; ++idx_other) | |
672 | 2207 if (curtab->tp_diffbuf[idx_other] != curbuf |
1075 | 2208 && curtab->tp_diffbuf[idx_other] != NULL) |
2209 { | |
2210 if (eap->cmdidx != CMD_diffput | |
2211 || curtab->tp_diffbuf[idx_other]->b_p_ma) | |
2212 break; | |
2213 found_not_ma = TRUE; | |
2214 } | |
7 | 2215 if (idx_other == DB_COUNT) |
2216 { | |
1075 | 2217 if (found_not_ma) |
2218 EMSG(_("E793: No other buffer in diff mode is modifiable")); | |
2219 else | |
2220 EMSG(_("E100: No other buffer in diff mode")); | |
7 | 2221 return; |
2222 } | |
2223 | |
2224 /* Check that there isn't a third buffer in the list */ | |
2225 for (i = idx_other + 1; i < DB_COUNT; ++i) | |
672 | 2226 if (curtab->tp_diffbuf[i] != curbuf |
2227 && curtab->tp_diffbuf[i] != NULL | |
2228 && (eap->cmdidx != CMD_diffput || curtab->tp_diffbuf[i]->b_p_ma)) | |
7 | 2229 { |
2230 EMSG(_("E101: More than two buffers in diff mode, don't know which one to use")); | |
2231 return; | |
2232 } | |
2233 } | |
2234 else | |
2235 { | |
2236 /* Buffer number or pattern given. Ignore trailing white space. */ | |
2237 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
|
2238 while (p > eap->arg && VIM_ISWHITE(p[-1])) |
7 | 2239 --p; |
2240 for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i) | |
2241 ; | |
2242 if (eap->arg + i == p) /* digits only */ | |
2243 i = atol((char *)eap->arg); | |
2244 else | |
2245 { | |
4236 | 2246 i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE); |
7 | 2247 if (i < 0) |
2248 return; /* error message already given */ | |
2249 } | |
2250 buf = buflist_findnr(i); | |
2251 if (buf == NULL) | |
2252 { | |
2253 EMSG2(_("E102: Can't find buffer \"%s\""), eap->arg); | |
2254 return; | |
2255 } | |
1788 | 2256 if (buf == curbuf) |
2257 return; /* nothing to do */ | |
7 | 2258 idx_other = diff_buf_idx(buf); |
2259 if (idx_other == DB_COUNT) | |
2260 { | |
2261 EMSG2(_("E103: Buffer \"%s\" is not in diff mode"), eap->arg); | |
2262 return; | |
2263 } | |
2264 } | |
2265 | |
2266 diff_busy = TRUE; | |
2267 | |
2268 /* When no range given include the line above or below the cursor. */ | |
2269 if (eap->addr_count == 0) | |
2270 { | |
2271 /* Make it possible that ":diffget" on the last line gets line below | |
2272 * the cursor line when there is no difference above the cursor. */ | |
2273 if (eap->cmdidx == CMD_diffget | |
2274 && eap->line1 == curbuf->b_ml.ml_line_count | |
2275 && diff_check(curwin, eap->line1) == 0 | |
2276 && (eap->line1 == 1 || diff_check(curwin, eap->line1 - 1) == 0)) | |
2277 ++eap->line2; | |
2278 else if (eap->line1 > 0) | |
2279 --eap->line1; | |
2280 } | |
2281 | |
2282 if (eap->cmdidx == CMD_diffget) | |
2283 { | |
2284 idx_from = idx_other; | |
2285 idx_to = idx_cur; | |
2286 } | |
2287 else | |
2288 { | |
2289 idx_from = idx_cur; | |
2290 idx_to = idx_other; | |
2291 /* Need to make the other buffer the current buffer to be able to make | |
2292 * changes in it. */ | |
2293 /* set curwin/curbuf to buf and save a few things */ | |
672 | 2294 aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]); |
7 | 2295 } |
2296 | |
819 | 2297 /* May give the warning for a changed buffer here, which can trigger the |
2298 * FileChangedRO autocommand, which may do nasty things and mess | |
2299 * everything up. */ | |
2300 if (!curbuf->b_changed) | |
2301 { | |
2302 change_warning(0); | |
2303 if (diff_buf_idx(curbuf) != idx_to) | |
2304 { | |
2305 EMSG(_("E787: Buffer changed unexpectedly")); | |
2306 return; | |
2307 } | |
2308 } | |
2309 | |
7 | 2310 dprev = NULL; |
672 | 2311 for (dp = curtab->tp_first_diff; dp != NULL; ) |
7 | 2312 { |
2313 if (dp->df_lnum[idx_cur] > eap->line2 + off) | |
2314 break; /* past the range that was specified */ | |
2315 | |
2316 dfree = NULL; | |
2317 lnum = dp->df_lnum[idx_to]; | |
2318 count = dp->df_count[idx_to]; | |
2319 if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off | |
2320 && u_save(lnum - 1, lnum + count) != FAIL) | |
2321 { | |
2322 /* Inside the specified range and saving for undo worked. */ | |
2323 start_skip = 0; | |
2324 end_skip = 0; | |
2325 if (eap->addr_count > 0) | |
2326 { | |
2327 /* A range was specified: check if lines need to be skipped. */ | |
2328 start_skip = eap->line1 + off - dp->df_lnum[idx_cur]; | |
2329 if (start_skip > 0) | |
2330 { | |
2331 /* range starts below start of current diff block */ | |
2332 if (start_skip > count) | |
2333 { | |
2334 lnum += count; | |
2335 count = 0; | |
2336 } | |
2337 else | |
2338 { | |
2339 count -= start_skip; | |
2340 lnum += start_skip; | |
2341 } | |
2342 } | |
2343 else | |
2344 start_skip = 0; | |
2345 | |
2346 end_skip = dp->df_lnum[idx_cur] + dp->df_count[idx_cur] - 1 | |
2347 - (eap->line2 + off); | |
2348 if (end_skip > 0) | |
2349 { | |
2350 /* range ends above end of current/from diff block */ | |
2351 if (idx_cur == idx_from) /* :diffput */ | |
2352 { | |
2353 i = dp->df_count[idx_cur] - start_skip - end_skip; | |
2354 if (count > i) | |
2355 count = i; | |
2356 } | |
2357 else /* :diffget */ | |
2358 { | |
2359 count -= end_skip; | |
2360 end_skip = dp->df_count[idx_from] - start_skip - count; | |
2361 if (end_skip < 0) | |
2362 end_skip = 0; | |
2363 } | |
2364 } | |
2365 else | |
2366 end_skip = 0; | |
2367 } | |
2368 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11113
diff
changeset
|
2369 buf_empty = BUFEMPTY(); |
7 | 2370 added = 0; |
2371 for (i = 0; i < count; ++i) | |
2372 { | |
648 | 2373 /* remember deleting the last line of the buffer */ |
2374 buf_empty = curbuf->b_ml.ml_line_count == 1; | |
7 | 2375 ml_delete(lnum, FALSE); |
2376 --added; | |
2377 } | |
2378 for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i) | |
2379 { | |
2380 linenr_T nr; | |
2381 | |
2382 nr = dp->df_lnum[idx_from] + start_skip + i; | |
672 | 2383 if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) |
7 | 2384 break; |
819 | 2385 p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], |
2386 nr, FALSE)); | |
7 | 2387 if (p != NULL) |
2388 { | |
2389 ml_append(lnum + i - 1, p, 0, FALSE); | |
2390 vim_free(p); | |
2391 ++added; | |
648 | 2392 if (buf_empty && curbuf->b_ml.ml_line_count == 2) |
2393 { | |
2394 /* Added the first line into an empty buffer, need to | |
2395 * delete the dummy empty line. */ | |
2396 buf_empty = FALSE; | |
2397 ml_delete((linenr_T)2, FALSE); | |
2398 } | |
7 | 2399 } |
2400 } | |
2401 new_count = dp->df_count[idx_to] + added; | |
2402 dp->df_count[idx_to] = new_count; | |
2403 | |
2404 if (start_skip == 0 && end_skip == 0) | |
2405 { | |
2406 /* Check if there are any other buffers and if the diff is | |
2407 * equal in them. */ | |
2408 for (i = 0; i < DB_COUNT; ++i) | |
819 | 2409 if (curtab->tp_diffbuf[i] != NULL && i != idx_from |
2410 && i != idx_to | |
7 | 2411 && !diff_equal_entry(dp, idx_from, i)) |
2412 break; | |
2413 if (i == DB_COUNT) | |
2414 { | |
2415 /* delete the diff entry, the buffers are now equal here */ | |
2416 dfree = dp; | |
2417 dp = dp->df_next; | |
2418 if (dprev == NULL) | |
672 | 2419 curtab->tp_first_diff = dp; |
7 | 2420 else |
2421 dprev->df_next = dp; | |
2422 } | |
2423 } | |
2424 | |
2425 /* Adjust marks. This will change the following entries! */ | |
2426 if (added != 0) | |
2427 { | |
2428 mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added); | |
2429 if (curwin->w_cursor.lnum >= lnum) | |
2430 { | |
2431 /* Adjust the cursor position if it's in/after the changed | |
2432 * lines. */ | |
2433 if (curwin->w_cursor.lnum >= lnum + count) | |
2434 curwin->w_cursor.lnum += added; | |
2435 else if (added < 0) | |
2436 curwin->w_cursor.lnum = lnum; | |
2437 } | |
2438 } | |
2439 changed_lines(lnum, 0, lnum + count, (long)added); | |
2440 | |
2441 if (dfree != NULL) | |
2442 { | |
2443 /* Diff is deleted, update folds in other windows. */ | |
2444 #ifdef FEAT_FOLDING | |
2445 diff_fold_update(dfree, idx_to); | |
2446 #endif | |
2447 vim_free(dfree); | |
2448 } | |
2449 else | |
2450 /* mark_adjust() may have changed the count in a wrong way */ | |
2451 dp->df_count[idx_to] = new_count; | |
2452 | |
2453 /* When changing the current buffer, keep track of line numbers */ | |
2454 if (idx_cur == idx_to) | |
2455 off += added; | |
2456 } | |
2457 | |
2458 /* If before the range or not deleted, go to next diff. */ | |
2459 if (dfree == NULL) | |
2460 { | |
2461 dprev = dp; | |
2462 dp = dp->df_next; | |
2463 } | |
2464 } | |
2465 | |
2466 /* restore curwin/curbuf and a few other things */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2467 if (eap->cmdidx != CMD_diffget) |
7 | 2468 { |
2469 /* Syncing undo only works for the current buffer, but we change | |
2470 * another buffer. Sync undo if the command was typed. This isn't | |
2471 * 100% right when ":diffput" is used in a function or mapping. */ | |
2472 if (KeyTyped) | |
825 | 2473 u_sync(FALSE); |
7 | 2474 aucmd_restbuf(&aco); |
2475 } | |
2476 | |
2477 diff_busy = FALSE; | |
2478 | |
2479 /* Check that the cursor is on a valid character and update it's position. | |
2480 * When there were filler lines the topline has become invalid. */ | |
2481 check_cursor(); | |
2482 changed_line_abv_curs(); | |
2483 | |
2484 /* Also need to redraw the other buffers. */ | |
2485 diff_redraw(FALSE); | |
2486 } | |
2487 | |
2488 #ifdef FEAT_FOLDING | |
2489 /* | |
2490 * Update folds for all diff buffers for entry "dp". | |
2491 * Skip buffer with index "skip_idx". | |
2492 * When there are no diffs, all folds are removed. | |
2493 */ | |
2494 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2495 diff_fold_update(diff_T *dp, int skip_idx) |
7 | 2496 { |
2497 int i; | |
2498 win_T *wp; | |
2499 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2500 FOR_ALL_WINDOWS(wp) |
7 | 2501 for (i = 0; i < DB_COUNT; ++i) |
672 | 2502 if (curtab->tp_diffbuf[i] == wp->w_buffer && i != skip_idx) |
7 | 2503 foldUpdate(wp, dp->df_lnum[i], |
2504 dp->df_lnum[i] + dp->df_count[i]); | |
2505 } | |
2506 #endif | |
2507 | |
2508 /* | |
2509 * Return TRUE if buffer "buf" is in diff-mode. | |
2510 */ | |
2511 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2512 diff_mode_buf(buf_T *buf) |
7 | 2513 { |
672 | 2514 tabpage_T *tp; |
2515 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2516 FOR_ALL_TABPAGES(tp) |
672 | 2517 if (diff_buf_idx_tp(buf, tp) != DB_COUNT) |
2518 return TRUE; | |
2519 return FALSE; | |
7 | 2520 } |
2521 | |
2522 /* | |
2523 * Move "count" times in direction "dir" to the next diff block. | |
2524 * Return FAIL if there isn't such a diff block. | |
2525 */ | |
2526 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2527 diff_move_to(int dir, long count) |
7 | 2528 { |
2529 int idx; | |
2530 linenr_T lnum = curwin->w_cursor.lnum; | |
2531 diff_T *dp; | |
2532 | |
2533 idx = diff_buf_idx(curbuf); | |
672 | 2534 if (idx == DB_COUNT || curtab->tp_first_diff == NULL) |
7 | 2535 return FAIL; |
2536 | |
672 | 2537 if (curtab->tp_diff_invalid) |
7 | 2538 ex_diffupdate(NULL); /* update after a big change */ |
2539 | |
672 | 2540 if (curtab->tp_first_diff == NULL) /* no diffs today */ |
7 | 2541 return FAIL; |
2542 | |
2543 while (--count >= 0) | |
2544 { | |
2545 /* Check if already before first diff. */ | |
672 | 2546 if (dir == BACKWARD && lnum <= curtab->tp_first_diff->df_lnum[idx]) |
7 | 2547 break; |
2548 | |
672 | 2549 for (dp = curtab->tp_first_diff; ; dp = dp->df_next) |
7 | 2550 { |
2551 if (dp == NULL) | |
2552 break; | |
2553 if ((dir == FORWARD && lnum < dp->df_lnum[idx]) | |
2554 || (dir == BACKWARD | |
2555 && (dp->df_next == NULL | |
2556 || lnum <= dp->df_next->df_lnum[idx]))) | |
2557 { | |
2558 lnum = dp->df_lnum[idx]; | |
2559 break; | |
2560 } | |
2561 } | |
2562 } | |
2563 | |
2564 /* don't end up past the end of the file */ | |
2565 if (lnum > curbuf->b_ml.ml_line_count) | |
2566 lnum = curbuf->b_ml.ml_line_count; | |
2567 | |
2568 /* When the cursor didn't move at all we fail. */ | |
2569 if (lnum == curwin->w_cursor.lnum) | |
2570 return FAIL; | |
2571 | |
2572 setpcmark(); | |
2573 curwin->w_cursor.lnum = lnum; | |
2574 curwin->w_cursor.col = 0; | |
2575 | |
2576 return OK; | |
2577 } | |
2578 | |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2579 /* |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2580 * 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
|
2581 * "buf1" in diff mode. |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2582 */ |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2583 static linenr_T |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2584 diff_get_corresponding_line_int( |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2585 buf_T *buf1, |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2586 linenr_T lnum1) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2587 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2588 int idx1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2589 int idx2; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2590 diff_T *dp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2591 int baseline = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2592 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2593 idx1 = diff_buf_idx(buf1); |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2594 idx2 = diff_buf_idx(curbuf); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2595 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
|
2596 return lnum1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2597 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2598 if (curtab->tp_diff_invalid) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2599 ex_diffupdate(NULL); /* update after a big change */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2600 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2601 if (curtab->tp_first_diff == NULL) /* no diffs today */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2602 return lnum1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2603 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2604 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2605 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2606 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
|
2607 return lnum1 - baseline; |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2608 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
|
2609 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2610 /* Inside the diffblock */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2611 baseline = lnum1 - dp->df_lnum[idx1]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2612 if (baseline > dp->df_count[idx2]) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2613 baseline = dp->df_count[idx2]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2614 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2615 return dp->df_lnum[idx2] + baseline; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2616 } |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2617 if ( (dp->df_lnum[idx1] == lnum1) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2618 && (dp->df_count[idx1] == 0) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2619 && (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
|
2620 && ((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
|
2621 > curwin->w_cursor.lnum)) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2622 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2623 * 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
|
2624 * 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
|
2625 * 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
|
2626 * 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
|
2627 * as expected. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2628 */ |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2629 return curwin->w_cursor.lnum; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2630 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
|
2631 - (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
|
2632 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2633 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2634 /* 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
|
2635 return lnum1 - baseline; |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2636 } |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2637 |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2638 /* |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2639 * 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
|
2640 * "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
|
2641 */ |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2642 linenr_T |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2643 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
|
2644 { |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2645 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
|
2646 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2647 /* 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
|
2648 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
|
2649 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
|
2650 return lnum; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2651 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2652 |
7 | 2653 /* |
2654 * For line "lnum" in the current window find the equivalent lnum in window | |
2655 * "wp", compensating for inserted/deleted lines. | |
2656 */ | |
2657 linenr_T | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2658 diff_lnum_win(linenr_T lnum, win_T *wp) |
7 | 2659 { |
2660 diff_T *dp; | |
2661 int idx; | |
2662 int i; | |
2663 linenr_T n; | |
2664 | |
2665 idx = diff_buf_idx(curbuf); | |
2666 if (idx == DB_COUNT) /* safety check */ | |
2667 return (linenr_T)0; | |
2668 | |
672 | 2669 if (curtab->tp_diff_invalid) |
7 | 2670 ex_diffupdate(NULL); /* update after a big change */ |
2671 | |
2672 /* search for a change that includes "lnum" in the list of diffblocks. */ | |
672 | 2673 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
7 | 2674 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
2675 break; | |
2676 | |
2677 /* When after the last change, compute relative to the last line number. */ | |
2678 if (dp == NULL) | |
2679 return wp->w_buffer->b_ml.ml_line_count | |
2680 - (curbuf->b_ml.ml_line_count - lnum); | |
2681 | |
2682 /* Find index for "wp". */ | |
2683 i = diff_buf_idx(wp->w_buffer); | |
2684 if (i == DB_COUNT) /* safety check */ | |
2685 return (linenr_T)0; | |
2686 | |
2687 n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]); | |
2688 if (n > dp->df_lnum[i] + dp->df_count[i]) | |
2689 n = dp->df_lnum[i] + dp->df_count[i]; | |
2690 return n; | |
2691 } | |
2692 | |
2693 #endif /* FEAT_DIFF */ |