comparison src/eval.c @ 4429:7eafa576528e v7.3.963

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.
author Bram Moolenaar <bram@vim.org>
date Fri, 17 May 2013 16:03:57 +0200
parents a84f21892563
children 21a99611149b
comparison
equal deleted inserted replaced
4428:f1ecf16fe9fc 4429:7eafa576528e
11892 int off; /* 1 for gettabwinvar() */ 11892 int off; /* 1 for gettabwinvar() */
11893 { 11893 {
11894 win_T *win, *oldcurwin; 11894 win_T *win, *oldcurwin;
11895 char_u *varname; 11895 char_u *varname;
11896 dictitem_T *v; 11896 dictitem_T *v;
11897 tabpage_T *tp; 11897 tabpage_T *tp, *oldtabpage;
11898 int done = FALSE; 11898 int done = FALSE;
11899 11899
11900 #ifdef FEAT_WINDOWS 11900 #ifdef FEAT_WINDOWS
11901 if (off == 1) 11901 if (off == 1)
11902 tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL)); 11902 tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL));
11910 rettv->v_type = VAR_STRING; 11910 rettv->v_type = VAR_STRING;
11911 rettv->vval.v_string = NULL; 11911 rettv->vval.v_string = NULL;
11912 11912
11913 if (win != NULL && varname != NULL) 11913 if (win != NULL && varname != NULL)
11914 { 11914 {
11915 /* Set curwin to be our win, temporarily. Also set curbuf, so 11915 /* Set curwin to be our win, temporarily. Also set the tabpage,
11916 * that we can get buffer-local options. */ 11916 * otherwise the window is not valid. */
11917 oldcurwin = curwin; 11917 switch_win(&oldcurwin, &oldtabpage, win, tp);
11918 curwin = win;
11919 curbuf = win->w_buffer;
11920 11918
11921 if (*varname == '&') /* window-local-option */ 11919 if (*varname == '&') /* window-local-option */
11922 { 11920 {
11923 if (get_option_tv(&varname, rettv, 1) == OK) 11921 if (get_option_tv(&varname, rettv, 1) == OK)
11924 done = TRUE; 11922 done = TRUE;
11934 done = TRUE; 11932 done = TRUE;
11935 } 11933 }
11936 } 11934 }
11937 11935
11938 /* restore previous notion of curwin */ 11936 /* restore previous notion of curwin */
11939 curwin = oldcurwin; 11937 restore_win(oldcurwin, oldtabpage);
11940 curbuf = curwin->w_buffer;
11941 } 11938 }
11942 11939
11943 if (!done && argvars[off + 2].v_type != VAR_UNKNOWN) 11940 if (!done && argvars[off + 2].v_type != VAR_UNKNOWN)
11944 /* use the default return value */ 11941 /* use the default return value */
11945 copy_tv(&argvars[off + 2], rettv); 11942 copy_tv(&argvars[off + 2], rettv);
16637 f_setwinvar(argvars, rettv) 16634 f_setwinvar(argvars, rettv)
16638 typval_T *argvars; 16635 typval_T *argvars;
16639 typval_T *rettv; 16636 typval_T *rettv;
16640 { 16637 {
16641 setwinvar(argvars, rettv, 0); 16638 setwinvar(argvars, rettv, 0);
16642 }
16643
16644 int
16645 switch_win(save_curwin, save_curtab, win, tp)
16646 win_T **save_curwin;
16647 tabpage_T **save_curtab;
16648 win_T *win;
16649 tabpage_T *tp;
16650 {
16651 #ifdef FEAT_WINDOWS
16652 /* set curwin to be our win, temporarily */
16653 *save_curwin = curwin;
16654 *save_curtab = curtab;
16655 goto_tabpage_tp(tp, FALSE, FALSE);
16656 if (!win_valid(win))
16657 return FAIL;
16658 curwin = win;
16659 curbuf = curwin->w_buffer;
16660 #endif
16661 return OK;
16662 }
16663
16664 void
16665 restore_win(save_curwin, save_curtab)
16666 win_T *save_curwin;
16667 tabpage_T *save_curtab;
16668 {
16669 #ifdef FEAT_WINDOWS
16670 /* Restore current tabpage and window, if still valid (autocommands can
16671 * make them invalid). */
16672 if (valid_tabpage(save_curtab))
16673 goto_tabpage_tp(save_curtab, FALSE, FALSE);
16674 if (win_valid(save_curwin))
16675 {
16676 curwin = save_curwin;
16677 curbuf = curwin->w_buffer;
16678 }
16679 #endif
16680 } 16639 }
16681 16640
16682 /* 16641 /*
16683 * "setwinvar()" and "settabwinvar()" functions 16642 * "setwinvar()" and "settabwinvar()" functions
16684 */ 16643 */