2014-11-17 08:45:52 -07:00
|
|
|
*nvim_provider.txt* For Nvim. {Nvim}
|
|
|
|
|
|
|
|
|
|
|
|
NVIM REFERENCE MANUAL by Thiago de Arruda
|
|
|
|
|
|
|
|
|
|
|
|
Nvim provider infrastructure *nvim-provider*
|
|
|
|
|
|
|
|
First of all, this document is meant to be read by developers interested in
|
|
|
|
contributing to the refactoring effort. If you are a normal user or plugin
|
|
|
|
developer looking to learn about Nvim |msgpack-rpc| infrastructure for
|
2015-02-16 23:28:37 -07:00
|
|
|
implementing plugins in other programming languages, see |remote-plugin|.
|
2015-02-24 15:31:42 -07:00
|
|
|
For instructions on how to enable Python plugins, see |nvim-python|. For
|
2014-11-17 08:45:52 -07:00
|
|
|
clipboard, see |nvim-clipboard|.
|
|
|
|
|
2015-02-24 15:31:42 -07:00
|
|
|
Instead of doing everything by itself, Nvim aims to simplify its own
|
2014-11-17 08:45:52 -07:00
|
|
|
maintenance by delegating as much work as possible to external systems. But
|
|
|
|
some Vim components are too tightly coupled and in some cases the refactoring
|
|
|
|
work necessary to swap in-house implementations by code that integrates to
|
|
|
|
other systems is too great. Nvim provider infrastructure is a facility that
|
|
|
|
aims to make this task simpler.
|
|
|
|
|
|
|
|
To understand why the provider infrastructure is useful, let us consider two
|
|
|
|
examples of integration with external systems that are implemented in Vim and
|
|
|
|
are now decoupled from Nvim core as providers:
|
|
|
|
|
2015-02-24 15:31:42 -07:00
|
|
|
The first example is clipboard integration: in the original Vim source code,
|
2014-12-07 02:28:48 -07:00
|
|
|
clipboard functions account for more than 1k lines of C source code (and that
|
2016-02-01 00:45:26 -07:00
|
|
|
is just on ui.c), all to perform two tasks that are now accomplished with
|
2014-11-17 08:45:52 -07:00
|
|
|
simple shell commands such as xclip or pbcopy/pbpaste.
|
|
|
|
|
2015-09-01 03:08:28 -07:00
|
|
|
The other example is Python scripting support: Vim has three files dedicated to
|
|
|
|
embedding the Python interpreter: if_python.c, if_python3.c and if_py_both.h.
|
2015-02-24 15:31:42 -07:00
|
|
|
Together these files sum about 9.5k lines of C source code. On Nvim, Python
|
2014-11-17 08:45:52 -07:00
|
|
|
scripting is performed by an external host process that is running 2k sloc
|
2015-02-24 15:31:42 -07:00
|
|
|
Python program.
|
2014-11-17 08:45:52 -07:00
|
|
|
|
2015-02-24 15:31:42 -07:00
|
|
|
In a perfect world, we would implement Python and clipboard integration in
|
2014-11-17 08:45:52 -07:00
|
|
|
pure vimscript and without touching the C code. Unfortunately we can't achieve
|
2015-09-01 03:08:28 -07:00
|
|
|
these goals without severely compromising backwards compatibility with Vim.
|
|
|
|
That's where providers come to the rescue.
|
2014-11-17 08:45:52 -07:00
|
|
|
|
2015-09-01 03:08:28 -07:00
|
|
|
In essence, this infrastructure is a simple framework that simplifies the task
|
|
|
|
of calling vimscript from C code, making it simpler to rewrite C functions that
|
2014-11-17 08:45:52 -07:00
|
|
|
interact with external systems in pure vimscript. It is composed of two
|
|
|
|
functions in eval.c:
|
|
|
|
|
|
|
|
- eval_call_provider(name, method, arguments): Call a provider(name) method
|
|
|
|
with arguments
|
|
|
|
- eval_has_provider(name): Checks if a provider is implemented
|
|
|
|
|
|
|
|
What these functions do is simple:
|
|
|
|
|
|
|
|
- eval_call_provider will call the provider#(name)#Call function passing in
|
|
|
|
the method and arguments.
|
|
|
|
- eval_has_provider will return true if the provider#(name)#Call function is
|
|
|
|
implemented, and is called by the "has" vimscript function to check if
|
|
|
|
features are available.
|
|
|
|
|
2014-12-07 02:28:48 -07:00
|
|
|
The basic idea is that the provider#(name)#Call function should implement
|
2014-11-17 08:45:52 -07:00
|
|
|
integration with an external system, because calling shell commands and
|
2014-12-07 02:28:48 -07:00
|
|
|
|msgpack-rpc| clients (Nvim only) is easier to do in vimscript.
|
2014-11-17 08:45:52 -07:00
|
|
|
|
2015-02-24 15:31:42 -07:00
|
|
|
Now, back to the Python example. Instead of modifying vimscript to allow for
|
2014-12-07 02:28:48 -07:00
|
|
|
the definition of lowercase functions and commands (for the |:python|,
|
|
|
|
|:pyfile|, and |:pydo| commands, and the |pyeval()| function), which would
|
|
|
|
break backwards compatibility with Vim, we implemented the
|
2014-11-17 08:45:52 -07:00
|
|
|
autoload/provider/python.vim script and the provider#python#Call function
|
2015-02-24 15:31:42 -07:00
|
|
|
that is only defined if an external Python host is started successfully.
|
2014-11-17 08:45:52 -07:00
|
|
|
|
2015-02-24 15:31:42 -07:00
|
|
|
That works well with the `has('python')` expression (normally used by Python
|
|
|
|
plugins) because if the Python host isn't installed then the plugin will
|
2014-12-07 02:28:48 -07:00
|
|
|
"think" it is running in a Vim compiled without |+python| feature.
|
2014-11-17 08:45:52 -07:00
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
vim:tw=78:ts=8:noet:ft=help:norl:
|