mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
API: nvim_source: save/restore script context #11159
Use a constant for the script id.
This commit is contained in:

committed by
Justin M. Keyes

parent
6aa03e86da
commit
0a8d145075
@@ -74,12 +74,11 @@ void api_vim_free_all_mem(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void nvim_source(String command, Error *err)
|
void nvim_source(String command, Error *err)
|
||||||
FUNC_API_SINCE(5)
|
FUNC_API_SINCE(7)
|
||||||
{
|
{
|
||||||
try_start();
|
try_start();
|
||||||
do_source_str((char_u *)command.data);
|
do_source_str((char_u *)command.data);
|
||||||
update_screen(VALID);
|
try_end(err);
|
||||||
try_end(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes an ex-command.
|
/// Executes an ex-command.
|
||||||
|
@@ -1193,7 +1193,7 @@ static void script_dump_profile(FILE *fd)
|
|||||||
/// profiled.
|
/// profiled.
|
||||||
bool prof_def_func(void)
|
bool prof_def_func(void)
|
||||||
{
|
{
|
||||||
if (current_sctx.sc_sid > 0 && current_SID < 999999) {
|
if (current_sctx.sc_sid > 0) {
|
||||||
return SCRIPT_ITEM(current_sctx.sc_sid).sn_pr_force;
|
return SCRIPT_ITEM(current_sctx.sc_sid).sn_pr_force;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -3048,9 +3048,13 @@ int do_source_str(char_u *cmd)
|
|||||||
.buf = cmd,
|
.buf = cmd,
|
||||||
.offset = 0,
|
.offset = 0,
|
||||||
};
|
};
|
||||||
current_SID = 999999;
|
const sctx_T save_current_sctx = current_sctx;
|
||||||
|
current_sctx.sc_sid = SID_STR;
|
||||||
|
current_sctx.sc_seq = 0;
|
||||||
|
current_sctx.sc_lnum = 0;
|
||||||
retval = do_cmdline(NULL, get_str_line, (void *)&cookie,
|
retval = do_cmdline(NULL, get_str_line, (void *)&cookie,
|
||||||
DOCMD_NOWAIT);
|
DOCMD_NOWAIT);
|
||||||
|
current_sctx = save_current_sctx;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -331,6 +331,7 @@ EXTERN int garbage_collect_at_exit INIT(= false);
|
|||||||
#define SID_NONE -6 // don't set scriptID
|
#define SID_NONE -6 // don't set scriptID
|
||||||
#define SID_LUA -7 // for Lua scripts/chunks
|
#define SID_LUA -7 // for Lua scripts/chunks
|
||||||
#define SID_API_CLIENT -8 // for API clients
|
#define SID_API_CLIENT -8 // for API clients
|
||||||
|
#define SID_STR -9 // for sourcing a string
|
||||||
|
|
||||||
// Script CTX being sourced or was sourced to define the current function.
|
// Script CTX being sourced or was sourced to define the current function.
|
||||||
EXTERN sctx_T current_sctx INIT(= { 0 COMMA 0 COMMA 0 });
|
EXTERN sctx_T current_sctx INIT(= { 0 COMMA 0 COMMA 0 });
|
||||||
|
Reference in New Issue
Block a user