neovim

package module
v0.0.0-...-f91850c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2015 License: MIT Imports: 10 Imported by: 1

README

neovim

Build Status

Go package for writing Neovim plugins

go get github.com/myitcv/neovim

This package is very much in alpha. Therefore, expect changes to this API. Stuff will break.

Writing plugins

See:

  • the Example plugin for a brief README on how to implement your own Go plugin
  • neogo, a proof of concept Neovim plugin written against the neovim Go package to support Go development in Neovim. This uses a go/parser AST generated from the current buffer to highlight code using matchaddpos (as opposed to Neovim's default regex-based syntax definitions)

As explained in the TODO, many of the steps required to create a plugin are not currently automated, but very much on the roadmap.

Supported platforms

At the time of writing this package has only been written for/tested against Linux.

Support welcomed on other platforms

Tests

go test ./...

Credit

Todo list

See the wiki

Documentation

Overview

Package neovim implements support for writing Neovim plugins in Go. Communication with Neovim is via MSGPACK:

https://github.com/msgpack/msgpack/blob/master/spec.md

All Neovim API methods are supported. In addition there is support for handling synchronous method calls or asynchronous notifications from Neovim by registering handlers in your plugin. See the MSGPACK RPC spec for further details on these two types of callback:

https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md

Via a plugin manifest (details to follow) your plugin can bind these handlers to either Autocmds, Functions or Commands in Neovim.

Status

This project is still in alpha.

Example Plugin

For a complete example, see the example.Example plugin http://godoc.org/github.com/myitcv/neovim/example

Writing plugins

Plugins implement the Plugin interface. Plugins are initialised with a Client that is passed to a plugin via the Init method they implement. The Client is used to communicate with a Neovim instance.

Concurrency

A single Client may safely be used by multiple goroutines. Calls to API methods are blocking by design.

Compatibility

There are currently no checks to verify a connected Neovim instance exposes the same API against which the neovim package was generated. This is future work (and probably needs some work on the Neovim side).

See also

The tool for generating the API The Neovim Go plugin manager The code generator used by plugin writers

Errors

Errors returned by this package are created using errors at http://godoc.org/github.com/juju/errors. Hence errors may be inspected using functions like errors.Details for example:

_, err := client.GetCurrentBuffer()
if err != nil {
	log.Fatalf("Could not get current buffer: %v", errors.Details(err))
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NullInitMethod

func NullInitMethod() error

Types

type AsyncDecoder

type AsyncDecoder interface {
	CallArgs
	AsyncRunner
}

type AsyncRunner

type AsyncRunner interface {
	Run() error
}

type Buffer

type Buffer struct {
	ID uint8
	// contains filtered or unexported fields
}

Buffer represents a Neovim Buffer

Multiple goroutines may invoke methods on a Buffer simultaneously

func (*Buffer) DelLine

func (b *Buffer) DelLine(index int) error

DelLine waiting for documentation from Neovim

func (*Buffer) ExtensionType

func (b *Buffer) ExtensionType() int8

func (*Buffer) GetLine

func (b *Buffer) GetLine(index int) (string, error)

GetLine waiting for documentation from Neovim

func (*Buffer) GetLineSlice

func (b *Buffer) GetLineSlice(start int, end int, includeStart bool, includeEnd bool) ([]string, error)

GetLineSlice waiting for documentation from Neovim

func (*Buffer) GetMark

func (b *Buffer) GetMark(name string) ([]int, error)

GetMark waiting for documentation from Neovim

func (*Buffer) GetName

func (b *Buffer) GetName() (string, error)

GetName waiting for documentation from Neovim

func (*Buffer) GetNumber

func (b *Buffer) GetNumber() (int, error)

GetNumber waiting for documentation from Neovim

func (*Buffer) GetOption

func (b *Buffer) GetOption(name string) (interface{}, error)

GetOption waiting for documentation from Neovim

func (*Buffer) GetVar

func (b *Buffer) GetVar(name string) (interface{}, error)

GetVar waiting for documentation from Neovim

func (*Buffer) Insert

func (b *Buffer) Insert(lnum int, lines []string) error

Insert waiting for documentation from Neovim

func (*Buffer) IsValid

func (b *Buffer) IsValid() (bool, error)

IsValid waiting for documentation from Neovim

func (*Buffer) Len

func (b *Buffer) Len() int

func (*Buffer) LineCount

func (b *Buffer) LineCount() (int, error)

LineCount waiting for documentation from Neovim

func (*Buffer) MarshalBinaryTo

func (b *Buffer) MarshalBinaryTo(buf []byte) error

func (*Buffer) SetLine

func (b *Buffer) SetLine(index int, line string) error

SetLine waiting for documentation from Neovim

func (*Buffer) SetLineSlice

func (b *Buffer) SetLineSlice(start int, end int, includeStart bool, includeEnd bool, replacement []string) error

SetLineSlice waiting for documentation from Neovim

func (*Buffer) SetName

func (b *Buffer) SetName(name string) error

SetName waiting for documentation from Neovim

func (*Buffer) SetOption

func (b *Buffer) SetOption(name string, value interface{}) error

SetOption waiting for documentation from Neovim

func (*Buffer) SetVar

func (b *Buffer) SetVar(name string, value interface{}) (interface{}, error)

SetVar waiting for documentation from Neovim

func (*Buffer) UnmarshalBinary

func (b *Buffer) UnmarshalBinary(buf []byte) error

type CallArgs

type CallArgs interface {
	Eval() msgp.Decodable
	Params() *MethodOptionParams
	Args() msgp.Decodable
}

type ChannelID

type ChannelID uint8

type Client

type Client struct {

	// PanicOnError can be set to have the Client panic when an error would
	// otherwise have been returned via an API method. Note: any attempt to
	// change this option during concurrent use of the Client will be racey.
	// This is useful for debugging.
	PanicOnError bool
	KillChannel  chan struct{}

	// TODO remove this
	HostName string
	// contains filtered or unexported fields
}

A Client represents a connection to a single Neovim instance

func NewClient

func NewClient(im InitMethod, c io.ReadWriteCloser, log Logger) (*Client, error)

NewClient creates a new Client

func NewCmdClient

func NewCmdClient(im InitMethod, c *exec.Cmd, log Logger) (*Client, error)

NewCmdClient creates a new Client that is linked via stdin/stdout to the supplied exec.Cmd, which is assumed to launch Neovim. The Neovim flag --embed is added if it is missing, and the exec.Cmd is started as part of creating the client. Calling Close() will close stdin on the embedded Neovim instance, thereby ending the process

func NewUnixClient

func NewUnixClient(im InitMethod, _net string, laddr, raddr *net.UnixAddr, log Logger) (*Client, error)

NewUnixClient is a convenience method for creating a new *Client. Method signature matches that of net.DialUnix

func (*Client) CallFunction

func (c *Client) CallFunction(fname string, args []interface{}) (interface{}, error)

CallFunction waiting for documentation from Neovim

func (*Client) ChangeDirectory

func (c *Client) ChangeDirectory(dir string) error

ChangeDirectory waiting for documentation from Neovim

func (*Client) Close

func (c *Client) Close() error

Close cleanly kills the client connection to Neovim

func (*Client) Command

func (c *Client) Command(str string) error

Command waiting for documentation from Neovim

func (*Client) CommandOutput

func (c *Client) CommandOutput(str string) (string, error)

CommandOutput waiting for documentation from Neovim

func (*Client) DelCurrentLine

func (c *Client) DelCurrentLine() error

DelCurrentLine waiting for documentation from Neovim

func (*Client) ErrWrite

func (c *Client) ErrWrite(str string) error

ErrWrite waiting for documentation from Neovim

func (*Client) Eval

func (c *Client) Eval(str string) (interface{}, error)

Eval waiting for documentation from Neovim

func (*Client) Feedkeys

func (c *Client) Feedkeys(keys string, mode string, escapeCsi bool) error

Feedkeys waiting for documentation from Neovim

func (*Client) GetAPIInfo

func (c *Client) GetAPIInfo() (ChannelID, *apidef.API, error)

func (*Client) GetApiInfo

func (c *Client) GetApiInfo() ([]interface{}, error)

GetApiInfo waiting for documentation from Neovim

func (*Client) GetBuffers

func (c *Client) GetBuffers() ([]Buffer, error)

GetBuffers waiting for documentation from Neovim

func (*Client) GetColorMap

func (c *Client) GetColorMap() (map[string]interface{}, error)

GetColorMap waiting for documentation from Neovim

func (*Client) GetCurrentBuffer

func (c *Client) GetCurrentBuffer() (Buffer, error)

GetCurrentBuffer waiting for documentation from Neovim

Example
package main

import (
	"fmt"
	"log"
	"os"
	"os/exec"

	"github.com/juju/errors"
	"github.com/myitcv/neovim"
)

func main() {
	cmd := exec.Command(os.Getenv("NEOVIM_BIN"), "-u", "/dev/null")
	cmd.Dir = "/tmp"

	client, err := neovim.NewCmdClient(neovim.NullInitMethod, cmd, nil)
	if err != nil {
		log.Fatalf("Could not create new client: %v", errors.Details(err))
	}
	client.Run()

	b, err := client.GetCurrentBuffer()
	if err != nil {
		log.Fatalf("Could not get current buffer: %v", errors.Details(err))
	}
	n, err := b.GetName()
	if err != nil {
		log.Fatalf("Could not get name for buffer %v: %v", b, errors.Details(err))
	}
	fmt.Printf("Current buffer is: %v %v\n", b.ID, n)

	err = client.Close()
	if err != nil {
		log.Fatalf("Could not close client: %v\n", err)
	}

}
Output:

Current buffer is: 2

func (*Client) GetCurrentLine

func (c *Client) GetCurrentLine() (string, error)

GetCurrentLine waiting for documentation from Neovim

func (*Client) GetCurrentTabpage

func (c *Client) GetCurrentTabpage() (Tabpage, error)

GetCurrentTabpage waiting for documentation from Neovim

func (*Client) GetCurrentWindow

func (c *Client) GetCurrentWindow() (Window, error)

GetCurrentWindow waiting for documentation from Neovim

func (*Client) GetOption

func (c *Client) GetOption(name string) (interface{}, error)

GetOption waiting for documentation from Neovim

func (*Client) GetTabpages

func (c *Client) GetTabpages() ([]Tabpage, error)

GetTabpages waiting for documentation from Neovim

func (*Client) GetVar

func (c *Client) GetVar(name string) (interface{}, error)

GetVar waiting for documentation from Neovim

func (*Client) GetVvar

func (c *Client) GetVvar(name string) (interface{}, error)

GetVvar waiting for documentation from Neovim

func (*Client) GetWindows

func (c *Client) GetWindows() ([]Window, error)

GetWindows waiting for documentation from Neovim

func (*Client) Input

func (c *Client) Input(keys string) (int, error)

Input waiting for documentation from Neovim

func (*Client) ListRuntimePaths

func (c *Client) ListRuntimePaths() ([]string, error)

ListRuntimePaths waiting for documentation from Neovim

func (*Client) NameToColor

func (c *Client) NameToColor(name string) (int, error)

NameToColor waiting for documentation from Neovim

func (*Client) OutWrite

func (c *Client) OutWrite(str string) error

OutWrite waiting for documentation from Neovim

func (*Client) RegisterAsyncFunction

func (c *Client) RegisterAsyncFunction(m string, d NewAsyncDecoder, rangeBased bool, eval bool) error

func (*Client) RegisterAsyncRequestHandler

func (c *Client) RegisterAsyncRequestHandler(m string, d NewAsyncDecoder, o *MethodOptions) error

func (*Client) RegisterSyncFunction

func (c *Client) RegisterSyncFunction(m string, d NewSyncDecoder, rangeBased bool, eval bool) error

func (*Client) RegisterSyncRequestHandler

func (c *Client) RegisterSyncRequestHandler(m string, d NewSyncDecoder, o *MethodOptions) error

func (*Client) ReplaceTermcodes

func (c *Client) ReplaceTermcodes(str string, fromPart bool, doLt bool, special bool) (string, error)

ReplaceTermcodes waiting for documentation from Neovim

func (*Client) ReportError

func (c *Client) ReportError(str string) error

ReportError waiting for documentation from Neovim

func (*Client) Run

func (c *Client) Run()

func (*Client) SetCurrentBuffer

func (c *Client) SetCurrentBuffer(buffer Buffer) error

SetCurrentBuffer waiting for documentation from Neovim

func (*Client) SetCurrentLine

func (c *Client) SetCurrentLine(line string) error

SetCurrentLine waiting for documentation from Neovim

func (*Client) SetCurrentTabpage

func (c *Client) SetCurrentTabpage(tabpage Tabpage) error

SetCurrentTabpage waiting for documentation from Neovim

func (*Client) SetCurrentWindow

func (c *Client) SetCurrentWindow(window Window) error

SetCurrentWindow waiting for documentation from Neovim

func (*Client) SetOption

func (c *Client) SetOption(name string, value interface{}) error

SetOption waiting for documentation from Neovim

func (*Client) SetVar

func (c *Client) SetVar(name string, value interface{}) (interface{}, error)

SetVar waiting for documentation from Neovim

func (*Client) Strwidth

func (c *Client) Strwidth(str string) (int, error)

Strwidth waiting for documentation from Neovim

func (*Client) Subscribe

func (c *Client) Subscribe(event string) error

Subscribe waiting for documentation from Neovim

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(event string) error

Unsubscribe waiting for documentation from Neovim

type Decoder

type Decoder interface {
	DecodeMsg(*msgp.Reader) error
}

Use for async notifications Here the error would simply be reported to the log (because there is nothing to return)

type Encoder

type Encoder interface {
	EncodeMsg(*msgp.Writer) error
}

type InitMethod

type InitMethod func() error

type InitMethodArgs

type InitMethodArgs struct {
	// contains filtered or unexported fields
}

func (*InitMethodArgs) DecodeMsg

func (z *InitMethodArgs) DecodeMsg(dc *msgp.Reader) (err error)

type InitMethodRetVals

type InitMethodRetVals struct {
	InitMethod
}

func (*InitMethodRetVals) EncodeMsg

func (z *InitMethodRetVals) EncodeMsg(en *msgp.Writer) (err error)

type InitMethodWrapper

type InitMethodWrapper struct {
	*Client
	InitMethod
	// contains filtered or unexported fields
}

func (*InitMethodWrapper) Args

func (i *InitMethodWrapper) Args() msgp.Decodable

func (*InitMethodWrapper) Eval

func (i *InitMethodWrapper) Eval() msgp.Decodable

func (*InitMethodWrapper) Params

func (*InitMethodWrapper) Results

func (i *InitMethodWrapper) Results() msgp.Encodable

func (*InitMethodWrapper) Run

func (i *InitMethodWrapper) Run() (error, error)

type Logger

type Logger interface {
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Fatalln(v ...interface{})
	Flags() int
	Output(calldepth int, s string) error
	Panic(v ...interface{})
	Panicf(format string, v ...interface{})
	Panicln(v ...interface{})
	Prefix() string
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
	SetFlags(flag int)
	SetPrefix(prefix string)
}

Logger is a local definition of the inteface effectively exposed by http://godoc.org/log

type MethodOptionParams

type MethodOptionParams struct {
	Range *Range
}

func (*MethodOptionParams) DecodeParams

func (m *MethodOptionParams) DecodeParams(o *MethodOptions, reader *msgp.Reader) error

type MethodOptions

type MethodOptions struct {
	Type  MethodType
	Range bool
	Eval  bool
}

func (*MethodOptions) ArgsLength

func (m *MethodOptions) ArgsLength() (res uint32)

type MethodType

type MethodType uint
const (
	FUNCTION MethodType = iota
	COMMAND
	AUTOCOMMAND
)

type NewAsyncDecoder

type NewAsyncDecoder func() AsyncDecoder

type NewAsyncDecoderOptions

type NewAsyncDecoderOptions struct {
	NewAsyncDecoder
	*MethodOptions
}

type NewSyncDecoder

type NewSyncDecoder func() SyncDecoder

type NewSyncDecoderOptions

type NewSyncDecoderOptions struct {
	NewSyncDecoder
	*MethodOptions
}

type NilDeocdable

type NilDeocdable struct{}

func (*NilDeocdable) DecodeMsg

func (n *NilDeocdable) DecodeMsg(r *msgp.Reader) error

type Plugin

type Plugin interface {
	Init(*Client, Logger) error
	Shutdown() error
}

Plugin is the interface implemented by writers of Neovim plugins using the neovim package

type Range

type Range struct {
	StartLine, EndLine int
}

func (*Range) DecodeMsg

func (z *Range) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Range) EncodeMsg

func (z Range) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Range) MarshalMsg

