Skip to content
This repository has been archived by the owner on Nov 12, 2017. It is now read-only.

Commit

Permalink
Merge pull request #27 from neovim/next
Browse files Browse the repository at this point in the history
Breaking update
  • Loading branch information
billyvg authored Jul 24, 2017
2 parents 0c116cb + 7ad9728 commit c41099f
Show file tree
Hide file tree
Showing 23 changed files with 590 additions and 769 deletions.
78 changes: 0 additions & 78 deletions .jscsrc

This file was deleted.

18 changes: 0 additions & 18 deletions .jshintrc

This file was deleted.

9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

95 changes: 14 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,93 +2,26 @@
We will be introducing breaking changes in the near future. See the [new node-host](https://github.com/neovim/node-host/tree/next) and [new node-client](https://github.com/neovim/node-client/tree/next) for more information about the changes

# node-host

[![Build Status](https://travis-ci.org/neovim/node-host.png)](https://travis-ci.org/neovim/node-host)
<br>

## Installation

**Prerequisites:** You must have the `node` executable on your PATH and a copy of `npm`

1. Install this plugin using Vundle or your favorite plugin manager
2. Navigate to the `node-host` directory (e.g. `~/.nvim/bundle/node-host`) and run `npm install`

## Usage

To use a Node plugin, place the appropriate file or folder in `rplugin/node` in a `runtimepath` directory (e.g. `~/.nvim/rplugin/node`), run `npm install` if necessary, and then execute a `:UpdateRemotePlugins`.
Once you restart Neovim, you will be able to use your new plugins!

### Example

```javascript
var fmt = require('util').format,
numCalls = 0

function incrementCalls() {
if ( numCalls == 5 ) {
throw new Error('Too many calls!')
}
numCalls++
}
**Prerequisites:** You must have the `node` executable (currently only 7.x is supported) on your PATH and a copy of `npm`

plugin.commandSync('Cmd', {
range: '',
nargs: '*',
}, function( nvim, args, range, cb ) {
try {
incrementCalls()
nvim.setCurrentLine(
fmt('Command: Called', numCalls, 'times, args:', args, 'range:', range),
cb )
} catch ( err ) {
cb( err )
}
})
1. Install this plugin using `vim-plug` or your favorite plugin manager
2. Install `neovim` package globally: `npm install -g neovim@next`

plugin.autocmdSync('BufEnter', {
pattern: '*.js',
eval: 'expand("<afile>")'
}, function( nvim, filename, cb ) {
try {
incrementCalls()
nvim.setCurrentLine(
fmt('Autocmd: Called', numCalls, 'times, file:', filename), cb )
} catch ( err ) {
cb( err )
}
})

plugin.function('Func', function( nvim, args ) {
try {
incrementCalls()
nvim.setCurrentLine( fmt('Function: Called', numCalls, 'times, args:', args) )
} catch ( err ) {}
})
### Example config (vim-plug)
```vim
call plug#begin()
Plug 'neovim/node-host', { 'branch': 'next', 'do': 'npm install -g neovim@next' }
call plug#end()
```

### Writing plugins

A plugin can either be a file or folder with the `*.js` extension in the `rplugin/node` directory.
If the plugin is a folder, the package "main" script will be loaded.

The following functions, available on the global `plugin` object, can be used to register plugin commands/functions/autocmds on the attached Neovim instance.

#### (command|function|autocmd)\[Sync](name, [opts], callback)

If the `Sync` variant is used, Neovim will wait for the plugin to return a response via the errback passed as the final argument to the plugin function.
Otherwise, Neovim will continue execution immediately, ignoring any return values or errors.

`name` is the name of the plugin, `opts` is an optional hash of options, and `callback` is a function that is called whenever the command, function, or autocmd, is triggered.

Note: since `require` caches modules, to see your changes, you will need to restart the host by restarting Neovim.

#### Debugging
## Usage
To use a Node plugin, place the appropriate file or folder in `rplugin/node` in a `runtimepath` directory (e.g. `~/.nvim/rplugin/node`), run `npm install` if necessary, and then execute a `:UpdateRemotePlugins`.

Also available in the global scope is the `debug` function, which can be used like `console.log` and writes to the file given by the `$NEOVIM_JS_DEBUG` environment variable.
If you suspect that errors may be occurring in or propagating up to the host, itself, further error output can be found in `.nvimlog`.
You *must* restart neovim after a `:UpdateRemotePlugins` before you can use your new plugin.

## TODO
## Writing plugins
A plugin can either be a file or folder in the `rplugin/node` directory. If the plugin is a folder, the `main` script from `package.json` will be loaded.

* Auto-install Node executable if missing
* Plugin manager that allows post-install hooks for `npm install`
* Better isolation of global variables
Please see the [neovim repository](https://github.com/billyvg/node-client) for documentation on how to write a plugin (API is currently a WIP)
Loading

0 comments on commit c41099f

Please sign in to comment.