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 ¶
- func NullInitMethod() error
- type AsyncDecoder
- type AsyncRunner
- type Buffer
- func (b *Buffer) DelLine(index int) error
- func (b *Buffer) ExtensionType() int8
- func (b *Buffer) GetLine(index int) (string, error)
- func (b *Buffer) GetLineSlice(start int, end int, includeStart bool, includeEnd bool) ([]string, error)
- func (b *Buffer) GetMark(name string) ([]int, error)
- func (b *Buffer) GetName() (string, error)
- func (b *Buffer) GetNumber() (int, error)
- func (b *Buffer) GetOption(name string) (interface{}, error)
- func (b *Buffer) GetVar(name string) (interface{}, error)
- func (b *Buffer) Insert(lnum int, lines []string) error
- func (b *Buffer) IsValid() (bool, error)
- func (b *Buffer) Len() int
- func (b *Buffer) LineCount() (int, error)
- func (b *Buffer) MarshalBinaryTo(buf []byte) error
- func (b *Buffer) SetLine(index int, line string) error
- func (b *Buffer) SetLineSlice(start int, end int, includeStart bool, includeEnd bool, replacement []string) error
- func (b *Buffer) SetName(name string) error
- func (b *Buffer) SetOption(name string, value interface{}) error
- func (b *Buffer) SetVar(name string, value interface{}) (interface{}, error)
- func (b *Buffer) UnmarshalBinary(buf []byte) error
- type CallArgs
- type ChannelID
- type Client
- func (c *Client) CallFunction(fname string, args []interface{}) (interface{}, error)
- func (c *Client) ChangeDirectory(dir string) error
- func (c *Client) Close() error
- func (c *Client) Command(str string) error
- func (c *Client) CommandOutput(str string) (string, error)
- func (c *Client) DelCurrentLine() error
- func (c *Client) ErrWrite(str string) error
- func (c *Client) Eval(str string) (interface{}, error)
- func (c *Client) Feedkeys(keys string, mode string, escapeCsi bool) error
- func (c *Client) GetAPIInfo() (ChannelID, *apidef.API, error)
- func (c *Client) GetApiInfo() ([]interface{}, error)
- func (c *Client) GetBuffers() ([]Buffer, error)
- func (c *Client) GetColorMap() (map[string]interface{}, error)
- func (c *Client) GetCurrentBuffer() (Buffer, error)
- func (c *Client) GetCurrentLine() (string, error)
- func (c *Client) GetCurrentTabpage() (Tabpage, error)
- func (c *Client) GetCurrentWindow() (Window, error)
- func (c *Client) GetOption(name string) (interface{}, error)
- func (c *Client) GetTabpages() ([]Tabpage, error)
- func (c *Client) GetVar(name string) (interface{}, error)
- func (c *Client) GetVvar(name string) (interface{}, error)
- func (c *Client) GetWindows() ([]Window, error)
- func (c *Client) Input(keys string) (int, error)
- func (c *Client) ListRuntimePaths() ([]string, error)
- func (c *Client) NameToColor(name string) (int, error)
- func (c *Client) OutWrite(str string) error
- func (c *Client) RegisterAsyncFunction(m string, d NewAsyncDecoder, rangeBased bool, eval bool) error
- func (c *Client) RegisterAsyncRequestHandler(m string, d NewAsyncDecoder, o *MethodOptions) error
- func (c *Client) RegisterSyncFunction(m string, d NewSyncDecoder, rangeBased bool, eval bool) error
- func (c *Client) RegisterSyncRequestHandler(m string, d NewSyncDecoder, o *MethodOptions) error
- func (c *Client) ReplaceTermcodes(str string, fromPart bool, doLt bool, special bool) (string, error)
- func (c *Client) ReportError(str string) error
- func (c *Client) Run()
- func (c *Client) SetCurrentBuffer(buffer Buffer) error
- func (c *Client) SetCurrentLine(line string) error
- func (c *Client) SetCurrentTabpage(tabpage Tabpage) error
- func (c *Client) SetCurrentWindow(window Window) error
- func (c *Client) SetOption(name string, value interface{}) error
- func (c *Client) SetVar(name string, value interface{}) (interface{}, error)
- func (c *Client) Strwidth(str string) (int, error)
- func (c *Client) Subscribe(event string) error
- func (c *Client) Unsubscribe(event string) error
- type Decoder
- type Encoder
- type InitMethod
- type InitMethodArgs
- type InitMethodRetVals
- type InitMethodWrapper
- type Logger
- type MethodOptionParams
- type MethodOptions
- type MethodType
- type NewAsyncDecoder
- type NewAsyncDecoderOptions
- type NewSyncDecoder
- type NewSyncDecoderOptions
- type NilDeocdable
- type Plugin
- type Range
- type RequestHandler
- type StdWrapper
- type SyncDecoder
- type SyncRunner
- type Tabpage
- func (b *Tabpage) ExtensionType() int8
- func (t *Tabpage) GetVar(name string) (interface{}, error)
- func (t *Tabpage) GetWindow() (Window, error)
- func (t *Tabpage) GetWindows() ([]Window, error)
- func (t *Tabpage) IsValid() (bool, error)
- func (b *Tabpage) Len() int
- func (b *Tabpage) MarshalBinaryTo(buf []byte) error
- func (t *Tabpage) SetVar(name string, value interface{}) (interface{}, error)
- func (b *Tabpage) UnmarshalBinary(buf []byte) error
- type Window
- func (b *Window) ExtensionType() int8
- func (w *Window) GetBuffer() (Buffer, error)
- func (w *Window) GetCursor() ([]int, error)
- func (w *Window) GetHeight() (int, error)
- func (w *Window) GetOption(name string) (interface{}, error)
- func (w *Window) GetPosition() ([]int, error)
- func (w *Window) GetTabpage() (Tabpage, error)
- func (w *Window) GetVar(name string) (interface{}, error)
- func (w *Window) GetWidth() (int, error)
- func (w *Window) IsValid() (bool, error)
- func (b *Window) Len() int
- func (b *Window) MarshalBinaryTo(buf []byte) error
- func (w *Window) SetCursor(pos []int) error
- func (w *Window) SetHeight(height int) error
- func (w *Window) SetOption(name string, value interface{}) error
- func (w *Window) SetVar(name string, value interface{}) (interface{}, error)
- func (w *Window) SetWidth(width int) error
- func (b *Window) UnmarshalBinary(buf []byte) error
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) ExtensionType ¶
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) MarshalBinaryTo ¶
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) UnmarshalBinary ¶
type CallArgs ¶
type CallArgs interface { Eval() msgp.Decodable Params() *MethodOptionParams Args() msgp.Decodable }
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 ¶
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 ¶
CallFunction waiting for documentation from Neovim
func (*Client) ChangeDirectory ¶
ChangeDirectory waiting for documentation from Neovim
func (*Client) CommandOutput ¶
CommandOutput waiting for documentation from Neovim
func (*Client) DelCurrentLine ¶
DelCurrentLine waiting for documentation from Neovim
func (*Client) GetApiInfo ¶
GetApiInfo waiting for documentation from Neovim
func (*Client) GetBuffers ¶
GetBuffers waiting for documentation from Neovim
func (*Client) GetColorMap ¶
GetColorMap waiting for documentation from Neovim
func (*Client) GetCurrentBuffer ¶
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 ¶
GetCurrentLine waiting for documentation from Neovim
func (*Client) GetCurrentTabpage ¶
GetCurrentTabpage waiting for documentation from Neovim
func (*Client) GetCurrentWindow ¶
GetCurrentWindow waiting for documentation from Neovim
func (*Client) GetTabpages ¶
GetTabpages waiting for documentation from Neovim
func (*Client) GetWindows ¶
GetWindows waiting for documentation from Neovim
func (*Client) ListRuntimePaths ¶
ListRuntimePaths waiting for documentation from Neovim
func (*Client) NameToColor ¶
NameToColor waiting for documentation from Neovim
func (*Client) RegisterAsyncFunction ¶
func (*Client) RegisterAsyncRequestHandler ¶
func (c *Client) RegisterAsyncRequestHandler(m string, d NewAsyncDecoder, o *MethodOptions) error
func (*Client) RegisterSyncFunction ¶
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 ¶
ReportError waiting for documentation from Neovim
func (*Client) SetCurrentBuffer ¶
SetCurrentBuffer waiting for documentation from Neovim
func (*Client) SetCurrentLine ¶
SetCurrentLine waiting for documentation from Neovim
func (*Client) SetCurrentTabpage ¶
SetCurrentTabpage waiting for documentation from Neovim
func (*Client) SetCurrentWindow ¶
SetCurrentWindow waiting for documentation from Neovim
func (*Client) Unsubscribe ¶
Unsubscribe waiting for documentation from Neovim
type Decoder ¶
Use for async notifications Here the error would simply be reported to the log (because there is nothing to return)
type InitMethod ¶
type InitMethod func() error
type InitMethodArgs ¶
type InitMethodArgs struct {
// contains filtered or unexported fields
}
type InitMethodRetVals ¶
type InitMethodRetVals struct {
InitMethod
}
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 (i *InitMethodWrapper) Params() *MethodOptionParams
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 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{}
type Plugin ¶
Plugin is the interface implemented by writers of Neovim plugins using the neovim package
type Range ¶
type Range struct {
StartLine, EndLine int
}
func (Range) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
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
type SyncDecoder ¶
type SyncDecoder interface { CallArgs SyncRunner Results() msgp.Encodable }
type SyncRunner ¶
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 (*Tabpage) GetWindows ¶
GetWindows waiting for documentation from Neovim
func (*Tabpage) MarshalBinaryTo ¶
func (*Tabpage) UnmarshalBinary ¶
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 (*Window) GetPosition ¶
GetPosition waiting for documentation from Neovim
func (*Window) GetTabpage ¶
GetTabpage waiting for documentation from Neovim