Skip to content
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

Merged
merged 2 commits into from Apr 26, 2018

Conversation

bfredl
Copy link
Member

@bfredl bfredl commented Apr 17, 2018

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 = {...}""") or exec_lua('_myplugin = require("myplugin")') to define a module with helper functions, and then use nvim.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.

@@ -115,6 +139,12 @@ def _to_nvim(self, obj):
return ExtType(*obj.code_data)
return obj

def _get_lua_helpers(self):
Copy link
Member

@justinmk justinmk Apr 17, 2018

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.

"""
if clear and clear_start is None:
clear_start = 0
helpers = self._session._get_lua_helpers()
Copy link
Member

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()

@bfredl
Copy link
Member Author

bfredl commented Apr 17, 2018

Now without helpers. I will add tests later.

@bfredl
Copy link
Member Author

bfredl commented Apr 25, 2018

Updated with tests. Also use only async_ for new functions.

@justinmk
Copy link
Member

LGTM. Will the docs autogenerate? I think it's cool enough to be mentioned in the README.md too.

@bfredl
Copy link
Member Author

bfredl commented Apr 25, 2018

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.

@bfredl
Copy link
Member Author

bfredl commented Apr 26, 2018

Merged. I will update docs for next release in separate PR.

bfredl added a commit that referenced this pull request Apr 29, 2018
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants