763
763
// Make a difference between the first buffer and every other.
764
764
for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) {
765
765
buf_T *buf = curtab->tp_diffbuf[idx_new];
766
if (buf == NULL || buf->b_ml.ml_mfp == NULL) {
767
continue; // skip buffer that isn't loaded
770
770
if (diff_write(buf, tmp_new) == FAIL) {
819
819
(diff_flags & DIFF_IWHITE) ? "-b " : "",
820
820
(diff_flags & DIFF_ICASE) ? "-i " : "",
821
821
tmp_orig, tmp_new);
822
append_redir(cmd, (int)len, p_srr, tmp_diff);
823
block_autocmds(); /* Avoid ShellCmdPost stuff */
822
append_redir(cmd, len, p_srr, tmp_diff);
823
block_autocmds(); // Avoid ShellCmdPost stuff
824
824
(void)call_shell(
826
826
kShellOptFilter | kShellOptSilent | kShellOptDoOut,
1057
1057
newFoldLevel();
1058
1058
curwin = old_curwin;
1060
wp->w_p_diff = TRUE;
1062
1060
// Use 'scrollbind' and 'cursorbind' when available
1063
if (!wp->w_p_diff_saved) {
1061
if (!wp->w_p_diff) {
1064
1062
wp->w_p_scb_save = wp->w_p_scb;
1066
1064
wp->w_p_scb = TRUE;
1068
if (!wp->w_p_diff_saved) {
1066
if (!wp->w_p_diff) {
1069
1067
wp->w_p_crb_save = wp->w_p_crb;
1071
1069
wp->w_p_crb = TRUE;
1073
if (!wp->w_p_diff_saved) {
1071
if (!wp->w_p_diff) {
1074
1072
wp->w_p_wrap_save = wp->w_p_wrap;
1076
1074
wp->w_p_wrap = FALSE;
1078
1076
curbuf = curwin->w_buffer;
1080
if (!wp->w_p_diff_saved) {
1078
if (!wp->w_p_diff) {
1079
if (wp->w_p_diff_saved) {
1080
free_string_option(wp->w_p_fdm_save);
1081
1082
wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm);
1083
1084
set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff",
1117
1120
void ex_diffoff(exarg_T *eap)
1119
win_T *old_curwin = curwin;
1120
int diffwin = FALSE;
1122
int diffwin = false;
1122
1124
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
1123
1125
if (eap->forceit ? wp->w_p_diff : (wp == curwin)) {
1124
// Set 'diff', 'scrollbind' off and 'wrap' on. If option values
1125
// were saved in diff_win_options() restore them.
1126
wp->w_p_diff = FALSE;
1129
wp->w_p_scb = wp->w_p_diff_saved ? wp->w_p_scb_save : FALSE;
1133
wp->w_p_crb = wp->w_p_diff_saved ? wp->w_p_crb_save : FALSE;
1136
if (!wp->w_p_wrap) {
1137
wp->w_p_wrap = wp->w_p_diff_saved ? wp->w_p_wrap_save : TRUE;
1140
curbuf = curwin->w_buffer;
1126
// Set 'diff' off. If option values were saved in
1127
// diff_win_options(), restore the ones whose settings seem to have
1128
// been left over from diff mode.
1129
wp->w_p_diff = false;
1142
1131
if (wp->w_p_diff_saved) {
1133
wp->w_p_scb = wp->w_p_scb_save;
1137
wp->w_p_crb = wp->w_p_crb_save;
1140
if (!wp->w_p_wrap) {
1141
wp->w_p_wrap = wp->w_p_wrap_save;
1143
1144
free_string_option(wp->w_p_fdm);
1144
wp->w_p_fdm = wp->w_p_fdm_save;
1145
wp->w_p_fdm_save = empty_option;
1147
set_string_option_direct((char_u *)"fdm", -1,
1148
(char_u *)"manual", OPT_LOCAL | OPT_FREE, 0);
1150
curwin = old_curwin;
1151
curbuf = curwin->w_buffer;
1153
if (wp->w_p_fdc == diff_foldcolumn) {
1154
wp->w_p_fdc = wp->w_p_diff_saved ? wp->w_p_fdc_save : 0;
1157
if ((wp->w_p_fdl == 0)
1158
&& wp->w_p_diff_saved) {
1159
wp->w_p_fdl = wp->w_p_fdl_save;
1145
wp->w_p_fdm = vim_strsave(wp->w_p_fdm_save);
1146
if (wp->w_p_fdc == diff_foldcolumn) {
1147
wp->w_p_fdc = wp->w_p_fdc_save;
1149
if (wp->w_p_fdl == 0) {
1150
wp->w_p_fdl = wp->w_p_fdl_save;
1163
1152
// Only restore 'foldenable' when 'foldmethod' is not
1164
1153
// "manual", otherwise we continue to show the diff folds.
1165
if (foldmethodIsManual(wp) || !wp->w_p_diff_saved) {
1166
wp->w_p_fen = FALSE;
1168
wp->w_p_fen = wp->w_p_fen_save;
1155
wp->w_p_fen = foldmethodIsManual(wp) ? false : wp->w_p_fen_save;
1160
// make sure topline is not halfway through a fold
1161
changed_window_setting_win(wp);
1174
// make sure topline is not halfway through a fold
1175
changed_window_setting_win(wp);
1177
1164
// Note: 'sbo' is not restored, it's a global option.
1178
1165
diff_buf_adjust(wp);
1180
wp->w_p_diff_saved = FALSE;
1182
1167
diffwin |= wp->w_p_diff;
1546
1531
return maxcount - dp->df_count[idx];
1549
/// Compare two entries in diff "*dp" and return TRUE if they are equal.
1552
/// @param idx1 First entry in diff "*dp"
1553
/// @param idx2 Second entry in diff "*dp"
1555
/// @return return TRUE if two entires are equal.
1556
static int diff_equal_entry(diff_T *dp, int idx1, int idx2)
1534
/// Compare two entries in diff "dp" and return true if they are equal.
1537
/// @param idx1 first entry in diff "dp"
1538
/// @param idx2 second entry in diff "dp"
1540
/// @return true if two entires are equal.
1541
static bool diff_equal_entry(diff_T *dp, int idx1, int idx2)
1542
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
1558
1544
if (dp->df_count[idx1] != dp->df_count[idx2]) {
1562
1548
if (diff_check_sanity(curtab, dp) == FAIL) {
1567
for (i = 0; i < dp->df_count[idx1]; ++i) {
1552
for (int i = 0; i < dp->df_count[idx1]; i++) {
1568
1553
char_u *line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1],
1569
dp->df_lnum[idx1] + i, FALSE));
1554
dp->df_lnum[idx1] + i, false));
1571
1556
int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2],
1572
dp->df_lnum[idx2] + i, FALSE));
1557
dp->df_lnum[idx2] + i, false));
1575
1560
if (cmp != 0) {
1582
1567
/// Compare strings "s1" and "s2" according to 'diffopt'.
1848
/// Return TRUE if 'diffopt' contains "horizontal".
1850
/// @return TRUE if 'diffopt' contains "horizontal"
1851
int diffopt_horizontal(void)
1833
/// Check that "diffopt" contains "horizontal".
1834
bool diffopt_horizontal(void)
1835
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
1853
1837
return (diff_flags & DIFF_HORIZONTAL) != 0;
1856
1840
/// Find the difference within a changed line.
1858
/// @param startp first char of the change
1859
/// @param endp last char of the change
1842
/// @param wp window whose current buffer to check
1843
/// @param lnum line number to check within the buffer
1844
/// @param startp first char of the change
1845
/// @param endp last char of the change
1861
/// @returns TRUE if the line was added, no other buffer has it.
1862
int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
1847
/// @return true if the line was added, no other buffer has it.
1848
bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
1849
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
1864
1851
char_u *line_new;
1871
1858
// Make a copy of the line, the next ml_get() will invalidate it.
1872
1859
char_u *line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE));
1974
/// Return TRUE if line "lnum" is not close to a diff block, this line should
1961
/// Check that line "lnum" is not close to a diff block, this line should
1975
1962
/// be in a fold.
1964
/// @param wp window containing the buffer to check
1965
/// @param lnum line number to check within the buffer
1980
/// @return FALSE if there are no diff blocks at all in this window.
1981
int diff_infold(win_T *wp, linenr_T lnum)
1967
/// @return false if there are no diff blocks at all in this window.
1968
bool diff_infold(win_T *wp, linenr_T lnum)
1969
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
1986
1974
// Return if 'diff' isn't set.
1987
1975
if (!wp->w_p_diff) {
2390
/// Checks if the buffer is in diff-mode.
2392
/// @param buf The buffer to check.
2394
/// @return TRUE if buffer "buf" is in diff-mode.
2378
/// Checks that the buffer is in diff-mode.
2380
/// @param buf buffer to check.
2395
2381
bool diff_mode_buf(buf_T *buf)
2382
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
2397
2384
FOR_ALL_TABS(tp) {
2398
2385
if (diff_buf_idx_tp(buf, tp) != DB_COUNT) {