Mercurial > vim
comparison src/evalvars.c @ 19834:2ef25a007bb7 v8.2.0473
patch 8.2.0473: variables declared in an outer scope
Commit: https://github.com/vim/vim/commit/8601545338581c01e328cdc3a72c0b12d92c54cf
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 29 15:12:15 2020 +0200
patch 8.2.0473: variables declared in an outer scope
Problem: Variables declared in an outer scope.
Solution: Decleare variables only in the scope where they are used.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 29 Mar 2020 15:15:04 +0200 |
parents | fe827d6267c2 |
children | 37c4779ca8f5 |
comparison
equal
deleted
inserted
replaced
19833:7f50fd15954b | 19834:2ef25a007bb7 |
---|---|
3459 */ | 3459 */ |
3460 void | 3460 void |
3461 f_getbufvar(typval_T *argvars, typval_T *rettv) | 3461 f_getbufvar(typval_T *argvars, typval_T *rettv) |
3462 { | 3462 { |
3463 buf_T *buf; | 3463 buf_T *buf; |
3464 buf_T *save_curbuf; | |
3465 char_u *varname; | 3464 char_u *varname; |
3466 dictitem_T *v; | 3465 dictitem_T *v; |
3467 int done = FALSE; | 3466 int done = FALSE; |
3468 | 3467 |
3469 (void)tv_get_number(&argvars[0]); // issue errmsg if type error | 3468 (void)tv_get_number(&argvars[0]); // issue errmsg if type error |
3474 rettv->v_type = VAR_STRING; | 3473 rettv->v_type = VAR_STRING; |
3475 rettv->vval.v_string = NULL; | 3474 rettv->vval.v_string = NULL; |
3476 | 3475 |
3477 if (buf != NULL && varname != NULL) | 3476 if (buf != NULL && varname != NULL) |
3478 { | 3477 { |
3479 // set curbuf to be our buf, temporarily | |
3480 save_curbuf = curbuf; | |
3481 curbuf = buf; | |
3482 | |
3483 if (*varname == '&') | 3478 if (*varname == '&') |
3484 { | 3479 { |
3480 buf_T *save_curbuf = curbuf; | |
3481 | |
3482 // set curbuf to be our buf, temporarily | |
3483 curbuf = buf; | |
3484 | |
3485 if (varname[1] == NUL) | 3485 if (varname[1] == NUL) |
3486 { | 3486 { |
3487 // get all buffer-local options in a dict | 3487 // get all buffer-local options in a dict |
3488 dict_T *opts = get_winbuf_options(TRUE); | 3488 dict_T *opts = get_winbuf_options(TRUE); |
3489 | 3489 |
3494 } | 3494 } |
3495 } | 3495 } |
3496 else if (get_option_tv(&varname, rettv, TRUE) == OK) | 3496 else if (get_option_tv(&varname, rettv, TRUE) == OK) |
3497 // buffer-local-option | 3497 // buffer-local-option |
3498 done = TRUE; | 3498 done = TRUE; |
3499 | |
3500 // restore previous notion of curbuf | |
3501 curbuf = save_curbuf; | |
3499 } | 3502 } |
3500 else | 3503 else |
3501 { | 3504 { |
3502 // Look up the variable. | 3505 // Look up the variable. |
3503 // Let getbufvar({nr}, "") return the "b:" dictionary. | 3506 // Let getbufvar({nr}, "") return the "b:" dictionary. |
3504 v = find_var_in_ht(&curbuf->b_vars->dv_hashtab, | 3507 v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b', varname, FALSE); |
3505 'b', varname, FALSE); | |
3506 if (v != NULL) | 3508 if (v != NULL) |
3507 { | 3509 { |
3508 copy_tv(&v->di_tv, rettv); | 3510 copy_tv(&v->di_tv, rettv); |
3509 done = TRUE; | 3511 done = TRUE; |
3510 } | 3512 } |
3511 } | 3513 } |
3512 | |
3513 // restore previous notion of curbuf | |
3514 curbuf = save_curbuf; | |
3515 } | 3514 } |
3516 | 3515 |
3517 if (!done && argvars[2].v_type != VAR_UNKNOWN) | 3516 if (!done && argvars[2].v_type != VAR_UNKNOWN) |
3518 // use the default value | 3517 // use the default value |
3519 copy_tv(&argvars[2], rettv); | 3518 copy_tv(&argvars[2], rettv); |
3616 // reset notion of buffer | 3615 // reset notion of buffer |
3617 aucmd_restbuf(&aco); | 3616 aucmd_restbuf(&aco); |
3618 } | 3617 } |
3619 else | 3618 else |
3620 { | 3619 { |
3621 buf_T *save_curbuf = curbuf; | |
3622 | |
3623 bufvarname = alloc(STRLEN(varname) + 3); | 3620 bufvarname = alloc(STRLEN(varname) + 3); |
3624 if (bufvarname != NULL) | 3621 if (bufvarname != NULL) |
3625 { | 3622 { |
3623 buf_T *save_curbuf = curbuf; | |
3624 | |
3626 curbuf = buf; | 3625 curbuf = buf; |
3627 STRCPY(bufvarname, "b:"); | 3626 STRCPY(bufvarname, "b:"); |
3628 STRCPY(bufvarname + 2, varname); | 3627 STRCPY(bufvarname + 2, varname); |
3629 set_var(bufvarname, varp, TRUE); | 3628 set_var(bufvarname, varp, TRUE); |
3630 vim_free(bufvarname); | 3629 vim_free(bufvarname); |