@@ -12420,12 +12420,16 @@ getwinvar(argvars, rettv, off)
1242012420 typval_T *rettv;
1242112421 int off; /* 1 for gettabwinvar() */
1242212422{
12423- win_T *win, *oldcurwin ;
12423+ win_T *win;
1242412424 char_u *varname;
1242512425 dictitem_T *v;
1242612426 tabpage_T *tp = NULL;
12427- tabpage_T *oldtabpage;
1242812427 int done = FALSE;
12428+ #ifdef FEAT_WINDOWS
12429+ win_T *oldcurwin;
12430+ tabpage_T *oldtabpage;
12431+ int need_switch_win;
12432+ #endif
1242912433
1243012434#ifdef FEAT_WINDOWS
1243112435 if (off == 1)
@@ -12442,9 +12446,14 @@ getwinvar(argvars, rettv, off)
1244212446
1244312447 if (win != NULL && varname != NULL)
1244412448 {
12449+ #ifdef FEAT_WINDOWS
1244512450 /* Set curwin to be our win, temporarily. Also set the tabpage,
12446- * otherwise the window is not valid. */
12447- if (switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK)
12451+ * otherwise the window is not valid. Only do this when needed,
12452+ * autocommands get blocked. */
12453+ need_switch_win = !(tp == curtab && win == curwin);
12454+ if (!need_switch_win
12455+ || switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK)
12456+ #endif
1244812457 {
1244912458 if (*varname == '&') /* window-local-option */
1245012459 {
@@ -12465,8 +12474,11 @@ getwinvar(argvars, rettv, off)
1246512474 }
1246612475 }
1246712476
12468- /* restore previous notion of curwin */
12469- restore_win(oldcurwin, oldtabpage, TRUE);
12477+ #ifdef FEAT_WINDOWS
12478+ if (need_switch_win)
12479+ /* restore previous notion of curwin */
12480+ restore_win(oldcurwin, oldtabpage, TRUE);
12481+ #endif
1247012482 }
1247112483
1247212484 if (!done && argvars[off + 2].v_type != VAR_UNKNOWN)
@@ -17597,6 +17609,7 @@ setwinvar(argvars, rettv, off)
1759717609#ifdef FEAT_WINDOWS
1759817610 win_T *save_curwin;
1759917611 tabpage_T *save_curtab;
17612+ int need_switch_win;
1760017613#endif
1760117614 char_u *varname, *winvarname;
1760217615 typval_T *varp;
@@ -17619,7 +17632,9 @@ setwinvar(argvars, rettv, off)
1761917632 if (win != NULL && varname != NULL && varp != NULL)
1762017633 {
1762117634#ifdef FEAT_WINDOWS
17622- if (switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK)
17635+ need_switch_win = !(tp == curtab && win == curwin);
17636+ if (!need_switch_win
17637+ || switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK)
1762317638#endif
1762417639 {
1762517640 if (*varname == '&')
@@ -17647,7 +17662,8 @@ setwinvar(argvars, rettv, off)
1764717662 }
1764817663 }
1764917664#ifdef FEAT_WINDOWS
17650- restore_win(save_curwin, save_curtab, TRUE);
17665+ if (need_switch_win)
17666+ restore_win(save_curwin, save_curtab, TRUE);
1765117667#endif
1765217668 }
1765317669}
0 commit comments