From 12daa7b09f9cf7bd6d7ede50d65a8a515dc79128 Mon Sep 17 00:00:00 2001 From: Jacob Simpson Date: Wed, 2 Sep 2015 00:51:54 -0700 Subject: [PATCH] Initial version of a simple Python plugin. A simple Python remote plugin for Neovim. Is working for Neovim: NVIM 0.0.0-alpha+201507262350 (compiled Jul 29 2015 22:40:18) --- README.md | 109 ++++++++++++++++++ doc/nvim-example-python-plugin.txt | 19 +++ doc/tags | 3 + plugin/nvim-example-python-plugin.vim | 6 + rplugin/python/nvim-example-python-plugin.py | 1 + .../nvim-example-python-plugin/__init__.py | 11 ++ .../nvim-example-python-plugin/__init__.pyc | Bin 0 -> 1066 bytes 7 files changed, 149 insertions(+) create mode 100644 README.md create mode 100644 doc/nvim-example-python-plugin.txt create mode 100644 doc/tags create mode 100644 plugin/nvim-example-python-plugin.vim create mode 100644 rplugin/python/nvim-example-python-plugin.py create mode 100644 rplugin/python/nvim-example-python-plugin/__init__.py create mode 100644 rplugin/python/nvim-example-python-plugin/__init__.pyc diff --git a/README.md b/README.md new file mode 100644 index 0000000..e569eba --- /dev/null +++ b/README.md @@ -0,0 +1,109 @@ +# Example Python Plugin for Neovim + +As part of the changes included in Neovim there is a new plugin model where +plugins are separate processes which Neovim communicates to using the +MessagePack protocol. + +Since plugins are distinct from the Neovim process, it is possible to write +plugins in many languages. + +This is a minimal example of a Python plugin. You should be able to (and feel +free to) copy this repository, rename a couple files, include the plugin in +your Vim config and see something happen. + +## Making a New Plugin + +The intention of this repository is to make it quick and easy to start a new +plugin. It is just enough to show how to make the basics work. + +```Bash +git clone --depth 1 https://github.com/jacobsimpson/nvim-example-python-plugin ~/.vim/bundles +rm -Rf ~/.vim/bundles/nvim-example-python-plugin/.git +``` + +## Configuring Vim + +I use NeoBundle so this is an example of how to load this plugin in NeoBundle. + +```VimL +" Required: +call neobundle#begin(expand('~/.vim/bundle/')) + + " Let NeoBundle manage NeoBundle + " Required: + NeoBundleFetch 'Shougo/neobundle.vim' + + " You probably have a number of other plugins listed here. + + " Add this line to make your new plugin load, assuming you haven't renamed it. + NeoBundle 'nvim-example-python-plugin' +call neobundle#end() +``` + +## Confirming the Plugin Loaded + +There is some VimL in the plugin that will print when Neovim is starting up: + + Starting the example Python Plugin + +That will confirm that the VimL portions of the plugin are loading correctly. +That does not guarantee that the Python portions of the plugin are loading. + +It should create a function that can be called. + +```VimL +:exec DoItVimL() +``` + +```VimL +:exec DoItPython() +``` + +It should add some mapped key handlers. + +## Changing the Interface + +Neovim includes a process whereby the interface of the remote plugin are cached +for Neovim. + +```VimL +:UpdateRemotePlugins +``` + +Run this command for *every* change in the plugin interface. Without this, you +may see errors on from Neovim telling you methods are missing from your plugin. +Or the new functionality you are trying to add just won't work. + +## Troubleshooting + +### Python Client Log File + +Define this environment variable to get output logged from your Python client. + +```Bash +export NVIM_PYTHON_LOG_FILE=${HOME}/.nvim-python.log +``` + +The output files will have a number appended, and should be visible with this: + +```Bash +ls ${HOME}/.nvim-python.log* +``` + +### Neovim Log File + +```Bash +ls ~/.nvimlog +``` + +### Neovim Library + +I found that the Python neovim module was not installed on my system. I didn't +see any great errors that lead me to that conclusion, so it is worth checking: + +```Bash +python -c "import neovim" +``` + +Should execute without an error. + diff --git a/doc/nvim-example-python-plugin.txt b/doc/nvim-example-python-plugin.txt new file mode 100644 index 0000000..5d47c52 --- /dev/null +++ b/doc/nvim-example-python-plugin.txt @@ -0,0 +1,19 @@ +*nvim-example-python-plugin.txt* A template of a remote Python plugin. + + Example Remote Python Plugin + +============================================================================== + +CONTENTS *nvim-example-python-plugin-contents* + + 1. Introduction .................... |nvim-example-python-plugin-intro| + + +Original Author: Jacob Simpson +License: The Unlicense + +INTRODUCTION *nvim-example-python-plugin-intro* + +A very simple example of a Python plugin in the new remote plugin style used by +Neovim. + diff --git a/doc/tags b/doc/tags new file mode 100644 index 0000000..6e69701 --- /dev/null +++ b/doc/tags @@ -0,0 +1,3 @@ +nvim-example-python-plugin-contents nvim-example-python-plugin.txt /*nvim-example-python-plugin-contents* +nvim-example-python-plugin-intro nvim-example-python-plugin.txt /*nvim-example-python-plugin-intro* +nvim-example-python-plugin.txt nvim-example-python-plugin.txt /*nvim-example-python-plugin.txt* diff --git a/plugin/nvim-example-python-plugin.vim b/plugin/nvim-example-python-plugin.vim new file mode 100644 index 0000000..b9038c2 --- /dev/null +++ b/plugin/nvim-example-python-plugin.vim @@ -0,0 +1,6 @@ + +echo "Starting the example Python Plugin" + +function DoItVimL() + echo "DoItVimL" +endfunction diff --git a/rplugin/python/nvim-example-python-plugin.py b/rplugin/python/nvim-example-python-plugin.py new file mode 100644 index 0000000..01ca36a --- /dev/null +++ b/rplugin/python/nvim-example-python-plugin.py @@ -0,0 +1 @@ +Autocmd: Called file: nvim-example-python-plugin.py diff --git a/rplugin/python/nvim-example-python-plugin/__init__.py b/rplugin/python/nvim-example-python-plugin/__init__.py new file mode 100644 index 0000000..f0c6ede --- /dev/null +++ b/rplugin/python/nvim-example-python-plugin/__init__.py @@ -0,0 +1,11 @@ +import neovim + +@neovim.plugin +class Limit(object): + def __init__(self, vim): + self.vim = vim + + @neovim.function('DoItPython') + def function_handler(self, args): + self.vim.command('echo "hello"') + diff --git a/rplugin/python/nvim-example-python-plugin/__init__.pyc b/rplugin/python/nvim-example-python-plugin/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e15f467e1f8f30a0f3e9f0dc1dddf1362c5a61eb GIT binary patch literal 1066 zcmc&zOHRWu5S=9aMI{y-0Cg1>B^N*l0UIP#p;TSajnyVDb>!Gp?IMu6gL5EpIWE8f z;EmIk1rkfJ;_+lW^Ze#HNj_S8uW#@Df|g?g>p7;&U`jj@X`%sJy{uH{sr>TKP3{jK~G1JB9(;03gI517IdpZ7>GFa0DX*b(8X5 znjpL2+SR;dj26ryq6Lu%G<#`;NHLK>gXVvH*B#IzhFSOTn``DJn#2&RLQfu1|;n1w###UkLdT7cf zx)x+OyLbPo#Q~U&=ce$=8ZiMsEoZDxqe+}@!CwkyhP4zTs3b&f%elsD&R6U?%Selh z3b`x5ocsRnE_i=_-8ncAvvm9cZpFJv_&ajG?LfTwhJtHHl`MRy_;1=l$kRsVGyY=& J{rz}1`T|q(3bz0N literal 0 HcmV?d00001