0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.4650: "import autoload" only works with using 'runtimepath'

Problem:    "import autoload" only works with using 'runtimepath'.
Solution:   Also support a relative and absolute file name.
This commit is contained in:
Bram Moolenaar
2022-03-30 21:12:27 +01:00
parent b4ad3b0dea
commit c0ceeeb839
15 changed files with 442 additions and 82 deletions

View File

@@ -1510,6 +1510,13 @@ get_script_svar(scriptref_T *sref, int dfunc_idx)
emsg(_(e_script_variable_type_changed));
return NULL;
}
if (!sv->sv_export && sref->sref_sid != current_sctx.sc_sid)
{
if (dfunc != NULL)
semsg(_(e_item_not_exported_in_script_str), sv->sv_name);
return NULL;
}
return sv;
}
@@ -2623,6 +2630,20 @@ exec_instructions(ectx_T *ectx)
}
break;
case ISN_SOURCE:
{
scriptitem_T *si = SCRIPT_ITEM(iptr->isn_arg.number);
if (si->sn_state == SN_STATE_NOT_LOADED)
{
SOURCING_LNUM = iptr->isn_lnum;
if (do_source(si->sn_name, FALSE, DOSO_NONE, NULL)
== FAIL)
goto on_error;
}
}
break;
// execute :substitute with an expression
case ISN_SUBSTITUTE:
{
@@ -2902,11 +2923,12 @@ exec_instructions(ectx_T *ectx)
}
break;
// load s: variable in old script
// load s: variable in old script or autoload import
case ISN_LOADS:
case ISN_LOADEXPORT:
{
hashtab_T *ht = &SCRIPT_VARS(
iptr->isn_arg.loadstore.ls_sid);
int sid = iptr->isn_arg.loadstore.ls_sid;
hashtab_T *ht = &SCRIPT_VARS(sid);
char_u *name = iptr->isn_arg.loadstore.ls_name;
dictitem_T *di = find_var_in_ht(ht, 0, name, TRUE);
@@ -2918,6 +2940,25 @@ exec_instructions(ectx_T *ectx)
}
else
{
if (iptr->isn_type == ISN_LOADEXPORT)
{
int idx = get_script_item_idx(sid, name, 0,
NULL, NULL);
svar_T *sv;
if (idx >= 0)
{
sv = ((svar_T *)SCRIPT_ITEM(sid)
->sn_var_vals.ga_data) + idx;
if (!sv->sv_export)
{
SOURCING_LNUM = iptr->isn_lnum;
semsg(_(e_item_not_exported_in_script_str),
name);
goto on_error;
}
}
}
if (GA_GROW_FAILS(&ectx->ec_stack, 1))
goto theend;
copy_tv(&di->di_tv, STACK_TV_BOT(0));
@@ -3039,20 +3080,48 @@ exec_instructions(ectx_T *ectx)
*tv = *STACK_TV_BOT(0);
break;
// store s: variable in old script
// store s: variable in old script or autoload import
case ISN_STORES:
case ISN_STOREEXPORT:
{
hashtab_T *ht = &SCRIPT_VARS(
iptr->isn_arg.loadstore.ls_sid);
int sid = iptr->isn_arg.loadstore.ls_sid;
hashtab_T *ht = &SCRIPT_VARS(sid);
char_u *name = iptr->isn_arg.loadstore.ls_name;
dictitem_T *di = find_var_in_ht(ht, 0, name + 2, TRUE);
dictitem_T *di = find_var_in_ht(ht, 0,
iptr->isn_type == ISN_STORES
? name + 2 : name, TRUE);
--ectx->ec_stack.ga_len;
SOURCING_LNUM = iptr->isn_lnum;
if (di == NULL)
{
if (iptr->isn_type == ISN_STOREEXPORT)
{
semsg(_(e_undefined_variable_str), name);
goto on_error;
}
store_var(name, STACK_TV_BOT(0));
}
else
{
SOURCING_LNUM = iptr->isn_lnum;
if (iptr->isn_type == ISN_STOREEXPORT)
{
int idx = get_script_item_idx(sid, name, 0,
NULL, NULL);
if (idx >= 0)
{
svar_T *sv = ((svar_T *)SCRIPT_ITEM(sid)
->sn_var_vals.ga_data) + idx;
if (!sv->sv_export)
{
semsg(_(e_item_not_exported_in_script_str),
name);
goto on_error;
}
}
}
if (var_check_permission(di, name) == FAIL)
{
clear_tv(STACK_TV_BOT(0));
@@ -5409,11 +5478,15 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
#endif
break;
case ISN_INSTR:
smsg("%s%4d INSTR", pfx, current);
list_instructions(" ", iptr->isn_arg.instr, INT_MAX, NULL);
msg(" -------------");
break;
case ISN_SOURCE:
{
smsg("%s%4d INSTR", pfx, current);
list_instructions(" ", iptr->isn_arg.instr,
INT_MAX, NULL);
msg(" -------------");
scriptitem_T *si = SCRIPT_ITEM(iptr->isn_arg.number);
smsg("%s%4d SOURCE %s", pfx, current, si->sn_name);
}
break;
case ISN_SUBSTITUTE:
@@ -5500,12 +5573,15 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
}
break;
case ISN_LOADS:
case ISN_LOADEXPORT:
{
scriptitem_T *si = SCRIPT_ITEM(
iptr->isn_arg.loadstore.ls_sid);
smsg("%s%4d LOADS s:%s from %s", pfx, current,
iptr->isn_arg.loadstore.ls_name, si->sn_name);
smsg("%s%4d %s s:%s from %s", pfx, current,
iptr->isn_type == ISN_LOADS ? "LOADS"
: "LOADEXPORT",
iptr->isn_arg.loadstore.ls_name, si->sn_name);
}
break;
case ISN_LOADAUTO:
@@ -5586,11 +5662,14 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
smsg("%s%4d STORET %s", pfx, current, iptr->isn_arg.string);
break;
case ISN_STORES:
case ISN_STOREEXPORT:
{
scriptitem_T *si = SCRIPT_ITEM(
iptr->isn_arg.loadstore.ls_sid);
smsg("%s%4d STORES %s in %s", pfx, current,
smsg("%s%4d %s %s in %s", pfx, current,
iptr->isn_type == ISN_STORES
? "STORES" : "STOREEXPORT",
iptr->isn_arg.loadstore.ls_name, si->sn_name);
}
break;