summaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c57
1 files changed, 41 insertions, 16 deletions
diff --git a/src/eval.c b/src/eval.c
index 085eff88c..e757f6bc7 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -16643,9 +16643,48 @@ 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, TRUE);
+ 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 (autocomands can
+ * make them invalid). */
+ if (valid_tabpage(save_curtab))
+ goto_tabpage_tp(save_curtab, TRUE);
+ if (win_valid(save_curwin))
+ {
+ curwin = save_curwin;
+ curbuf = curwin->w_buffer;
+ }
+#endif
+}
+
/*
* "setwinvar()" and "settabwinvar()" functions
*/
+
static void
setwinvar(argvars, rettv, off)
typval_T *argvars;
@@ -16678,14 +16717,8 @@ setwinvar(argvars, rettv, off)
if (win != NULL && varname != NULL && varp != NULL)
{
#ifdef FEAT_WINDOWS
- /* set curwin to be our win, temporarily */
- save_curwin = curwin;
- save_curtab = curtab;
- goto_tabpage_tp(tp, TRUE);
- if (!win_valid(win))
+ if (switch_win(&save_curwin, &save_curtab, win, tp) == FAIL)
return;
- curwin = win;
- curbuf = curwin->w_buffer;
#endif
if (*varname == '&')
@@ -16713,15 +16746,7 @@ setwinvar(argvars, rettv, off)
}
#ifdef FEAT_WINDOWS
- /* Restore current tabpage and window, if still valid (autocomands can
- * make them invalid). */
- if (valid_tabpage(save_curtab))
- goto_tabpage_tp(save_curtab, TRUE);
- if (win_valid(save_curwin))
- {
- curwin = save_curwin;
- curbuf = curwin->w_buffer;
- }
+ restore_win(save_curwin, save_curtab);
#endif
}
}