Skip to content

Commit 3f86eb0

Browse files
committed
Update README.md
1 parent cbfb3f9 commit 3f86eb0

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,81 @@ Library for scripting Nvim processes through its msgpack-rpc API.
1212
pip install neovim
1313
```
1414

15+
You can install the package without being root by adding the `--user` flag. You can use `pip2` and `pip3` to explicitly install for python2 and python3, respectively.
16+
17+
#### Python Plugin API
18+
19+
Neovim has a new mechanism for defining plugins, as well as a number of extensions to the python API. The API extensions are accessible no matter if the traditional `:python` interface or the new mechanism is used, as discussed below.
20+
21+
* `vim.funcs` exposes vimscript functions (both builtin and global user defined functions) as a python namespace. For instance to set the value of the value of a register
22+
23+
`vim.funcs.setreg('0', ["some", "text"], 'l')`
24+
25+
* The API is not thread-safe in general. However, `vim.async_call` allows a spawned thread to schedule code to be executed on the main thread. This method could also be called from `:python` or a synchronous request handler, to defer some execution that shouldn't block nvim.
26+
27+
`:python vim.async_call(myfunc, args...)`
28+
29+
Note that this code will still block the plugin host if it does long-running computations. Intensive computations should be done in a separate thread (or process), and `vim.async_call` can be used to send results back to nvim.
30+
31+
* Some methods accept an extra keyword-only argument `async`: `vim.eval`, `vim.command` as well as the `vim.funcs` wrappers. The python host will not wait for nvim to complete the request, which also means that the return value is unavailable.
32+
33+
#### Remote (new-style) plugins
34+
35+
Neovim allows python plugins to be defined by placing python files or packages in `rplugin/python3/` (in a runtimepath folder). These follow the structure of this example:
36+
```python
37+
import neovim
38+
39+
@neovim.plugin
40+
class TestPlugin(object):
41+
42+
def __init__(self, nvim):
43+
self.nvim = nvim
44+
45+
@neovim.function("TestFunction", sync=True)
46+
def testfunction(self, args):
47+
return 3
48+
49+
@neovim.command("TestCommand", range='', nargs='*')
50+
def testcommand(self, args, range):
51+
self.nvim.current.line = ('Command with args: {}, range: {}'
52+
.format(args, range))
53+
54+
@neovim.autocmd('BufEnter', pattern='*.py', eval='expand("<afile>")', sync=True)
55+
def on_bufenter(self, filename):
56+
self.nvim.out_write("testplugin is in " + filename + "\n")
57+
```
58+
59+
If `sync=True` is supplied nvim will wait for the handler to finish (this is required for function return values),
60+
but by default handlers are executed asynchronously.
61+
62+
You need to run `:UpdateRemotePlugins` in nvim for changes in the specifications to have effect. For details see `:help remote-plugin` in nvim.
63+
64+
#### Development
65+
66+
Install the master version by cloning this repository and in the root folder execute
67+
68+
```sh
69+
pip install .
70+
```
71+
72+
You need to rerun this command if you have changed the code, in order for nvim to use it for the plugin host.
73+
74+
To run the tests execute
75+
76+
```sh
77+
NVIM_CHILD_ARGV='["nvim", "-u", "NONE", "--embed"]' nosetests
78+
```
79+
80+
Alternatively, if you want to see the state of nvim, you could
81+
82+
```sh
83+
export NVIM_LISTEN_ADDRESS=/tmp/nvimtest
84+
xterm -e "nvim -u NONE"&
85+
nosetests
86+
```
87+
88+
But note you need to restart nvim every time you run the tests! Substitute your favorite terminal emulator for `xterm`.
89+
1590
#### Usage through the python REPL
1691

1792
A number of different transports are supported, but the simplest way to get

0 commit comments

Comments
 (0)