|
1 | 1 | """Main Nvim interface."""
|
| 2 | +import functools |
2 | 3 | import os
|
3 | 4 |
|
4 | 5 | from msgpack import ExtType
|
@@ -73,6 +74,7 @@ def __init__(self, session, channel_id, metadata):
|
73 | 74 | self.windows = RemoteSequence(session, 'vim_get_windows')
|
74 | 75 | self.tabpages = RemoteSequence(session, 'vim_get_tabpages')
|
75 | 76 | self.current = Current(session)
|
| 77 | + self.funcs = Funcs(self) |
76 | 78 | self.error = NvimError
|
77 | 79 |
|
78 | 80 | def with_hook(self, hook):
|
@@ -124,6 +126,10 @@ def eval(self, string, async=False):
|
124 | 126 | """Evaluate a vimscript expression."""
|
125 | 127 | return self._session.request('vim_eval', string, async=async)
|
126 | 128 |
|
| 129 | + def call(self, name, *args): |
| 130 | + """Call a vimscript function.""" |
| 131 | + return self._session.request('vim_call_function', name, args) |
| 132 | + |
127 | 133 | def strwidth(self, string):
|
128 | 134 | """Return the number of display cells `string` occupies.
|
129 | 135 |
|
@@ -257,6 +263,17 @@ def tabpage(self, tabpage):
|
257 | 263 | return self._session.request('vim_set_current_tabpage', tabpage)
|
258 | 264 |
|
259 | 265 |
|
| 266 | +class Funcs(object): |
| 267 | + |
| 268 | + """Helper class for functional vimscript interface.""" |
| 269 | + |
| 270 | + def __init__(self, nvim): |
| 271 | + self._nvim = nvim |
| 272 | + |
| 273 | + def __getattr__(self, name): |
| 274 | + return functools.partial(self._nvim.call, name) |
| 275 | + |
| 276 | + |
260 | 277 | class ExtHook(SessionHook):
|
261 | 278 | def __init__(self, types):
|
262 | 279 | self.types = types
|
|
0 commit comments