New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lua integration (and update_highlights as an useful example) #325
Conversation
neovim/api/nvim.py
Outdated
@@ -115,6 +139,12 @@ def _to_nvim(self, obj): | |||
return ExtType(*obj.code_data) | |||
return obj | |||
|
|||
def _get_lua_helpers(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about _get_private_lua
or _get_lua_wrapper
or just _get_lua
. And doc like this:
"""
Returns a wrapper to a private Lua module associated with this python client, providing these functions:
...
"""
The word "helpers" needs to go away in all of our projects, it is useless and seems to proliferate as soon as it's used once.
neovim/api/buffer.py
Outdated
""" | ||
if clear and clear_start is None: | ||
clear_start = 0 | ||
helpers = self._session._get_lua_helpers() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lua = self._session._get_lua()
Now without |
5297334
to
f07190a
Compare
Updated with tests. Also use only |
LGTM. Will the docs autogenerate? I think it's cool enough to be mentioned in the README.md too. |
readthedocs has a "master" channel that should update on push to master. I plan to do a release very soon after this, so plugins can prepare for 3.7 (and use this), the release after that (coordinated with nvim 0.3?) will do the formal rename. |
Merged. I will update docs for next release in separate PR. |
This release adds support for Python 3.7 which now is in beta. `async` is a keyword in python3.7, and it should be replaced with `async_` when used as a keyword argument to API methods. `async` is still supported with python 2.7 and 3.6 for the moment, but considered deprecated. Also, integration with the in-process lua interpreter in Nvim is now supported. Changes since 0.2.4: * debcde0 clean up remote object implementation (#313) * e880fe7 Guidelines for local plugin development (#317) * 1ab98e8 Update the working directory on DirChanged for legacy plugins (#296) * d53415d Fix SyntaxError in py3.7: use `async_` instead of `async` (#274) * b65f62d Use `pytest` as `nosetests` are not longer maintained (#266) * d9aed96 Support using lua functions. `buf.update_higlights` as an internal example (#325)
Async rplugins (and sync ones for that matter) should conveniently be able to use lua to execute some logic on the nvim side. Rplugins can use
exec_lua(""" .... _myplugin = {...}""")
orexec_lua('_myplugin = require("myplugin")')
to define a module with helper functions, and then usenvim.lua._myplugin.myfunction(..., [async=True])
to call it.The
update_highlights
shows an example of the helper function pattern. Though it gets a bit more complex as we expect multiple copies of the python host, ordinary rplugins need not add the channel_id to the module name like the host does. nvim-ipy will add a more simple example how this can look for an rplugin.