func (z Range) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Range) Msgsize

func (z Range) Msgsize() (s int)

func (*Range) UnmarshalMsg

func (z *Range) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type RequestHandler

type RequestHandler func([]interface{}) ([]interface{}, error)

RequestHandler is the type signature of callback handlers used in RegisterRequestHandler

type StdWrapper

type StdWrapper struct {
	Stdin  io.WriteCloser
	Stdout io.ReadCloser
}

StdWrapper is a wrapper around two io.WriterCloser and io.ReadCloser instances that exposes itself as an io.ReadWriteCloser. Typically used with os.Stdin and os.Stdout or their pipe equivalents

func (*StdWrapper) Close

func (s *StdWrapper) Close() error

func (*StdWrapper) Read

func (s *StdWrapper) Read(p []byte) (n int, err error)

func (*StdWrapper) Write

func (s *StdWrapper) Write(p []byte) (n int, err error)

type SyncDecoder

type SyncDecoder interface {
	CallArgs
	SyncRunner
	Results() msgp.Encodable
}

type SyncRunner

type SyncRunner interface {
	Run() (error, error)
}

type Tabpage

type Tabpage struct {
	ID uint8
	// contains filtered or unexported fields
}

Tabpage represents a Neovim Tabpage

Multiple goroutines may invoke methods on a Tabpage simultaneously

