0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

updated for version 7.3.963

Problem:    Setting curbuf without curwin causes trouble.
Solution:   Add switch_buffer() and restore_buffer().  Block autocommands to
            avoid trouble.
This commit is contained in:
Bram Moolenaar
2013-05-17 16:03:57 +02:00
parent 55b8ad3dab
commit 105bc355a6
7 changed files with 163 additions and 85 deletions

View File

@@ -11894,7 +11894,7 @@ getwinvar(argvars, rettv, off)
win_T *win, *oldcurwin;
char_u *varname;
dictitem_T *v;
tabpage_T *tp;
tabpage_T *tp, *oldtabpage;
int done = FALSE;
#ifdef FEAT_WINDOWS
@@ -11912,11 +11912,9 @@ getwinvar(argvars, rettv, off)
if (win != NULL && varname != NULL)
{
/* Set curwin to be our win, temporarily. Also set curbuf, so
* that we can get buffer-local options. */
oldcurwin = curwin;
curwin = win;
curbuf = win->w_buffer;
/* Set curwin to be our win, temporarily. Also set the tabpage,
* otherwise the window is not valid. */
switch_win(&oldcurwin, &oldtabpage, win, tp);
if (*varname == '&') /* window-local-option */
{
@@ -11936,8 +11934,7 @@ getwinvar(argvars, rettv, off)
}
/* restore previous notion of curwin */
curwin = oldcurwin;
curbuf = curwin->w_buffer;
restore_win(oldcurwin, oldtabpage);
}
if (!done && argvars[off + 2].v_type != VAR_UNKNOWN)
@@ -16641,44 +16638,6 @@ f_setwinvar(argvars, rettv)
setwinvar(argvars, rettv, 0);
}
int
switch_win(save_curwin, save_curtab, win, tp)
win_T **save_curwin;
tabpage_T **save_curtab;
win_T *win;
tabpage_T *tp;
{
#ifdef FEAT_WINDOWS
/* set curwin to be our win, temporarily */
*save_curwin = curwin;
*save_curtab = curtab;
goto_tabpage_tp(tp, FALSE, FALSE);
if (!win_valid(win))
return FAIL;
curwin = win;
curbuf = curwin->w_buffer;
#endif
return OK;
}
void
restore_win(save_curwin, save_curtab)
win_T *save_curwin;
tabpage_T *save_curtab;
{
#ifdef FEAT_WINDOWS
/* Restore current tabpage and window, if still valid (autocommands can
* make them invalid). */
if (valid_tabpage(save_curtab))
goto_tabpage_tp(save_curtab, FALSE, FALSE);
if (win_valid(save_curwin))
{
curwin = save_curwin;
curbuf = curwin->w_buffer;
}
#endif
}
/*
* "setwinvar()" and "settabwinvar()" functions
*/