vim-patch:7.4.888

Problem:    The OptionSet autocommands are not triggered from setwinvar().
Solution:   Do not use switch_win() when not needed. (Hirohito Higashi)

ba117c23df
This commit is contained in:
Jurica Bradaric
2016-02-11 23:01:30 +01:00
parent 7609a96a35
commit de23395fa7
2 changed files with 43 additions and 31 deletions

View File

@@ -10697,11 +10697,11 @@ getwinvar (
int off /* 1 for gettabwinvar() */ int off /* 1 for gettabwinvar() */
) )
{ {
win_T *win, *oldcurwin; win_T *win, *oldcurwin;
char_u *varname; char_u *varname;
dictitem_T *v; dictitem_T *v;
tabpage_T *tp = NULL; tabpage_T *tp = NULL;
tabpage_T *oldtabpage = NULL; tabpage_T *oldtabpage = NULL;
bool done = false; bool done = false;
if (off == 1) if (off == 1)
@@ -10716,12 +10716,16 @@ getwinvar (
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
if (win != NULL && varname != NULL) { if (win != NULL && varname != NULL) {
/* Set curwin to be our win, temporarily. Also set the tabpage, // Set curwin to be our win, temporarily. Also set the tabpage,
* otherwise the window is not valid. */ // otherwise the window is not valid. Only do this when needed,
if (switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK) { // autocommands get blocked.
if (*varname == '&') { /* window-local-option */ bool need_switch_win = tp != curtab || win != curwin;
if (get_option_tv(&varname, rettv, 1) == OK) if (!need_switch_win
|| switch_win(&oldcurwin, &oldtabpage, win, tp, true) == OK) {
if (*varname == '&') { // window-local-option
if (get_option_tv(&varname, rettv, 1) == OK) {
done = true; done = true;
}
} else { } else {
// Look up the variable. // Look up the variable.
// Let getwinvar({nr}, "") return the "w:" dictionary. // Let getwinvar({nr}, "") return the "w:" dictionary.
@@ -10733,8 +10737,10 @@ getwinvar (
} }
} }
/* restore previous notion of curwin */ if (need_switch_win) {
restore_win(oldcurwin, oldtabpage, TRUE); // restore previous notion of curwin
restore_win(oldcurwin, oldtabpage, true);
}
} }
if (!done && argvars[off + 2].v_type != VAR_UNKNOWN) if (!done && argvars[off + 2].v_type != VAR_UNKNOWN)
@@ -15559,26 +15565,32 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off)
varname = get_tv_string_chk(&argvars[off + 1]); varname = get_tv_string_chk(&argvars[off + 1]);
varp = &argvars[off + 2]; varp = &argvars[off + 2];
if (win != NULL && varname != NULL && varp != NULL if (win != NULL && varname != NULL && varp != NULL) {
&& switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK) { bool need_switch_win = tp != curtab || win != curwin;
if (*varname == '&') { if (!need_switch_win
long numval; || switch_win(&save_curwin, &save_curtab, win, tp, true) == OK) {
char_u *strval; if (*varname == '&') {
int error = FALSE; long numval;
char_u *strval;
int error = false;
++varname; ++varname;
numval = get_tv_number_chk(varp, &error); numval = get_tv_number_chk(varp, &error);
strval = get_tv_string_buf_chk(varp, nbuf); strval = get_tv_string_buf_chk(varp, nbuf);
if (!error && strval != NULL) if (!error && strval != NULL) {
set_option_value(varname, numval, strval, OPT_LOCAL); set_option_value(varname, numval, strval, OPT_LOCAL);
} else { }
winvarname = xmalloc(STRLEN(varname) + 3); } else {
STRCPY(winvarname, "w:"); winvarname = xmalloc(STRLEN(varname) + 3);
STRCPY(winvarname + 2, varname); STRCPY(winvarname, "w:");
set_var(winvarname, varp, TRUE); STRCPY(winvarname + 2, varname);
xfree(winvarname); set_var(winvarname, varp, TRUE);
xfree(winvarname);
}
}
if (need_switch_win) {
restore_win(save_curwin, save_curtab, true);
} }
restore_win(save_curwin, save_curtab, TRUE);
} }
} }

View File

@@ -400,7 +400,7 @@ static int included_patches[] = {
// 891, // 891,
// 890 NA // 890 NA
// 889, // 889,
// 888, 888,
887, 887,
// 886 NA // 886 NA
// 885, // 885,