Documentation
¶
Overview ¶
Package neovim implements support for writing Neovim plugins in Go. It also implements a tool for generating the MSGPACK-based API against a Neovim instance.
All API methods are supported, as are notifications. See Subscription for an example of how to register a subscription on a given topic.
Example Plugin ¶
For an example plugin see http://godoc.org/github.com/myitcv/neovim/example
Client ¶
Everything starts from Client:
_, err := neovim.NewUnixClient("unix", nil, &net.UnixAddr{Name: "/tmp/neovim"}) if err != nil { log.Fatalf("Could not create new Unix client: %v", errgo.Details(err)) }
See the examples for further usage patterns.
Concurrency ¶
A single Client may safely be used by multiple goroutines. Calls to API methods are blocking by design.
Generating the API ¶
See the github repo for details on re-generating the API.
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).
Errors ¶
Errors returned by this package are created using errgo at http://godoc.org/github.com/juju/errgo. Hence errors may be inspected using functions like errgo.Details for example:
_, err := client.GetCurrentBuffer() if err != nil { log.Fatalf("Could not get current buffer: %v", errgo.Details(err)) }
Index ¶
- type Buffer
- func (b *Buffer) DelLine(index int) error
- func (b *Buffer) GetLength() (int, error)
- func (b *Buffer) GetLine(index int) (string, error)
- func (b *Buffer) GetMark(name string) (uint32, error)
- func (b *Buffer) GetName() (string, error)
- func (b *Buffer) GetNumber() (int, error)
- func (b *Buffer) GetOption(name string) (interface{}, error)
- func (b *Buffer) GetSlice(start int, end int, includeStart bool, includeEnd bool) ([]string, 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) SetLine(index int, line string) error
- func (b *Buffer) SetName(name string) error
- func (b *Buffer) SetOption(name string, value interface{}) error
- func (b *Buffer) SetSlice(start int, end int, includeStart bool, includeEnd bool, replacement []string) error
- func (b *Buffer) SetVar(name string, value interface{}) (interface{}, error)
- type Client
- func (c *Client) ChangeDirectory(dir string) error
- func (c *Client) Close() error
- func (c *Client) Command(str 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) error
- func (c *Client) GetBuffers() ([]Buffer, 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) ListRuntimePaths() ([]string, error)
- func (c *Client) OutWrite(str string) error
- func (c *Client) PushKeys(str string) error
- func (c *Client) RegisterProvider(m string, r RequestHandler) error
- func (c *Client) ReplaceTermcodes(str string, fromPart bool, doLt bool, special bool) (string, error)
- 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(topic string) (*Subscription, error)
- func (c *Client) Unsubscribe(sub *Subscription) error
- type Logger
- type Plugin
- type RequestHandler
- type StdWrapper
- type Subscription
- type SubscriptionEvent
- type Tabpage
- type Window
- func (w *Window) GetBuffer() (Buffer, error)
- func (w *Window) GetCursor() (uint32, error)
- func (w *Window) GetHeight() (int, error)
- func (w *Window) GetOption(name string) (interface{}, error)
- func (w *Window) GetPosition() (uint32, 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 (w *Window) SetCursor(pos uint32) 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
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct { ID uint32 // contains filtered or unexported fields }
Buffer represents a Neovim Buffer
Multiple goroutines may invoke methods on a Buffer simultaneously
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{} // contains filtered or unexported fields }
A Client represents a connection to a single Neovim instance
func NewClient ¶
func NewClient(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 --embedded-mode 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 ¶
NewUnixClient is a convenience method for creating a new *Client. Method signature matches that of net.DialUnix
func (*Client) ChangeDirectory ¶
ChangeDirectory waiting for documentation from Neovim
func (*Client) DelCurrentLine ¶
DelCurrentLine waiting for documentation from Neovim
func (*Client) GetBuffers ¶
GetBuffers 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/errgo" "github.com/myitcv/neovim" ) func main() { cmd := exec.Command(os.Getenv("NEOVIM_BIN"), "-u", "/dev/null") cmd.Dir = "/tmp" client, err := neovim.NewCmdClient(cmd, nil) if err != nil { log.Fatalf("Could not create new client: %v", errgo.Details(err)) } b, err := client.GetCurrentBuffer() if err != nil { log.Fatalf("Could not get current buffer: %v", errgo.Details(err)) } n, err := b.GetName() if err != nil { log.Fatalf("Could not get name for buffer %v: %v", b, errgo.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) RegisterProvider ¶
func (c *Client) RegisterProvider(m string, r RequestHandler) 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) 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) Subscribe ¶
func (c *Client) Subscribe(topic string) (*Subscription, error)
Subscribe subscribes to a topic of events from Neovim. The *Subscription.Events channel will receive SubscriptionEvent's Unsubscribe needs to be called on a different goroutine to the goroutine that handles these SubscriptionEvent's
func (*Client) Unsubscribe ¶
func (c *Client) Unsubscribe(sub *Subscription) error
Unsubscribe unsubscribes from a topic of events from Neovim. This needs to be called on a different goroutine to that which is handling the SubscriptionEvent's
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) }
type RequestHandler ¶
type RequestHandler func([]interface{}) ([]interface{}, error)
TODO we might modify this to return an encode instead but this would require exposing the enc on Client Needs some thought
type StdWrapper ¶
type StdWrapper struct { Stdin io.WriteCloser Stdout io.ReadCloser }
func (*StdWrapper) Close ¶
func (s *StdWrapper) Close() error
type Subscription ¶
type Subscription struct { Topic string Events chan *SubscriptionEvent }
A Subscription represents a subscription to a Neovim event on a particular topic.
Example ¶
package main import ( "fmt" "log" "os" "os/exec" "github.com/juju/errgo" "github.com/myitcv/neovim" ) func main() { cmd := exec.Command(os.Getenv("NEOVIM_BIN"), "-u", "/dev/null") cmd.Dir = "/tmp" client, err := neovim.NewCmdClient(cmd, nil) if err != nil { log.Fatalf("Could not create new client: %v", errgo.Details(err)) } client.PanicOnError = true topic := "topic1" sub, err := client.Subscribe(topic) if err != nil { log.Fatalf("Could not subscribe to topic %v, with respChan %v and errChan %v: %v", sub.Topic, sub, errgo.Details(err)) } unsubbed := make(chan struct{}) done := make(chan struct{}) received := make(chan struct{}) go func() { ForLoop: for { select { case e := <-sub.Events: if e == nil { break ForLoop } fmt.Printf("We got %v\n", e.Value) received <- struct{}{} } } done <- struct{}{} }() command := fmt.Sprintf(`call send_event(0, "%v", 1)`, topic) _ = client.Command(command) <-received go func() { _ = client.Unsubscribe(sub) unsubbed <- struct{}{} }() <-done <-unsubbed _ = client.Close() }
Output: We got [1]
type SubscriptionEvent ¶
type SubscriptionEvent struct { Topic string Value []interface{} }
A SubscriptionEvent contains the value Value announced via a notification on topic Topic
type Tabpage ¶
type Tabpage struct { ID uint32 // contains filtered or unexported fields }
Tabpage represents a Neovim Tabpage
Multiple goroutines may invoke methods on a Tabpage simultaneously
func (*Tabpage) GetWindows ¶
GetWindows waiting for documentation from Neovim
type Window ¶
type Window struct { ID uint32 // contains filtered or unexported fields }
Window represents a Neovim Window
Multiple goroutines may invoke methods on a Window simultaneously
func (*Window) GetPosition ¶
GetPosition waiting for documentation from Neovim
func (*Window) GetTabpage ¶
GetTabpage waiting for documentation from Neovim