summaryrefslogtreecommitdiff
path: root/src/userfunc.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-30 21:12:27 +0100
committerBram Moolenaar <Bram@vim.org>2022-03-30 21:12:27 +0100
commitc0ceeeb839b8c6bebd3a2abd1c07d40ec3c6edca (patch)
tree2f51e084f45dbe3437520d32f83e67fb9704aa6b /src/userfunc.c
parentb4ad3b0deac12674a7773311890b48fd39c6807c (diff)
downloadvim-git-c0ceeeb839b8c6bebd3a2abd1c07d40ec3c6edca.tar.gz
patch 8.2.4650: "import autoload" only works with using 'runtimepath'v8.2.4650
Problem: "import autoload" only works with using 'runtimepath'. Solution: Also support a relative and absolute file name.
Diffstat (limited to 'src/userfunc.c')
-rw-r--r--src/userfunc.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/userfunc.c b/src/userfunc.c
index ce2ad1301..729ee89b2 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -1884,23 +1884,33 @@ fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error)
}
/*
+ * Concatenate the script ID and function name into "<SNR>99_name".
+ * "buffer" must have size MAX_FUNC_NAME_LEN.
+ */
+ void
+func_name_with_sid(char_u *name, int sid, char_u *buffer)
+{
+ // A script-local function is stored as "<SNR>99_name".
+ buffer[0] = K_SPECIAL;
+ buffer[1] = KS_EXTRA;
+ buffer[2] = (int)KE_SNR;
+ vim_snprintf((char *)buffer + 3, MAX_FUNC_NAME_LEN - 3, "%ld_%s",
+ (long)sid, name);
+}
+
+/*
* Find a function "name" in script "sid".
*/
static ufunc_T *
find_func_with_sid(char_u *name, int sid)
{
hashitem_T *hi;
- char_u buffer[200];
+ char_u buffer[MAX_FUNC_NAME_LEN];
if (!SCRIPT_ID_VALID(sid))
return NULL; // not in a script
- // A script-local function is stored as "<SNR>99_name".
- buffer[0] = K_SPECIAL;
- buffer[1] = KS_EXTRA;
- buffer[2] = (int)KE_SNR;
- vim_snprintf((char *)buffer + 3, sizeof(buffer) - 3, "%ld_%s",
- (long)sid, name);
+ func_name_with_sid(name, sid, buffer);
hi = hash_find(&func_hashtab, buffer);
if (!HASHITEM_EMPTY(hi))
return HI2UF(hi);
@@ -1914,7 +1924,7 @@ find_func_with_sid(char_u *name, int sid)
find_func_with_prefix(char_u *name, int sid)
{
hashitem_T *hi;
- char_u buffer[200];
+ char_u buffer[MAX_FUNC_NAME_LEN];
scriptitem_T *si;
if (vim_strchr(name, AUTOLOAD_CHAR) != NULL)