func (*Tabpage) ExtensionType

func (b *Tabpage) ExtensionType() int8

func (*Tabpage) GetVar

func (t *Tabpage) GetVar(name string) (interface{}, error)

GetVar waiting for documentation from Neovim

func (*Tabpage) GetWindow

func (t *Tabpage) GetWindow() (Window, error)

GetWindow waiting for documentation from Neovim

func (*Tabpage) GetWindows

func (t *Tabpage) GetWindows() ([]Window, error)

GetWindows waiting for documentation from Neovim

func (*Tabpage) IsValid

func (t *Tabpage) IsValid() (bool, error)

IsValid waiting for documentation from Neovim

func (*Tabpage) Len

func (b *Tabpage) Len() int

func (*Tabpage) MarshalBinaryTo

func (b *Tabpage) MarshalBinaryTo(buf []byte) error

func (*Tabpage) SetVar

func (t *Tabpage) SetVar(name string, value interface{}) (interface{}, error)

SetVar waiting for documentation from Neovim

func (*Tabpage) UnmarshalBinary

func (b *Tabpage) UnmarshalBinary(buf []byte) error

type Window

type Window struct {
	ID uint8
	// contains filtered or unexported fields
}

Window represents a Neovim Window

Multiple goroutines may invoke methods on a Window simultaneously

