2424static int diff_busy = FALSE; /* ex_diffgetput() is busy */
2525
2626/* flags obtained from the 'diffopt' option */
27- #define DIFF_FILLER 1 // display filler lines
28- #define DIFF_ICASE 2 // ignore case
29- #define DIFF_IWHITE 4 // ignore change in white space
30- #define DIFF_HORIZONTAL 8 // horizontal splits
31- #define DIFF_VERTICAL 16 // vertical splits
32- #define DIFF_HIDDEN_OFF 32 // diffoff when hidden
33- #define DIFF_INTERNAL 64 // use internal xdiff algorithm
27+ #define DIFF_FILLER 0x001 // display filler lines
28+ #define DIFF_IBLANK 0x002 // ignore empty lines
29+ #define DIFF_ICASE 0x004 // ignore case
30+ #define DIFF_IWHITE 0x008 // ignore change in white space
31+ #define DIFF_IWHITEALL 0x010 // ignore all white space changes
32+ #define DIFF_IWHITEEOL 0x020 // ignore change in white space at EOL
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)
3438static int diff_flags = DIFF_INTERNAL | DIFF_FILLER ;
3539
3640static long diff_algorithm = 0 ;
@@ -1050,6 +1054,12 @@ diff_file_internal(diffio_T *diffio)
10501054
10511055 if (diff_flags & DIFF_IWHITE )
10521056 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 ;
10531063
10541064 emit_cfg .ctxlen = 0 ; // don't need any diff_context here
10551065 emit_cb .priv = & diffio -> dio_diff ;
@@ -1106,14 +1116,17 @@ diff_file(diffio_T *dio)
11061116 // Build the diff command and execute it. Always use -a, binary
11071117 // differences are of no use. Ignore errors, diff returns
11081118 // 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" ,
11101120 diff_a_works == FALSE ? "" : "-a " ,
11111121#if defined(MSWIN )
11121122 diff_bin_works == TRUE ? "--binary " : "" ,
11131123#else
11141124 "" ,
11151125#endif
11161126 (diff_flags & DIFF_IWHITE ) ? "-b " : "" ,
1127+ (diff_flags & DIFF_IWHITEALL ) ? "-w " : "" ,
1128+ (diff_flags & DIFF_IWHITEEOL ) ? "-Z " : "" ,
1129+ (diff_flags & DIFF_IBLANK ) ? "-B " : "" ,
11171130 (diff_flags & DIFF_ICASE ) ? "-i " : "" ,
11181131 tmp_orig , tmp_new );
11191132 append_redir (cmd , (int )len , p_srr , tmp_diff );
@@ -1946,17 +1959,25 @@ diff_cmp(char_u *s1, char_u *s2)
19461959 char_u * p1 , * p2 ;
19471960 int l ;
19481961
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 )
19501967 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 ))
19521969 return MB_STRICMP (s1 , s2 );
19531970
1954- /* Ignore white space changes and possibly ignore case. */
19551971 p1 = s1 ;
19561972 p2 = s2 ;
1973+
1974+ // Ignore white space changes and possibly ignore case.
19571975 while (* p1 != NUL && * p2 != NUL )
19581976 {
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 ))))
19601981 {
19611982 p1 = skipwhite (p1 );
19621983 p2 = skipwhite (p2 );
@@ -1970,7 +1991,7 @@ diff_cmp(char_u *s1, char_u *s2)
19701991 }
19711992 }
19721993
1973- /* Ignore trailing white space. */
1994+ // Ignore trailing white space.
19741995 p1 = skipwhite (p1 );
19751996 p2 = skipwhite (p2 );
19761997 if (* p1 != NUL || * p2 != NUL )
@@ -2142,11 +2163,26 @@ diffopt_changed(void)
21422163 p += 8 ;
21432164 diff_context_new = getdigits (& p );
21442165 }
2166+ else if (STRNCMP (p , "iblank" , 6 ) == 0 )
2167+ {
2168+ p += 6 ;
2169+ diff_flags_new |= DIFF_IBLANK ;
2170+ }
21452171 else if (STRNCMP (p , "icase" , 5 ) == 0 )
21462172 {
21472173 p += 5 ;
21482174 diff_flags_new |= DIFF_ICASE ;
21492175 }
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 ;
2185+ }
21502186 else if (STRNCMP (p , "iwhite" , 6 ) == 0 )
21512187 {
21522188 p += 6 ;
@@ -2315,9 +2351,12 @@ diff_find_change(
23152351 si_org = si_new = 0 ;
23162352 while (line_org [si_org ] != NUL )
23172353 {
2318- if ((diff_flags & DIFF_IWHITE )
2319- && VIM_ISWHITE (line_org [si_org ])
2320- && VIM_ISWHITE (line_new [si_new ]))
2354+ if (((diff_flags & DIFF_IWHITE )
2355+ && VIM_ISWHITE (line_org [si_org ])
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 ]))))
23212360 {
23222361 si_org = (int )(skipwhite (line_org + si_org ) - line_org );
23232362 si_new = (int )(skipwhite (line_new + si_new ) - line_new );
@@ -2351,9 +2390,12 @@ diff_find_change(
23512390 while (ei_org >= * startp && ei_new >= si_new
23522391 && ei_org >= 0 && ei_new >= 0 )
23532392 {
2354- if ((diff_flags & DIFF_IWHITE )
2355- && VIM_ISWHITE (line_org [ei_org ])
2356- && VIM_ISWHITE (line_new [ei_new ]))
2393+ if (((diff_flags & DIFF_IWHITE )
2394+ && VIM_ISWHITE (line_org [ei_org ])
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 ]))))
23572399 {
23582400 while (ei_org >= * startp
23592401 && VIM_ISWHITE (line_org [ei_org ]))
0 commit comments