mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
provider: Add support for python commands/functions
This uses the provider/scripting infrastructure to reintroduce python support through the msgpack-rpc API. A new 'initpython' option was added, and it must be set to a command that will bootstrap the python provider the first time it's needed.
This commit is contained in:
parent
8a091e7f5c
commit
486c8e37c1
@ -6457,6 +6457,7 @@ static struct fst {
|
||||
{"prevnonblank", 1, 1, f_prevnonblank},
|
||||
{"printf", 2, 19, f_printf},
|
||||
{"pumvisible", 0, 0, f_pumvisible},
|
||||
{"pyeval", 1, 1, f_pyeval},
|
||||
{"range", 1, 3, f_range},
|
||||
{"readfile", 1, 3, f_readfile},
|
||||
{"reltime", 0, 2, f_reltime},
|
||||
@ -11461,7 +11462,13 @@ static void f_pumvisible(typval_T *argvars, typval_T *rettv)
|
||||
rettv->vval.v_number = 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* "pyeval()" function
|
||||
*/
|
||||
static void f_pyeval(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
script_host_eval("python_eval", argvars, rettv);
|
||||
}
|
||||
|
||||
/*
|
||||
* "range()" function
|
||||
|
@ -789,6 +789,22 @@ void ex_profile(exarg_T *eap)
|
||||
}
|
||||
}
|
||||
|
||||
void ex_python(exarg_T *eap)
|
||||
{
|
||||
script_host_execute("python_execute", eap);
|
||||
}
|
||||
|
||||
void ex_pyfile(exarg_T *eap)
|
||||
{
|
||||
script_host_execute_file("python_execute_file", eap);
|
||||
}
|
||||
|
||||
void ex_pydo(exarg_T *eap)
|
||||
{
|
||||
script_host_do_range("python_do_range", eap);
|
||||
}
|
||||
|
||||
|
||||
/* Command line expansion for :profile. */
|
||||
static enum {
|
||||
PEXP_SUBCMD, /* expand :profile sub-commands */
|
||||
|
@ -737,6 +737,12 @@ enum CMD_index
|
||||
RANGE|WHOLEFOLD|BANG|REGSTR|TRLBAR|ZEROR|CMDWIN|MODIFY),
|
||||
EX(CMD_pwd, "pwd", ex_pwd,
|
||||
TRLBAR|CMDWIN),
|
||||
EX(CMD_python, "python", ex_python,
|
||||
RANGE|EXTRA|NEEDARG|CMDWIN),
|
||||
EX(CMD_pydo, "pydo", ex_pydo,
|
||||
RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN),
|
||||
EX(CMD_pyfile, "pyfile", ex_pyfile,
|
||||
RANGE|FILE1|NEEDARG|CMDWIN),
|
||||
EX(CMD_quit, "quit", ex_quit,
|
||||
BANG|TRLBAR|CMDWIN),
|
||||
EX(CMD_quitall, "quitall", ex_quit_all,
|
||||
|
@ -1859,6 +1859,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
|
||||
case CMD_noautocmd:
|
||||
case CMD_noswapfile:
|
||||
case CMD_psearch:
|
||||
case CMD_python:
|
||||
case CMD_return:
|
||||
case CMD_rightbelow:
|
||||
case CMD_silent:
|
||||
|
@ -963,6 +963,9 @@ static struct vimoption
|
||||
{"infercase", "inf", P_BOOL|P_VI_DEF,
|
||||
(char_u *)&p_inf, PV_INF,
|
||||
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
|
||||
{"initpython","ipy",P_STRING|P_VI_DEF|P_SECURE,
|
||||
(char_u *)&p_ipy, PV_NONE,
|
||||
{(char_u *)NULL, (char_u *)0L} SCRIPTID_INIT},
|
||||
{"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
|
||||
(char_u *)&p_im, PV_NONE,
|
||||
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
|
||||
|
@ -630,6 +630,7 @@ EXTERN int p_write; /* 'write' */
|
||||
EXTERN int p_wa; /* 'writeany' */
|
||||
EXTERN int p_wb; /* 'writebackup' */
|
||||
EXTERN long p_wd; /* 'writedelay' */
|
||||
EXTERN char *p_ipy; // 'initpython'
|
||||
|
||||
/*
|
||||
* "indir" values for buffer-local opions.
|
||||
|
@ -31,6 +31,12 @@ static struct feature {
|
||||
size_t name_length;
|
||||
uint64_t channel_id;
|
||||
} features[] = {
|
||||
FEATURE("python",
|
||||
&p_ipy,
|
||||
"python_execute",
|
||||
"python_execute_file",
|
||||
"python_do_range",
|
||||
"python_eval")
|
||||
};
|
||||
|
||||
static Map(cstr_t, uint64_t) *registered_providers = NULL;
|
||||
|
@ -9,7 +9,7 @@ STARTTEST
|
||||
:so small.vim
|
||||
:set encoding=latin1
|
||||
:set noswapfile
|
||||
:if !has('python') | e! test.ok | wq! test.out | endif
|
||||
:if !has('python') || has('neovim') | e! test.ok | wq! test.out | endif
|
||||
:lang C
|
||||
:fun Test()
|
||||
:py import vim
|
||||
|
Loading…
Reference in New Issue
Block a user