func (*Window) ExtensionType

func (b *Window) ExtensionType() int8

func (*Window) GetBuffer

func (w *Window) GetBuffer() (Buffer, error)

GetBuffer waiting for documentation from Neovim

func (*Window) GetCursor

func (w *Window) GetCursor() ([]int, error)

GetCursor waiting for documentation from Neovim

func (*Window) GetHeight

func (w *Window) GetHeight() (int, error)

GetHeight waiting for documentation from Neovim

func (*Window) GetOption

func (w *Window) GetOption(name string) (interface{}, error)

GetOption waiting for documentation from Neovim

func (*Window) GetPosition

func (w *Window) GetPosition() ([]int, error)

GetPosition waiting for documentation from Neovim

func (*Window) GetTabpage

func (w *Window) GetTabpage() (Tabpage, error)

GetTabpage waiting for documentation from Neovim

func (*Window) GetVar

func (w *Window) GetVar(name string) (interface{}, error)

GetVar waiting for documentation from Neovim

func (*Window) GetWidth

func (w *Window) GetWidth() (int, error)

GetWidth waiting for documentation from Neovim

func (*Window) IsValid

func (w *Window) IsValid() (bool, error)

IsValid waiting for documentation from Neovim

func (*Window) Len

func (b *Window) Len() int

func (*Window) MarshalBinaryTo

func (b *Window) MarshalBinaryTo(buf []byte) error

func (*Window) SetCursor

func (w *Window) SetCursor(pos []int) error

SetCursor waiting for documentation from Neovim

func (*Window) SetHeight

func (w *Window) SetHeight(height int) error

SetHeight waiting for documentation from Neovim

func (*Window) SetOption

func (w *Window) SetOption(name string, value interface{}) error

SetOption waiting for documentation from Neovim

func (*Window) SetVar

func (w *Window) SetVar(name string, value interface{}) (interface{}, error)

SetVar waiting for documentation from Neovim

func (*Window) SetWidth

func (w *Window) SetWidth(width int) error

SetWidth waiting for documentation from Neovim

func (*Window) UnmarshalBinary

func (b *Window) UnmarshalBinary(buf []byte) error

Directories

Path Synopsis
cmd
template

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL