diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2022-11-07 14:49:53 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-07 14:49:53 +0800 |
| commit | e9c1cb71f8a4d6d7818dcb5f71ac78bee431309a (patch) | |
| tree | 0ae5f982feae83a659b83e8a9272a3cab778252b /src/nvim/eval | |
| parent | b042f6d9022a4c734477f1fdbc92b4f8134661b3 (diff) | |
| parent | 2ed2c04aa518fb2591497e9a5ebe9cc32d8894a8 (diff) | |
| download | rneovim-e9c1cb71f8a4d6d7818dcb5f71ac78bee431309a.tar.gz rneovim-e9c1cb71f8a4d6d7818dcb5f71ac78bee431309a.tar.bz2 rneovim-e9c1cb71f8a4d6d7818dcb5f71ac78bee431309a.zip | |
Merge pull request #20987 from zeertzjq/vim-8.2.3751
vim-patch:8.2.{3735,3751,3756,3758,3788,3792}
Diffstat (limited to 'src/nvim/eval')
| -rw-r--r-- | src/nvim/eval/userfunc.c | 4 | ||||
| -rw-r--r-- | src/nvim/eval/vars.c | 23 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index d07cfe0bd9..cc21bf56ca 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1394,7 +1394,7 @@ func_call_skip_call: } /// call the 'callback' function and return the result as a number. -/// Returns -1 when calling the function fails. Uses argv[0] to argv[argc - 1] +/// Returns -2 when calling the function fails. Uses argv[0] to argv[argc - 1] /// for the function arguments. argv[argc] should have type VAR_UNKNOWN. /// /// @param argcount number of "argvars" @@ -1403,7 +1403,7 @@ varnumber_T callback_call_retnr(Callback *callback, int argcount, typval_T *argv { typval_T rettv; if (!callback_call(callback, argcount, argvars, &rettv)) { - return -1; + return -2; } varnumber_T retval = tv_get_number_chk(&rettv, NULL); diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 139e7ed66b..6c4d33df89 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -560,8 +560,6 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo { char *arg_end = NULL; int len; - int opt_flags; - char *tofree = NULL; // ":let $VAR = expr": Set environment variable. if (*arg == '$') { @@ -582,12 +580,12 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo && vim_strchr(endchars, *skipwhite(arg)) == NULL) { emsg(_(e_letunexp)); } else if (!check_secure()) { + char *tofree = NULL; const char c1 = name[len]; name[len] = NUL; const char *p = tv_get_string_chk(tv); if (p != NULL && op != NULL && *op == '.') { char *s = vim_getenv(name); - if (s != NULL) { tofree = concat_str(s, p); p = (const char *)tofree; @@ -611,7 +609,8 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo return NULL; } // Find the end of the name. - char *const p = (char *)find_option_end((const char **)&arg, &opt_flags); + int scope; + char *const p = (char *)find_option_end((const char **)&arg, &scope); if (p == NULL || (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL)) { @@ -623,11 +622,13 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo char *stringval = NULL; const char *s = NULL; bool failed = false; + uint32_t opt_p_flags; + char *tofree = NULL; const char c1 = *p; *p = NUL; - opt_type = get_option_value(arg, &numval, &stringval, opt_flags); + opt_type = get_option_value(arg, &numval, &stringval, &opt_p_flags, scope); if (opt_type == gov_bool || opt_type == gov_number || opt_type == gov_hidden_bool @@ -636,8 +637,13 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo n = (long)tv_get_number(tv); } - // Avoid setting a string option to the text "v:false" or similar. - if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL) { + if ((opt_p_flags & P_FUNC) && tv_is_func(*tv)) { + // If the option can be set to a function reference or a lambda + // and the passed value is a function reference, then convert it to + // the name (string) of the function reference. + s = tofree = encode_tv2string(tv, NULL); + } else if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL) { + // Avoid setting a string option to the text "v:false" or similar. s = tv_get_string_chk(tv); } @@ -674,7 +680,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo if (!failed) { if (opt_type != gov_string || s != NULL) { - char *err = set_option_value(arg, n, s, opt_flags); + char *err = set_option_value(arg, n, s, scope); arg_end = p; if (err != NULL) { emsg(_(err)); @@ -685,6 +691,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo } *p = c1; xfree(stringval); + xfree(tofree); } // ":let @r = expr": Set register contents. } else if (*arg == '@') { |