Skip to content

Commit

Permalink
Initial version of a simple Python plugin.
Browse files Browse the repository at this point in the history
A simple Python remote plugin for Neovim. Is working for Neovim:

NVIM 0.0.0-alpha+201507262350 (compiled Jul 29 2015 22:40:18)
  • Loading branch information
jacobsimpson committed Sep 2, 2015
1 parent ce84b93 commit 12daa7b
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 0 deletions.
109 changes: 109 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

19 changes: 19 additions & 0 deletions doc/nvim-example-python-plugin.txt
Original file line number Diff line number Diff line change
@@ -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.

3 changes: 3 additions & 0 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -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*
6 changes: 6 additions & 0 deletions plugin/nvim-example-python-plugin.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

echo "Starting the example Python Plugin"

function DoItVimL()
echo "DoItVimL"
endfunction
1 change: 1 addition & 0 deletions rplugin/python/nvim-example-python-plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Autocmd: Called file: nvim-example-python-plugin.py
11 changes: 11 additions & 0 deletions rplugin/python/nvim-example-python-plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -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"')

Binary file not shown.

0 comments on commit 12daa7b

Please sign in to comment.