mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 09:18:19 +00:00
vim-patch:8.2.3889: duplicate code for translating script-local function name
Problem: Duplicate code for translating script-local function name.
Solution: Move the code to get_scriptlocal_funcname(). (Yegappan Lakshmanan,
closes vim/vim#9393)
e7f4abd38b
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
@@ -5018,18 +5018,11 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref)
|
||||
int arg_idx = 0;
|
||||
list_T *list = NULL;
|
||||
if (strncmp(s, "s:", 2) == 0 || strncmp(s, "<SID>", 5) == 0) {
|
||||
char sid_buf[25];
|
||||
int off = *s == 's' ? 2 : 5;
|
||||
|
||||
// Expand s: and <SID> into <SNR>nr_, so that the function can
|
||||
// also be called from another script. Using trans_function_name()
|
||||
// would also work, but some plugins depend on the name being
|
||||
// printable text.
|
||||
snprintf(sid_buf, sizeof(sid_buf), "<SNR>%" PRId64 "_",
|
||||
(int64_t)current_sctx.sc_sid);
|
||||
name = xmalloc(strlen(sid_buf) + strlen(s + off) + 1);
|
||||
STRCPY(name, sid_buf);
|
||||
STRCAT(name, s + off);
|
||||
name = get_scriptlocal_funcname(s);
|
||||
} else {
|
||||
name = xstrdup(s);
|
||||
}
|
||||
@@ -5538,6 +5531,14 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg)
|
||||
callback->type = kCallbackNone;
|
||||
callback->data.funcref = NULL;
|
||||
} else {
|
||||
if (arg->v_type == VAR_STRING) {
|
||||
char *newname = get_scriptlocal_funcname(arg->vval.v_string);
|
||||
if (newname != NULL) {
|
||||
xfree(arg->vval.v_string);
|
||||
name = arg->vval.v_string = newname;
|
||||
}
|
||||
}
|
||||
|
||||
func_ref((char_u *)name);
|
||||
callback->data.funcref = xstrdup(name);
|
||||
callback->type = kCallbackFuncref;
|
||||
|
Reference in New Issue
Block a user