mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
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 #9393)
This commit is contained in:
committed by
Bram Moolenaar
parent
73a024209c
commit
e7f4abd38b
@@ -3875,6 +3875,46 @@ untrans_function_name(char_u *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the 'funcname' starts with "s:" or "<SID>", then expands it to the
|
||||
* current script ID and returns the expanded function name. The caller should
|
||||
* free the returned name. If not called from a script context or the function
|
||||
* name doesn't start with these prefixes, then returns NULL.
|
||||
* This doesn't check whether the script-local function exists or not.
|
||||
*/
|
||||
char_u *
|
||||
get_scriptlocal_funcname(char_u *funcname)
|
||||
{
|
||||
char sid_buf[25];
|
||||
int off;
|
||||
char_u *newname;
|
||||
|
||||
if (funcname == NULL)
|
||||
return NULL;
|
||||
|
||||
if (STRNCMP(funcname, "s:", 2) != 0
|
||||
&& STRNCMP(funcname, "<SID>", 5) != 0)
|
||||
// The function name is not a script-local function name
|
||||
return NULL;
|
||||
|
||||
if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
|
||||
{
|
||||
emsg(_(e_using_sid_not_in_script_context));
|
||||
return NULL;
|
||||
}
|
||||
// Expand s: prefix into <SNR>nr_<name>
|
||||
vim_snprintf(sid_buf, sizeof(sid_buf), "<SNR>%ld_",
|
||||
(long)current_sctx.sc_sid);
|
||||
off = *funcname == 's' ? 2 : 5;
|
||||
newname = alloc(STRLEN(sid_buf) + STRLEN(funcname + off) + 1);
|
||||
if (newname == NULL)
|
||||
return NULL;
|
||||
STRCPY(newname, sid_buf);
|
||||
STRCAT(newname, funcname + off);
|
||||
|
||||
return newname;
|
||||
}
|
||||
|
||||
/*
|
||||
* Call trans_function_name(), except that a lambda is returned as-is.
|
||||
* Returns the name in allocated memory.
|
||||
|
Reference in New Issue
Block a user