mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
API: nvim_source
This commit is contained in:

committed by
Justin M. Keyes

parent
70b6061666
commit
6aa03e86da
@@ -1193,7 +1193,7 @@ static void script_dump_profile(FILE *fd)
|
||||
/// profiled.
|
||||
bool prof_def_func(void)
|
||||
{
|
||||
if (current_sctx.sc_sid > 0) {
|
||||
if (current_sctx.sc_sid > 0 && current_SID < 999999) {
|
||||
return SCRIPT_ITEM(current_sctx.sc_sid).sn_pr_force;
|
||||
}
|
||||
return false;
|
||||
@@ -3015,6 +3015,44 @@ static FILE *fopen_noinh_readbin(char *filename)
|
||||
return fdopen(fd_tmp, READBIN);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char_u *buf;
|
||||
size_t offset;
|
||||
} GetStrLineCookie;
|
||||
|
||||
static char_u *get_str_line(int c, void *cookie, int ident)
|
||||
{
|
||||
GetStrLineCookie *p = cookie;
|
||||
size_t i = p->offset;
|
||||
if (strlen((char *)p->buf) <= p->offset) {
|
||||
return NULL;
|
||||
}
|
||||
while (!(p->buf[i] == '\n' || p->buf[i] == '\0')) {
|
||||
i++;
|
||||
}
|
||||
char buf[2046];
|
||||
char *dst;
|
||||
dst = xstpncpy(buf, (char *)p->buf+p->offset, i - p->offset);
|
||||
if ((uint32_t)(dst - buf) != i - p->offset) {
|
||||
smsg(_("nvim_source error parsing command %s"), p->buf);
|
||||
}
|
||||
buf[i-p->offset]='\0';
|
||||
p->offset = i + 1;
|
||||
return (char_u *)xstrdup(buf);
|
||||
}
|
||||
|
||||
int do_source_str(char_u *cmd)
|
||||
{
|
||||
int retval;
|
||||
GetStrLineCookie cookie = {
|
||||
.buf = cmd,
|
||||
.offset = 0,
|
||||
};
|
||||
current_SID = 999999;
|
||||
retval = do_cmdline(NULL, get_str_line, (void *)&cookie,
|
||||
DOCMD_NOWAIT);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// Read the file "fname" and execute its lines as EX commands.
|
||||
///
|
||||
|
Reference in New Issue
Block a user