diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-06-26 18:27:01 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-07-17 11:37:41 -0300 |
commit | 486c8e37c17e4aa89fa9ef7e0c682b659a5a8a82 (patch) | |
tree | 08768b45ebf42eb2c0594cc3d506672213eb3201 | |
parent | 8a091e7f5c58a27fb3af1de76284430e812c95b5 (diff) | |
download | rneovim-486c8e37c17e4aa89fa9ef7e0c682b659a5a8a82.tar.gz rneovim-486c8e37c17e4aa89fa9ef7e0c682b659a5a8a82.tar.bz2 rneovim-486c8e37c17e4aa89fa9ef7e0c682b659a5a8a82.zip |
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.
-rw-r--r-- | src/nvim/eval.c | 9 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 16 | ||||
-rw-r--r-- | src/nvim/ex_cmds_defs.h | 6 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 1 | ||||
-rw-r--r-- | src/nvim/option.c | 3 | ||||
-rw-r--r-- | src/nvim/option_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/os/provider.c | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test86.in | 2 |
8 files changed, 42 insertions, 2 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 8eb4fa90d6..e72dd60dcf 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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 diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 3440616310..7371ada9b8 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -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 */ diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index 4eafa46c10..52e8bb7465 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -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, diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index a82623691e..3eb9d1277e 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -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: diff --git a/src/nvim/option.c b/src/nvim/option.c index b80f014441..5b3f0d5612 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -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}, diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 95db55a164..401cf3d200 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -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. diff --git a/src/nvim/os/provider.c b/src/nvim/os/provider.c index 967314eee4..9bd1c82569 100644 --- a/src/nvim/os/provider.c +++ b/src/nvim/os/provider.c @@ -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; diff --git a/src/nvim/testdir/test86.in b/src/nvim/testdir/test86.in index 240e07e477..ecb06bafd3 100644 --- a/src/nvim/testdir/test86.in +++ b/src/nvim/testdir/test86.in @@ -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 |