diff options
-rw-r--r-- | src/diff.c | 54 | ||||
-rw-r--r-- | src/option.c | 13 | ||||
-rw-r--r-- | src/structs.h | 18 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 80 insertions, 7 deletions
diff --git a/src/diff.c b/src/diff.c index cf091408d..92648a361 100644 --- a/src/diff.c +++ b/src/diff.c @@ -1138,21 +1138,36 @@ diff_win_options(wp, addbuf) # endif wp->w_p_diff = TRUE; + /* Use 'scrollbind' and 'cursorbind' when available */ #ifdef FEAT_SCROLLBIND + if (!wp->w_p_diff_saved) + wp->w_p_scb_save = wp->w_p_scb; wp->w_p_scb = TRUE; #endif #ifdef FEAT_CURSORBIND + if (!wp->w_p_diff_saved) + wp->w_p_crb_save = wp->w_p_crb; wp->w_p_crb = TRUE; #endif + if (!wp->w_p_diff_saved) + 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) + 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) + { + wp->w_p_fdc_save = wp->w_p_fdc; + wp->w_p_fen_save = wp->w_p_fen; + wp->w_p_fdl_save = wp->w_p_fdl; + } wp->w_p_fdc = diff_foldcolumn; wp->w_p_fen = TRUE; wp->w_p_fdl = 0; @@ -1164,6 +1179,8 @@ diff_win_options(wp, addbuf) if (vim_strchr(p_sbo, 'h') == NULL) do_cmdline_cmd((char_u *)"set sbo+=hor"); #endif + /* Saved the current values, to be restored in ex_diffoff(). */ + wp->w_p_diff_saved = TRUE; if (addbuf) diff_buf_add(wp->w_buffer); @@ -1188,25 +1205,48 @@ ex_diffoff(eap) { if (wp == curwin || (eap->forceit && wp->w_p_diff)) { - /* Set 'diff', 'scrollbind' off and 'wrap' on. */ + /* Set 'diff', 'scrollbind' off and 'wrap' on. If option values + * were saved in diff_win_options() restore them. */ wp->w_p_diff = FALSE; - RESET_BINDING(wp); - wp->w_p_wrap = TRUE; + +#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; - set_string_option_direct((char_u *)"fdm", -1, + if (wp->w_p_diff_saved) + { + 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; - wp->w_p_fdc = 0; - wp->w_p_fen = FALSE; - wp->w_p_fdl = 0; + 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_fen) + wp->w_p_fen = wp->w_p_diff_saved ? wp->w_p_fen_save : FALSE; + if (wp->w_p_fdl == 0 && wp->w_p_diff_saved) + wp->w_p_fdl = wp->w_p_fdl_save; 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; diff --git a/src/option.c b/src/option.c index 8911b015a..e91ef5d60 100644 --- a/src/option.c +++ b/src/option.c @@ -10118,14 +10118,19 @@ copy_winopt(from, to) to->wo_stl = vim_strsave(from->wo_stl); #endif to->wo_wrap = from->wo_wrap; +#ifdef FEAT_DIFF + to->wo_wrap_save = from->wo_wrap_save; +#endif #ifdef FEAT_LINEBREAK to->wo_lbr = from->wo_lbr; #endif #ifdef FEAT_SCROLLBIND to->wo_scb = from->wo_scb; + to->wo_scb_save = from->wo_scb_save; #endif #ifdef FEAT_CURSORBIND to->wo_crb = from->wo_crb; + to->wo_crb_save = from->wo_crb_save; #endif #ifdef FEAT_SPELL to->wo_spell = from->wo_spell; @@ -10137,6 +10142,7 @@ copy_winopt(from, to) #endif #ifdef FEAT_DIFF to->wo_diff = from->wo_diff; + to->wo_diff_saved = from->wo_diff_saved; #endif #ifdef FEAT_CONCEAL to->wo_cocu = vim_strsave(from->wo_cocu); @@ -10144,11 +10150,16 @@ copy_winopt(from, to) #endif #ifdef FEAT_FOLDING to->wo_fdc = from->wo_fdc; + to->wo_fdc_save = from->wo_fdc_save; to->wo_fen = from->wo_fen; + to->wo_fen_save = from->wo_fen_save; to->wo_fdi = vim_strsave(from->wo_fdi); to->wo_fml = from->wo_fml; to->wo_fdl = from->wo_fdl; + to->wo_fdl_save = from->wo_fdl_save; to->wo_fdm = vim_strsave(from->wo_fdm); + to->wo_fdm_save = from->wo_diff_saved + ? vim_strsave(from->wo_fdm_save) : empty_option; to->wo_fdn = from->wo_fdn; # ifdef FEAT_EVAL to->wo_fde = vim_strsave(from->wo_fde); @@ -10180,6 +10191,7 @@ check_winopt(wop) #ifdef FEAT_FOLDING check_string_option(&wop->wo_fdi); check_string_option(&wop->wo_fdm); + check_string_option(&wop->wo_fdm_save); # ifdef FEAT_EVAL check_string_option(&wop->wo_fde); check_string_option(&wop->wo_fdt); @@ -10210,6 +10222,7 @@ clear_winopt(wop) #ifdef FEAT_FOLDING clear_string_option(&wop->wo_fdi); clear_string_option(&wop->wo_fdm); + clear_string_option(&wop->wo_fdm_save); # ifdef FEAT_EVAL clear_string_option(&wop->wo_fde); clear_string_option(&wop->wo_fdt); diff --git a/src/structs.h b/src/structs.h index 1fc91dc9b..f74d218bd 100644 --- a/src/structs.h +++ b/src/structs.h @@ -141,14 +141,22 @@ typedef struct #ifdef FEAT_FOLDING long wo_fdc; # define w_p_fdc w_onebuf_opt.wo_fdc /* 'foldcolumn' */ + int wo_fdc_save; +# define w_p_fdc_save w_onebuf_opt.wo_fdc_save /* 'foldenable' saved for diff mode */ int wo_fen; # define w_p_fen w_onebuf_opt.wo_fen /* 'foldenable' */ + int wo_fen_save; +# define w_p_fen_save w_onebuf_opt.wo_fen_save /* 'foldenable' saved for diff mode */ char_u *wo_fdi; # define w_p_fdi w_onebuf_opt.wo_fdi /* 'foldignore' */ long wo_fdl; # define w_p_fdl w_onebuf_opt.wo_fdl /* 'foldlevel' */ + int wo_fdl_save; +# define w_p_fdl_save w_onebuf_opt.wo_fdl_save /* 'foldlevel' state saved for diff mode */ char_u *wo_fdm; # define w_p_fdm w_onebuf_opt.wo_fdm /* 'foldmethod' */ + char_u *wo_fdm_save; +# define w_p_fdm_save w_onebuf_opt.wo_fdm_save /* 'fdm' saved for diff mode */ long wo_fml; # define w_p_fml w_onebuf_opt.wo_fml /* 'foldminlines' */ long wo_fdn; @@ -213,9 +221,17 @@ typedef struct #ifdef FEAT_SCROLLBIND int wo_scb; # define w_p_scb w_onebuf_opt.wo_scb /* 'scrollbind' */ + int wo_diff_saved; /* options were saved for starting diff mode */ +# define w_p_diff_saved w_onebuf_opt.wo_diff_saved + int wo_scb_save; /* 'scrollbind' saved for diff mode*/ +# define w_p_scb_save w_onebuf_opt.wo_scb_save #endif int wo_wrap; #define w_p_wrap w_onebuf_opt.wo_wrap /* 'wrap' */ +#ifdef FEAT_DIFF + int wo_wrap_save; /* 'wrap' state saved for diff mode*/ +# define w_p_wrap_save w_onebuf_opt.wo_wrap_save +#endif #ifdef FEAT_CONCEAL char_u *wo_cocu; /* 'concealcursor' */ # define w_p_cocu w_onebuf_opt.wo_cocu @@ -225,6 +241,8 @@ typedef struct #ifdef FEAT_CURSORBIND int wo_crb; # define w_p_crb w_onebuf_opt.wo_crb /* 'cursorbind' */ + int wo_crb_save; /* 'cursorbind' state saved for diff mode*/ +# define w_p_crb_save w_onebuf_opt.wo_crb_save #endif #ifdef FEAT_EVAL diff --git a/src/version.c b/src/version.c index e03d81b06..e4c6d503d 100644 --- a/src/version.c +++ b/src/version.c @@ -729,6 +729,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1294, +/**/ 1293, /**/ 1292, |