Mercurial > vim
comparison src/eval.c @ 6222:63121fdd093f v7.4.446
updated for version 7.4.446
Problem: In some situations, when setting up an environment to trigger an
autocommand, the environment is not properly restored.
Solution: Check the return value of switch_win() and call restore_win()
always. (Daniel Hahler)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 19 Sep 2014 14:26:36 +0200 |
parents | 8c3c067b4ae3 |
children | ac6cfdc02695 |
comparison
equal
deleted
inserted
replaced
6221:f3c980ab39a3 | 6222:63121fdd093f |
---|---|
12084 tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL)); | 12084 tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL)); |
12085 if (tp != NULL && varname != NULL) | 12085 if (tp != NULL && varname != NULL) |
12086 { | 12086 { |
12087 /* Set tp to be our tabpage, temporarily. Also set the window to the | 12087 /* Set tp to be our tabpage, temporarily. Also set the window to the |
12088 * first window in the tabpage, otherwise the window is not valid. */ | 12088 * first window in the tabpage, otherwise the window is not valid. */ |
12089 switch_win(&oldcurwin, &oldtabpage, tp->tp_firstwin, tp, TRUE); | 12089 if (switch_win(&oldcurwin, &oldtabpage, tp->tp_firstwin, tp, TRUE) |
12090 | 12090 == OK) |
12091 /* look up the variable */ | 12091 { |
12092 /* Let gettabvar({nr}, "") return the "t:" dictionary. */ | 12092 /* look up the variable */ |
12093 v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE); | 12093 /* Let gettabvar({nr}, "") return the "t:" dictionary. */ |
12094 if (v != NULL) | 12094 v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE); |
12095 { | 12095 if (v != NULL) |
12096 copy_tv(&v->di_tv, rettv); | 12096 { |
12097 done = TRUE; | 12097 copy_tv(&v->di_tv, rettv); |
12098 done = TRUE; | |
12099 } | |
12098 } | 12100 } |
12099 | 12101 |
12100 /* restore previous notion of curwin */ | 12102 /* restore previous notion of curwin */ |
12101 restore_win(oldcurwin, oldtabpage, TRUE); | 12103 restore_win(oldcurwin, oldtabpage, TRUE); |
12102 } | 12104 } |
12231 | 12233 |
12232 if (win != NULL && varname != NULL) | 12234 if (win != NULL && varname != NULL) |
12233 { | 12235 { |
12234 /* Set curwin to be our win, temporarily. Also set the tabpage, | 12236 /* Set curwin to be our win, temporarily. Also set the tabpage, |
12235 * otherwise the window is not valid. */ | 12237 * otherwise the window is not valid. */ |
12236 switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE); | 12238 if (switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK) |
12237 | 12239 { |
12238 if (*varname == '&') /* window-local-option */ | 12240 if (*varname == '&') /* window-local-option */ |
12239 { | |
12240 if (get_option_tv(&varname, rettv, 1) == OK) | |
12241 done = TRUE; | |
12242 } | |
12243 else | |
12244 { | |
12245 /* Look up the variable. */ | |
12246 /* Let getwinvar({nr}, "") return the "w:" dictionary. */ | |
12247 v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w', varname, FALSE); | |
12248 if (v != NULL) | |
12249 { | 12241 { |
12250 copy_tv(&v->di_tv, rettv); | 12242 if (get_option_tv(&varname, rettv, 1) == OK) |
12251 done = TRUE; | 12243 done = TRUE; |
12244 } | |
12245 else | |
12246 { | |
12247 /* Look up the variable. */ | |
12248 /* Let getwinvar({nr}, "") return the "w:" dictionary. */ | |
12249 v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w', | |
12250 varname, FALSE); | |
12251 if (v != NULL) | |
12252 { | |
12253 copy_tv(&v->di_tv, rettv); | |
12254 done = TRUE; | |
12255 } | |
12252 } | 12256 } |
12253 } | 12257 } |
12254 | 12258 |
12255 /* restore previous notion of curwin */ | 12259 /* restore previous notion of curwin */ |
12256 restore_win(oldcurwin, oldtabpage, TRUE); | 12260 restore_win(oldcurwin, oldtabpage, TRUE); |
17250 varp = &argvars[off + 2]; | 17254 varp = &argvars[off + 2]; |
17251 | 17255 |
17252 if (win != NULL && varname != NULL && varp != NULL) | 17256 if (win != NULL && varname != NULL && varp != NULL) |
17253 { | 17257 { |
17254 #ifdef FEAT_WINDOWS | 17258 #ifdef FEAT_WINDOWS |
17255 if (switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == FAIL) | 17259 if (switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK) |
17256 return; | 17260 #endif |
17257 #endif | 17261 { |
17258 | 17262 if (*varname == '&') |
17259 if (*varname == '&') | |
17260 { | |
17261 long numval; | |
17262 char_u *strval; | |
17263 int error = FALSE; | |
17264 | |
17265 ++varname; | |
17266 numval = get_tv_number_chk(varp, &error); | |
17267 strval = get_tv_string_buf_chk(varp, nbuf); | |
17268 if (!error && strval != NULL) | |
17269 set_option_value(varname, numval, strval, OPT_LOCAL); | |
17270 } | |
17271 else | |
17272 { | |
17273 winvarname = alloc((unsigned)STRLEN(varname) + 3); | |
17274 if (winvarname != NULL) | |
17275 { | 17263 { |
17276 STRCPY(winvarname, "w:"); | 17264 long numval; |
17277 STRCPY(winvarname + 2, varname); | 17265 char_u *strval; |
17278 set_var(winvarname, varp, TRUE); | 17266 int error = FALSE; |
17279 vim_free(winvarname); | 17267 |
17268 ++varname; | |
17269 numval = get_tv_number_chk(varp, &error); | |
17270 strval = get_tv_string_buf_chk(varp, nbuf); | |
17271 if (!error && strval != NULL) | |
17272 set_option_value(varname, numval, strval, OPT_LOCAL); | |
17280 } | 17273 } |
17281 } | 17274 else |
17282 | 17275 { |
17276 winvarname = alloc((unsigned)STRLEN(varname) + 3); | |
17277 if (winvarname != NULL) | |
17278 { | |
17279 STRCPY(winvarname, "w:"); | |
17280 STRCPY(winvarname + 2, varname); | |
17281 set_var(winvarname, varp, TRUE); | |
17282 vim_free(winvarname); | |
17283 } | |
17284 } | |
17285 } | |
17283 #ifdef FEAT_WINDOWS | 17286 #ifdef FEAT_WINDOWS |
17284 restore_win(save_curwin, save_curtab, TRUE); | 17287 restore_win(save_curwin, save_curtab, TRUE); |
17285 #endif | 17288 #endif |
17286 } | 17289 } |
17287 } | 17290 } |