changeset 6897:d3a23af4bba1 v7.4.768

patch 7.4.768 Problem: :diffoff only works properly once. Solution: Also make :diffoff work when used a second time. (Olaf Dabrunz)
author Bram Moolenaar <bram@vim.org>
date Fri, 03 Jul 2015 15:06:56 +0200
parents 026862df2f7b
children b1c3486d5950
files src/diff.c src/version.c
diffstat 2 files changed, 42 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/diff.c
+++ b/src/diff.c
@@ -1138,32 +1138,34 @@ diff_win_options(wp, addbuf)
     curwin = old_curwin;
 # endif
 
-    wp->w_p_diff = TRUE;
-
     /* Use 'scrollbind' and 'cursorbind' when available */
 #ifdef FEAT_SCROLLBIND
-    if (!wp->w_p_diff_saved)
+    if (!wp->w_p_diff)
 	wp->w_p_scb_save = wp->w_p_scb;
     wp->w_p_scb = TRUE;
 #endif
 #ifdef FEAT_CURSORBIND
-    if (!wp->w_p_diff_saved)
+    if (!wp->w_p_diff)
 	wp->w_p_crb_save = wp->w_p_crb;
     wp->w_p_crb = TRUE;
 #endif
-    if (!wp->w_p_diff_saved)
+    if (!wp->w_p_diff)
 	wp->w_p_wrap_save = wp->w_p_wrap;
     wp->w_p_wrap = FALSE;
 # ifdef FEAT_FOLDING
     curwin = wp;
     curbuf = curwin->w_buffer;
-    if (!wp->w_p_diff_saved)
+    if (!wp->w_p_diff)
+    {
+	if (wp->w_p_diff_saved)
+	    free_string_option(wp->w_p_fdm_save);
 	wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm);
+    }
     set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff",
 						       OPT_LOCAL|OPT_FREE, 0);
     curwin = old_curwin;
     curbuf = curwin->w_buffer;
-    if (!wp->w_p_diff_saved)
+    if (!wp->w_p_diff)
     {
 	wp->w_p_fdc_save = wp->w_p_fdc;
 	wp->w_p_fen_save = wp->w_p_fen;
@@ -1183,6 +1185,8 @@ diff_win_options(wp, addbuf)
     /* Saved the current values, to be restored in ex_diffoff(). */
     wp->w_p_diff_saved = TRUE;
 
+    wp->w_p_diff = TRUE;
+
     if (addbuf)
 	diff_buf_add(wp->w_buffer);
     redraw_win_later(wp, NOT_VALID);
@@ -1197,7 +1201,6 @@ ex_diffoff(eap)
     exarg_T	*eap;
 {
     win_T	*wp;
-    win_T	*old_curwin = curwin;
 #ifdef FEAT_SCROLLBIND
     int		diffwin = FALSE;
 #endif
@@ -1206,57 +1209,47 @@ ex_diffoff(eap)
     {
 	if (eap->forceit ? wp->w_p_diff : wp == curwin)
 	{
-	    /* Set 'diff', 'scrollbind' off and 'wrap' on. If option values
-	     * were saved in diff_win_options() restore them. */
+	    /* Set 'diff' off. If option values were saved in
+	     * diff_win_options(), restore the ones whose settings seem to have
+	     * been left over from diff mode.  */
 	    wp->w_p_diff = FALSE;
 
-#ifdef FEAT_SCROLLBIND
-	    if (wp->w_p_scb)
-		wp->w_p_scb = wp->w_p_diff_saved ? wp->w_p_scb_save : FALSE;
-#endif
-#ifdef FEAT_CURSORBIND
-	    if (wp->w_p_crb)
-		wp->w_p_crb = wp->w_p_diff_saved ? wp->w_p_crb_save : FALSE;
-#endif
-	    if (!wp->w_p_wrap)
-		wp->w_p_wrap = wp->w_p_diff_saved ? wp->w_p_wrap_save : TRUE;
-#ifdef FEAT_FOLDING
-	    curwin = wp;
-	    curbuf = curwin->w_buffer;
 	    if (wp->w_p_diff_saved)
 	    {
+
+#ifdef FEAT_SCROLLBIND
+		if (wp->w_p_scb)
+		    wp->w_p_scb = wp->w_p_scb_save;
+#endif
+#ifdef FEAT_CURSORBIND
+		if (wp->w_p_crb)
+		    wp->w_p_crb = wp->w_p_crb_save;
+#endif
+		if (!wp->w_p_wrap)
+		    wp->w_p_wrap = wp->w_p_wrap_save;
+#ifdef FEAT_FOLDING
 		free_string_option(wp->w_p_fdm);
-		wp->w_p_fdm = wp->w_p_fdm_save;
-		wp->w_p_fdm_save = empty_option;
-	    }
-	    else
-		set_string_option_direct((char_u *)"fdm", -1,
-				   (char_u *)"manual", OPT_LOCAL|OPT_FREE, 0);
-	    curwin = old_curwin;
-	    curbuf = curwin->w_buffer;
-	    if (wp->w_p_fdc == diff_foldcolumn)
-		wp->w_p_fdc = wp->w_p_diff_saved ? wp->w_p_fdc_save : 0;
-	    if (wp->w_p_fdl == 0 && wp->w_p_diff_saved)
-		wp->w_p_fdl = wp->w_p_fdl_save;
+		wp->w_p_fdm = vim_strsave(wp->w_p_fdm_save);
 
-	    if (wp->w_p_fen)
-	    {
+		if (wp->w_p_fdc == diff_foldcolumn)
+		    wp->w_p_fdc = wp->w_p_fdc_save;
+		if (wp->w_p_fdl == 0)
+		    wp->w_p_fdl = wp->w_p_fdl_save;
+
 		/* Only restore 'foldenable' when 'foldmethod' is not
 		 * "manual", otherwise we continue to show the diff folds. */
-		if (foldmethodIsManual(wp) || !wp->w_p_diff_saved)
-		    wp->w_p_fen = FALSE;
-		else
-		    wp->w_p_fen = wp->w_p_fen_save;
+		if (wp->w_p_fen)
+		    wp->w_p_fen = foldmethodIsManual(wp) ? FALSE
+							 : wp->w_p_fen_save;
+
+		foldUpdateAll(wp);
+		/* make sure topline is not halfway a fold */
+		changed_window_setting_win(wp);
+#endif
 	    }
 
-	    foldUpdateAll(wp);
-	    /* make sure topline is not halfway a fold */
-	    changed_window_setting_win(wp);
-#endif
 	    /* Note: 'sbo' is not restored, it's a global option. */
 	    diff_buf_adjust(wp);
-
-	    wp->w_p_diff_saved = FALSE;
 	}
 #ifdef FEAT_SCROLLBIND
 	diffwin |= wp->w_p_diff;
--- a/src/version.c
+++ b/src/version.c
@@ -742,6 +742,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    768,
+/**/
     767,
 /**/
     766,