comparison src/diff.c @ 14762:b43ea03bb522 v8.1.0393

patch 8.1.0393: not all white space difference options available commit https://github.com/vim/vim/commit/785fc6567f572b8caefbc89ec29bbd8b801464ae Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 15 19:17:38 2018 +0200 patch 8.1.0393: not all white space difference options available Problem: Not all white space difference options available. Solution: Add "iblank", "iwhiteall" and "iwhiteeol" to 'diffopt'.
author Christian Brabandt <cb@256bit.org>
date Sat, 15 Sep 2018 19:30:06 +0200
parents 193471015e1a
children f562b9fbd0d3
comparison
equal deleted inserted replaced
14761:99582039da8d 14762:b43ea03bb522
22 #if defined(FEAT_DIFF) || defined(PROTO) 22 #if defined(FEAT_DIFF) || defined(PROTO)
23 23
24 static int diff_busy = FALSE; /* ex_diffgetput() is busy */ 24 static int diff_busy = FALSE; /* ex_diffgetput() is busy */
25 25
26 /* flags obtained from the 'diffopt' option */ 26 /* flags obtained from the 'diffopt' option */
27 #define DIFF_FILLER 1 // display filler lines 27 #define DIFF_FILLER 0x001 // display filler lines
28 #define DIFF_ICASE 2 // ignore case 28 #define DIFF_IBLANK 0x002 // ignore empty lines
29 #define DIFF_IWHITE 4 // ignore change in white space 29 #define DIFF_ICASE 0x004 // ignore case
30 #define DIFF_HORIZONTAL 8 // horizontal splits 30 #define DIFF_IWHITE 0x008 // ignore change in white space
31 #define DIFF_VERTICAL 16 // vertical splits 31 #define DIFF_IWHITEALL 0x010 // ignore all white space changes
32 #define DIFF_HIDDEN_OFF 32 // diffoff when hidden 32 #define DIFF_IWHITEEOL 0x020 // ignore change in white space at EOL
33 #define DIFF_INTERNAL 64 // use internal xdiff algorithm 33 #define DIFF_HORIZONTAL 0x040 // horizontal splits
34 #define DIFF_VERTICAL 0x080 // vertical splits
35 #define DIFF_HIDDEN_OFF 0x100 // diffoff when hidden
36 #define DIFF_INTERNAL 0x200 // use internal xdiff algorithm
37 #define ALL_WHITE_DIFF (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL)
34 static int diff_flags = DIFF_INTERNAL | DIFF_FILLER; 38 static int diff_flags = DIFF_INTERNAL | DIFF_FILLER;
35 39
36 static long diff_algorithm = 0; 40 static long diff_algorithm = 0;
37 41
38 #define LBUFLEN 50 /* length of line in diff file */ 42 #define LBUFLEN 50 /* length of line in diff file */
1048 1052
1049 param.flags = diff_algorithm; 1053 param.flags = diff_algorithm;
1050 1054
1051 if (diff_flags & DIFF_IWHITE) 1055 if (diff_flags & DIFF_IWHITE)
1052 param.flags |= XDF_IGNORE_WHITESPACE_CHANGE; 1056 param.flags |= XDF_IGNORE_WHITESPACE_CHANGE;
1057 if (diff_flags & DIFF_IWHITEALL)
1058 param.flags |= XDF_IGNORE_WHITESPACE;
1059 if (diff_flags & DIFF_IWHITEEOL)
1060 param.flags |= XDF_IGNORE_WHITESPACE_AT_EOL;
1061 if (diff_flags & DIFF_IBLANK)
1062 param.flags |= XDF_IGNORE_BLANK_LINES;
1053 1063
1054 emit_cfg.ctxlen = 0; // don't need any diff_context here 1064 emit_cfg.ctxlen = 0; // don't need any diff_context here
1055 emit_cb.priv = &diffio->dio_diff; 1065 emit_cb.priv = &diffio->dio_diff;
1056 emit_cb.outf = xdiff_out; 1066 emit_cb.outf = xdiff_out;
1057 if (xdl_diff(&diffio->dio_orig.din_mmfile, 1067 if (xdl_diff(&diffio->dio_orig.din_mmfile,
1104 vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)""); 1114 vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)"");
1105 1115
1106 // Build the diff command and execute it. Always use -a, binary 1116 // Build the diff command and execute it. Always use -a, binary
1107 // differences are of no use. Ignore errors, diff returns 1117 // differences are of no use. Ignore errors, diff returns
1108 // non-zero when differences have been found. 1118 // non-zero when differences have been found.
1109 vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s %s", 1119 vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s%s%s%s %s",
1110 diff_a_works == FALSE ? "" : "-a ", 1120 diff_a_works == FALSE ? "" : "-a ",
1111 #if defined(MSWIN) 1121 #if defined(MSWIN)
1112 diff_bin_works == TRUE ? "--binary " : "", 1122 diff_bin_works == TRUE ? "--binary " : "",
1113 #else 1123 #else
1114 "", 1124 "",
1115 #endif 1125 #endif
1116 (diff_flags & DIFF_IWHITE) ? "-b " : "", 1126 (diff_flags & DIFF_IWHITE) ? "-b " : "",
1127 (diff_flags & DIFF_IWHITEALL) ? "-w " : "",
1128 (diff_flags & DIFF_IWHITEEOL) ? "-Z " : "",
1129 (diff_flags & DIFF_IBLANK) ? "-B " : "",
1117 (diff_flags & DIFF_ICASE) ? "-i " : "", 1130 (diff_flags & DIFF_ICASE) ? "-i " : "",
1118 tmp_orig, tmp_new); 1131 tmp_orig, tmp_new);
1119 append_redir(cmd, (int)len, p_srr, tmp_diff); 1132 append_redir(cmd, (int)len, p_srr, tmp_diff);
1120 block_autocmds(); // avoid ShellCmdPost stuff 1133 block_autocmds(); // avoid ShellCmdPost stuff
1121 (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT); 1134 (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
1944 diff_cmp(char_u *s1, char_u *s2) 1957 diff_cmp(char_u *s1, char_u *s2)
1945 { 1958 {
1946 char_u *p1, *p2; 1959 char_u *p1, *p2;
1947 int l; 1960 int l;
1948 1961
1949 if ((diff_flags & (DIFF_ICASE | DIFF_IWHITE)) == 0) 1962 if ((diff_flags & DIFF_IBLANK)
1963 && (*skipwhite(s1) == NUL || *skipwhite(s2) == NUL))
1964 return 0;
1965
1966 if ((diff_flags & (DIFF_ICASE | ALL_WHITE_DIFF)) == 0)
1950 return STRCMP(s1, s2); 1967 return STRCMP(s1, s2);
1951 if ((diff_flags & DIFF_ICASE) && !(diff_flags & DIFF_IWHITE)) 1968 if ((diff_flags & DIFF_ICASE) && !(diff_flags & ALL_WHITE_DIFF))
1952 return MB_STRICMP(s1, s2); 1969 return MB_STRICMP(s1, s2);
1953 1970
1954 /* Ignore white space changes and possibly ignore case. */
1955 p1 = s1; 1971 p1 = s1;
1956 p2 = s2; 1972 p2 = s2;
1973
1974 // Ignore white space changes and possibly ignore case.
1957 while (*p1 != NUL && *p2 != NUL) 1975 while (*p1 != NUL && *p2 != NUL)
1958 { 1976 {
1959 if (VIM_ISWHITE(*p1) && VIM_ISWHITE(*p2)) 1977 if (((diff_flags & DIFF_IWHITE)
1978 && VIM_ISWHITE(*p1) && VIM_ISWHITE(*p2))
1979 || ((diff_flags & DIFF_IWHITEALL)
1980 && (VIM_ISWHITE(*p1) || VIM_ISWHITE(*p2))))
1960 { 1981 {
1961 p1 = skipwhite(p1); 1982 p1 = skipwhite(p1);
1962 p2 = skipwhite(p2); 1983 p2 = skipwhite(p2);
1963 } 1984 }
1964 else 1985 else
1968 p1 += l; 1989 p1 += l;
1969 p2 += l; 1990 p2 += l;
1970 } 1991 }
1971 } 1992 }
1972 1993
1973 /* Ignore trailing white space. */ 1994 // Ignore trailing white space.
1974 p1 = skipwhite(p1); 1995 p1 = skipwhite(p1);
1975 p2 = skipwhite(p2); 1996 p2 = skipwhite(p2);
1976 if (*p1 != NUL || *p2 != NUL) 1997 if (*p1 != NUL || *p2 != NUL)
1977 return 1; 1998 return 1;
1978 return 0; 1999 return 0;
2140 else if (STRNCMP(p, "context:", 8) == 0 && VIM_ISDIGIT(p[8])) 2161 else if (STRNCMP(p, "context:", 8) == 0 && VIM_ISDIGIT(p[8]))
2141 { 2162 {
2142 p += 8; 2163 p += 8;
2143 diff_context_new = getdigits(&p); 2164 diff_context_new = getdigits(&p);
2144 } 2165 }
2166 else if (STRNCMP(p, "iblank", 6) == 0)
2167 {
2168 p += 6;
2169 diff_flags_new |= DIFF_IBLANK;
2170 }
2145 else if (STRNCMP(p, "icase", 5) == 0) 2171 else if (STRNCMP(p, "icase", 5) == 0)
2146 { 2172 {
2147 p += 5; 2173 p += 5;
2148 diff_flags_new |= DIFF_ICASE; 2174 diff_flags_new |= DIFF_ICASE;
2175 }
2176 else if (STRNCMP(p, "iwhiteall", 9) == 0)
2177 {
2178 p += 9;
2179 diff_flags_new |= DIFF_IWHITEALL;
2180 }
2181 else if (STRNCMP(p, "iwhiteeol", 9) == 0)
2182 {
2183 p += 9;
2184 diff_flags_new |= DIFF_IWHITEEOL;
2149 } 2185 }
2150 else if (STRNCMP(p, "iwhite", 6) == 0) 2186 else if (STRNCMP(p, "iwhite", 6) == 0)
2151 { 2187 {
2152 p += 6; 2188 p += 6;
2153 diff_flags_new |= DIFF_IWHITE; 2189 diff_flags_new |= DIFF_IWHITE;
2313 2349
2314 /* Search for start of difference */ 2350 /* Search for start of difference */
2315 si_org = si_new = 0; 2351 si_org = si_new = 0;
2316 while (line_org[si_org] != NUL) 2352 while (line_org[si_org] != NUL)
2317 { 2353 {
2318 if ((diff_flags & DIFF_IWHITE) 2354 if (((diff_flags & DIFF_IWHITE)
2319 && VIM_ISWHITE(line_org[si_org]) 2355 && VIM_ISWHITE(line_org[si_org])
2320 && VIM_ISWHITE(line_new[si_new])) 2356 && VIM_ISWHITE(line_new[si_new]))
2357 || ((diff_flags & DIFF_IWHITEALL)
2358 && (VIM_ISWHITE(line_org[si_org])
2359 || VIM_ISWHITE(line_new[si_new]))))
2321 { 2360 {
2322 si_org = (int)(skipwhite(line_org + si_org) - line_org); 2361 si_org = (int)(skipwhite(line_org + si_org) - line_org);
2323 si_new = (int)(skipwhite(line_new + si_new) - line_new); 2362 si_new = (int)(skipwhite(line_new + si_new) - line_new);
2324 } 2363 }
2325 else 2364 else
2349 ei_org = (int)STRLEN(line_org); 2388 ei_org = (int)STRLEN(line_org);
2350 ei_new = (int)STRLEN(line_new); 2389 ei_new = (int)STRLEN(line_new);
2351 while (ei_org >= *startp && ei_new >= si_new 2390 while (ei_org >= *startp && ei_new >= si_new
2352 && ei_org >= 0 && ei_new >= 0) 2391 && ei_org >= 0 && ei_new >= 0)
2353 { 2392 {
2354 if ((diff_flags & DIFF_IWHITE) 2393 if (((diff_flags & DIFF_IWHITE)
2355 && VIM_ISWHITE(line_org[ei_org]) 2394 && VIM_ISWHITE(line_org[ei_org])
2356 && VIM_ISWHITE(line_new[ei_new])) 2395 && VIM_ISWHITE(line_new[ei_new]))
2396 || ((diff_flags & DIFF_IWHITEALL)
2397 && (VIM_ISWHITE(line_org[ei_org])
2398 || VIM_ISWHITE(line_new[ei_new]))))
2357 { 2399 {
2358 while (ei_org >= *startp 2400 while (ei_org >= *startp
2359 && VIM_ISWHITE(line_org[ei_org])) 2401 && VIM_ISWHITE(line_org[ei_org]))
2360 --ei_org; 2402 --ei_org;
2361 while (ei_new >= si_new 2403 while (ei_new >= si_new