annotate src/diff.c @ 318:1c408f85789e

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