diff --git a/nvim/api.go b/nvim/api.go index cb296e0f..858c5c01 100644 --- a/nvim/api.go +++ b/nvim/api.go @@ -166,7 +166,7 @@ func (b *Batch) HLByName(name string, rgb bool, highlight *HLAttrs) { // in addition the following keys are also recognized: // // default -// don't override existing definition, like `hi default`. +// don't override existing definition, like "hi default". func (v *Nvim) SetHighlight(nsID int, name string, val *HLAttrs) error { return v.call("nvim_set_hl", nil, nsID, name, val) } @@ -180,7 +180,7 @@ func (v *Nvim) SetHighlight(nsID int, name string, val *HLAttrs) error { // in addition the following keys are also recognized: // // default -// don't override existing definition, like `hi default`. +// don't override existing definition, like "hi default". func (b *Batch) SetHighlight(nsID int, name string, val *HLAttrs) { b.call("nvim_set_hl", nil, nsID, name, val) } @@ -228,7 +228,7 @@ func (b *Batch) SetHighlightNameSpace(nsID int) { // Handle keys as if typed; otherwise they are handled as if coming from a mapping. // This matters for undo, opening folds, etc. // -// The escape_csi arg is whether the escape K_SPECIAL/CSI bytes in keys arg. +// The escapeCSI arg is whether the escape K_SPECIAL/CSI bytes in keys arg. func (v *Nvim) FeedKeys(keys string, mode string, escapeCSI bool) error { return v.call("nvim_feedkeys", nil, keys, mode, escapeCSI) } @@ -252,7 +252,7 @@ func (v *Nvim) FeedKeys(keys string, mode string, escapeCSI bool) error { // Handle keys as if typed; otherwise they are handled as if coming from a mapping. // This matters for undo, opening folds, etc. // -// The escape_csi arg is whether the escape K_SPECIAL/CSI bytes in keys arg. +// The escapeCSI arg is whether the escape K_SPECIAL/CSI bytes in keys arg. func (b *Batch) FeedKeys(keys string, mode string, escapeCSI bool) { b.call("nvim_feedkeys", nil, keys, mode, escapeCSI) } @@ -278,6 +278,33 @@ func (b *Batch) Input(keys string, written *int) { // // This API is non-blocking. It doesn't wait on any resulting action, but // queues the event to be processed soon by the event loop. +// +// The button arg is mouse button. One of +// "left" +// "right" +// "middle" +// "wheel" +// +// The action arg is for ordinary buttons. One of +// "press" +// "drag" +// "release" +// For the wheel, One of +// "up" +// "down +// "left" +// "right" +// +// The modifier arg is string of modifiers each represented by a single char. +// The same specifiers are used as for a key press, except +// that the "-" separator is optional, so "C-A-", "c-a" +// and "CA" can all be used to specify Ctrl+Alt+click. +// +// The grid arg is grid number if the client uses "ui-multigrid", else 0. +// +// The row arg is mouse row-position (zero-based, like redraw events). +// +// The col arg is mouse column-position (zero-based, like redraw events). func (v *Nvim) InputMouse(button string, action string, modifier string, grid int, row int, col int) error { return v.call("nvim_input_mouse", nil, button, action, modifier, grid, row, col) } @@ -286,6 +313,33 @@ func (v *Nvim) InputMouse(button string, action string, modifier string, grid in // // This API is non-blocking. It doesn't wait on any resulting action, but // queues the event to be processed soon by the event loop. +// +// The button arg is mouse button. One of +// "left" +// "right" +// "middle" +// "wheel" +// +// The action arg is for ordinary buttons. One of +// "press" +// "drag" +// "release" +// For the wheel, One of +// "up" +// "down +// "left" +// "right" +// +// The modifier arg is string of modifiers each represented by a single char. +// The same specifiers are used as for a key press, except +// that the "-" separator is optional, so "C-A-", "c-a" +// and "CA" can all be used to specify Ctrl+Alt+click. +// +// The grid arg is grid number if the client uses "ui-multigrid", else 0. +// +// The row arg is mouse row-position (zero-based, like redraw events). +// +// The col arg is mouse column-position (zero-based, like redraw events). func (b *Batch) InputMouse(button string, action string, modifier string, grid int, row int, col int) { b.call("nvim_input_mouse", nil, button, action, modifier, grid, row, col) } @@ -301,6 +355,12 @@ func (b *Batch) InputMouse(button string, action string, modifier string, grid i // -> '\x80ku' // // The returned sequences can be used as input to feedkeys. +// +// The fromPart arg is legacy Vim parameter. Usually true. +// +// The doLT arg is also translate . Ignored if "special" is false. +// +// The special arg is replace "keycodes", e.g. becomes a "\n" char. func (v *Nvim) ReplaceTermcodes(str string, fromPart bool, doLT bool, special bool) (input string, err error) { err = v.call("nvim_replace_termcodes", &input, str, fromPart, doLT, special) return input, err @@ -317,6 +377,12 @@ func (v *Nvim) ReplaceTermcodes(str string, fromPart bool, doLT bool, special bo // -> '\x80ku' // // The returned sequences can be used as input to feedkeys. +// +// The fromPart arg is legacy Vim parameter. Usually true. +// +// The doLT arg is also translate . Ignored if "special" is false. +// +// The special arg is replace "keycodes", e.g. becomes a "\n" char. func (b *Batch) ReplaceTermcodes(str string, fromPart bool, doLT bool, special bool, input *string) { b.call("nvim_replace_termcodes", input, str, fromPart, doLT, special) } @@ -340,6 +406,8 @@ func (b *Batch) CommandOutput(cmd string, out *string) { // // Dictionaries and Lists are recursively expanded. // +// The expr arg is VimL expression string. +// // :help expression func (v *Nvim) Eval(expr string, result interface{}) error { return v.call("nvim_eval", result, expr) @@ -349,6 +417,8 @@ func (v *Nvim) Eval(expr string, result interface{}) error { // // Dictionaries and Lists are recursively expanded. // +// The expr arg is VimL expression string. +// // :help expression func (b *Batch) Eval(expr string, result interface{}) { b.call("nvim_eval", &result, expr) @@ -705,7 +775,7 @@ func (b *Batch) SetOption(name string, value interface{}) { // The chunks is a list of [text, hl_group] arrays, each representing a // text chunk with specified highlight. hl_group element can be omitted for no highlight. // -// If history is true, add to |message-history|. +// If history is true, add to "message-history". // // The opts arg is optional parameters. Reserved for future use. func (v *Nvim) Echo(chunks []TextChunk, history bool, opts map[string]interface{}) error { @@ -717,7 +787,7 @@ func (v *Nvim) Echo(chunks []TextChunk, history bool, opts map[string]interface{ // The chunks is a list of [text, hl_group] arrays, each representing a // text chunk with specified highlight. hl_group element can be omitted for no highlight. // -// If history is true, add to |message-history|. +// If history is true, add to "message-history". // // The opts arg is optional parameters. Reserved for future use. func (b *Batch) Echo(chunks []TextChunk, history bool, opts map[string]interface{}) { @@ -834,8 +904,8 @@ func (b *Batch) SetCurrentWindow(window Window) { // // The listed arg sets buflisted buffer opttion. // -// The scratch arg creates a "throwaway" |scratch-buffer| for temporary work (always 'nomodified'). -// Also sets 'nomodeline' on the buffer. +// The scratch arg creates a "throwaway" "scratch-buffer" for temporary work (always "nomodified"). +// Also sets "nomodeline" on the buffer. func (v *Nvim) CreateBuffer(listed bool, scratch bool) (buffer Buffer, err error) { err = v.call("nvim_create_buf", &buffer, listed, scratch) return buffer, err @@ -845,8 +915,8 @@ func (v *Nvim) CreateBuffer(listed bool, scratch bool) (buffer Buffer, err error // // The listed arg sets buflisted buffer opttion. // -// The scratch arg creates a "throwaway" |scratch-buffer| for temporary work (always 'nomodified'). -// Also sets 'nomodeline' on the buffer. +// The scratch arg creates a "throwaway" "scratch-buffer" for temporary work (always "nomodified"). +// Also sets "nomodeline" on the buffer. func (b *Batch) CreateBuffer(listed bool, scratch bool, buffer *Buffer) { b.call("nvim_create_buf", buffer, listed, scratch) } @@ -860,7 +930,7 @@ func (b *Batch) CreateBuffer(listed bool, scratch bool, buffer *Buffer) { // External windows are only supported with multigrid GUIs, and are displayed as separate top-level windows. // // For a general overview of floats, see -// help api-floatwin +// :help api-floatwin // // Exactly one of `external` and `relative` must be specified. // The `width` and `height` of the new window must be specified. @@ -873,6 +943,7 @@ func (b *Batch) CreateBuffer(listed bool, scratch bool, buffer *Buffer) { // // Out-of-bounds values, and configurations that make the float not fit inside // the main editor, are allowed. +// // The builtin implementation truncates values so floats are fully within the main screen grid. // External GUIs could let floats hover outside of the main window like a tooltip, but // this should not be used to specify arbitrary WM screen positions. @@ -890,7 +961,7 @@ func (v *Nvim) OpenWindow(buffer Buffer, enter bool, config *WindowConfig) (wind // External windows are only supported with multigrid GUIs, and are displayed as separate top-level windows. // // For a general overview of floats, see -// help api-floatwin +// :help api-floatwin // // Exactly one of `external` and `relative` must be specified. // The `width` and `height` of the new window must be specified. @@ -903,6 +974,7 @@ func (v *Nvim) OpenWindow(buffer Buffer, enter bool, config *WindowConfig) (wind // // Out-of-bounds values, and configurations that make the float not fit inside // the main editor, are allowed. +// // The builtin implementation truncates values so floats are fully within the main screen grid. // External GUIs could let floats hover outside of the main window like a tooltip, but // this should not be used to specify arbitrary WM screen positions. @@ -948,8 +1020,8 @@ func (b *Batch) SetCurrentTabpage(tabpage Tabpage) { // AddBufferHighlight and SetBufferVirtualText. // // Namespaces can be named or anonymous. -// If `name` matches an existing namespace, the associated id is returned. -// If `name` is an empty string a new, anonymous namespace is created. +// If "name" matches an existing namespace, the associated id is returned. +// If "name" is an empty string a new, anonymous namespace is created. // // The returns the namespace ID. func (v *Nvim) CreateNamespace(name string) (nsID int, err error) { @@ -963,8 +1035,8 @@ func (v *Nvim) CreateNamespace(name string) (nsID int, err error) { // AddBufferHighlight and SetBufferVirtualText. // // Namespaces can be named or anonymous. -// If `name` matches an existing namespace, the associated id is returned. -// If `name` is an empty string a new, anonymous namespace is created. +// If "name" matches an existing namespace, the associated id is returned. +// If "name" is an empty string a new, anonymous namespace is created. // // The returns the namespace ID. func (b *Batch) CreateNamespace(name string, nsID *int) { @@ -1006,13 +1078,10 @@ func (b *Batch) Namespaces(namespaces *map[string]int) { // -1 is paste in a single call (i.e. without streaming). // // To `stream` a paste, call Paste sequentially with these `phase` args: -// // 1 // starts the paste (exactly once) -// // 2 // continues the paste (zero or more times) -// // 3 // ends the paste (exactly once) // @@ -1048,13 +1117,10 @@ func (v *Nvim) Paste(data string, crlf bool, phase int) (state bool, err error) // -1 is paste in a single call (i.e. without streaming). // // To `stream` a paste, call Paste sequentially with these `phase` args: -// // 1 // starts the paste (exactly once) -// // 2 // continues the paste (zero or more times) -// // 3 // ends the paste (exactly once) // @@ -1075,14 +1141,19 @@ func (b *Batch) Paste(data string, crlf bool, phase int, state *bool) { // // lines is readfile() style list of lines. // -// type is edit behavior: any getregtype() result, or: -// "b": blockwise-visual mode (may include width, e.g. "b3") -// "c": characterwise mode -// "l": linewise mode -// "" : guess by contents, see setreg() -// after is insert after cursor (like `p`), or before (like `P`). +// typ is edit behavior: any getregtype() result, or: +// "b" +// blockwise-visual mode (may include width, e.g. "b3") +// "c" +// characterwise mode +// "l" +// linewise mode +// "" +// guess by contents, see setreg(). +// +// After is insert after cursor (like `p`), or before (like `P`). // -// follow is place cursor at end of inserted text. +// follow arg is place cursor at end of inserted text. func (v *Nvim) Put(lines []string, typ string, after bool, follow bool) error { return v.call("nvim_put", nil, lines, typ, after, follow) } @@ -1093,14 +1164,19 @@ func (v *Nvim) Put(lines []string, typ string, after bool, follow bool) error { // // lines is readfile() style list of lines. // -// type is edit behavior: any getregtype() result, or: -// "b": blockwise-visual mode (may include width, e.g. "b3") -// "c": characterwise mode -// "l": linewise mode -// "" : guess by contents, see setreg() -// after is insert after cursor (like `p`), or before (like `P`). +// typ is edit behavior: any getregtype() result, or: +// "b" +// blockwise-visual mode (may include width, e.g. "b3") +// "c" +// characterwise mode +// "l" +// linewise mode +// "" +// guess by contents, see setreg(). // -// follow is place cursor at end of inserted text. +// After is insert after cursor (like `p`), or before (like `P`). +// +// follow arg is place cursor at end of inserted text. func (b *Batch) Put(lines []string, typ string, after bool, follow bool) { b.call("nvim_put", nil, lines, typ, after, follow) } @@ -1247,7 +1323,7 @@ func (b *Batch) KeyMap(mode string, maps *[]*Mapping) { // Right-hand-side {rhs} of the mapping. // // opts -// Optional parameters map. Accepts all :map-arguments as keys excluding but including noremap. +// Optional parameters map. Accepts all ":map-arguments" as keys excluding "buffer" but including "noremap". // Values are Booleans. Unknown key is an error. func (v *Nvim) SetKeyMap(mode string, lhs string, rhs string, opts map[string]bool) error { return v.call("nvim_set_keymap", nil, mode, lhs, rhs, opts) @@ -1271,7 +1347,7 @@ func (v *Nvim) SetKeyMap(mode string, lhs string, rhs string, opts map[string]bo // Right-hand-side {rhs} of the mapping. // // opts -// Optional parameters map. Accepts all :map-arguments as keys excluding but including noremap. +// Optional parameters map. Accepts all ":map-arguments" as keys excluding "buffer" but including "noremap". // Values are Booleans. Unknown key is an error. func (b *Batch) SetKeyMap(mode string, lhs string, rhs string, opts map[string]bool) { b.call("nvim_set_keymap", nil, mode, lhs, rhs, opts) @@ -1300,7 +1376,8 @@ func (b *Batch) DeleteKeyMap(mode string, lhs string) { // Commands gets a map of global (non-buffer-local) Ex commands. // Currently only user-commands are supported, not builtin Ex commands. // -// opts is optional parameters. Currently only supports {"builtin":false}. +// opts is optional parameters. Currently only supports: +// {"builtin":false} func (v *Nvim) Commands(opts map[string]interface{}) (commands map[string]*Command, err error) { err = v.call("nvim_get_commands", &commands, opts) return commands, err @@ -1309,20 +1386,25 @@ func (v *Nvim) Commands(opts map[string]interface{}) (commands map[string]*Comma // Commands gets a map of global (non-buffer-local) Ex commands. // Currently only user-commands are supported, not builtin Ex commands. // -// opts is optional parameters. Currently only supports {"builtin":false}. +// opts is optional parameters. Currently only supports: +// {"builtin":false} func (b *Batch) Commands(opts map[string]interface{}, commands *map[string]*Command) { b.call("nvim_get_commands", commands, opts) } // APIInfo returns a 2-tuple (Array), where item 0 is the current channel id and item -// 1 is the |api-metadata| map (Dictionary). +// 1 is the "pi-metadata|" map (Dictionary). +// +// Returns 2-tuple [{channel-id}, {api-metadata}]. func (v *Nvim) APIInfo() (apiInfo []interface{}, err error) { err = v.call("nvim_get_api_info", &apiInfo) return apiInfo, err } // APIInfo returns a 2-tuple (Array), where item 0 is the current channel id and item -// 1 is the |api-metadata| map (Dictionary). +// 1 is the "pi-metadata|" map (Dictionary). +// +// Returns 2-tuple [{channel-id}, {api-metadata}]. func (b *Batch) APIInfo(apiInfo *[]interface{}) { b.call("nvim_get_api_info", apiInfo) } @@ -1352,6 +1434,40 @@ func (b *Batch) SetClientInfo(name string, version *ClientVersion, typ string, m } // ChannelInfo get information about a channel. +// +// Rreturns Dictionary describing a channel, with these keys: +// +// "stream" +// The stream underlying the channel. value are: +// "stdio" +// stdin and stdout of this Nvim instance. +// "stderr" +// stderr of this Nvim instance. +// "socket" +// TCP/IP socket or named pipe. +// "job" +// job with communication over its stdio. +// +// "mode" +// How data received on the channel is interpreted. value are: +// "bytes" +// send and receive raw bytes. +// "terminal" +// A terminal instance interprets ASCII sequences. +// "rpc" +// RPC communication on the channel is active. +// +// "pty" +// Name of pseudoterminal, if one is used (optional). +// On a POSIX system, this will be a device path like /dev/pts/1. +// Even if the name is unknown, the key will still be present to indicate a pty is used. +// This is currently the case when using winpty on windows. +// +// "buffer" +// Buffer with connected |terminal| instance (optional). +// +// "client" +// Information about the client on the other end of the RPC channel, if it has added it using SetClientInfo() (optional). func (v *Nvim) ChannelInfo(channelID int) (channel *Channel, err error) { var result Channel err = v.call("nvim_get_chan_info", &result, channelID) @@ -1359,6 +1475,40 @@ func (v *Nvim) ChannelInfo(channelID int) (channel *Channel, err error) { } // ChannelInfo get information about a channel. +// +// Rreturns Dictionary describing a channel, with these keys: +// +// "stream" +// The stream underlying the channel. value are: +// "stdio" +// stdin and stdout of this Nvim instance. +// "stderr" +// stderr of this Nvim instance. +// "socket" +// TCP/IP socket or named pipe. +// "job" +// job with communication over its stdio. +// +// "mode" +// How data received on the channel is interpreted. value are: +// "bytes" +// send and receive raw bytes. +// "terminal" +// A terminal instance interprets ASCII sequences. +// "rpc" +// RPC communication on the channel is active. +// +// "pty" +// Name of pseudoterminal, if one is used (optional). +// On a POSIX system, this will be a device path like /dev/pts/1. +// Even if the name is unknown, the key will still be present to indicate a pty is used. +// This is currently the case when using winpty on windows. +// +// "buffer" +// Buffer with connected |terminal| instance (optional). +// +// "client" +// Information about the client on the other end of the RPC channel, if it has added it using SetClientInfo() (optional). func (b *Batch) ChannelInfo(channelID int, channel *Channel) { b.call("nvim_get_chan_info", channel, channelID) } @@ -1978,23 +2128,53 @@ func (b *Batch) BufferExtmarks(buffer Buffer, nsID int, start interface{}, end i // The opts arg is optional parameters. // // id -// ID of the extmark to edit. int type. +// ID of the extmark to edit. // // end_line -// Ending line of the mark, 0-based inclusive. int type. +// Ending line of the mark, 0-based inclusive. // // end_col -// Ending col of the mark, 0-based inclusive. int type. +// Ending col of the mark, 0-based inclusive. // // hl_group -// Name ar ID of the highlight group used to highlight this mark. string or int type. +// Name of the highlight group used to highlight this mark. // // virt_text -// virtual text to link to this mark. TextChunk type. +// Virtual text to link to this mark. +// +// virt_text_pos +// Positioning of virtual text. +// Possible values: +// "eol" +// right after eol character (default) +// "overlay" +// display over the specified column, without shifting the underlying text. +// +// virt_text_hide +// Hide the virtual text when the background text is selected or hidden due to horizontal scroll 'nowrap'. +// +// hl_mode +// Control how highlights are combined with the highlights of the text. Currently only affects +// virt_text highlights, but might affect "hl_group" in later versions. +// Possible values: +// "replace" +// only show the virt_text color. This is the default. +// "combine" +// combine with background text color +// "blend" +// blend with background text color. // // ephemeral -// For use with SetDecorationProvider callbacks. bool type. -// The mark will only be used for the current redraw cycle, and not be permantently stored in the buffer. +// For use with "nvim_set_decoration_provider" callbacks. The mark will only be used for the current redraw cycle, +// and not be permantently stored in the buffer. +// +// right_gravity +// Boolean that indicates the direction the extmark will be shifted in when new text is +// inserted (true for right, false for left). defaults to true. +// +// end_right_gravity +// Boolean that indicates the direction the extmark end position (if it exists) will be +// shifted in when new text is inserted (true for right, false for left). Defaults to false. func (v *Nvim) SetBufferExtmark(buffer Buffer, nsID int, line int, col int, opts map[string]interface{}) (id int, err error) { err = v.call("nvim_buf_set_extmark", &id, buffer, nsID, line, col, opts) return id, err @@ -2015,23 +2195,53 @@ func (v *Nvim) SetBufferExtmark(buffer Buffer, nsID int, line int, col int, opts // The opts arg is optional parameters. // // id -// ID of the extmark to edit. int type. +// ID of the extmark to edit. // // end_line -// Ending line of the mark, 0-based inclusive. int type. +// Ending line of the mark, 0-based inclusive. // // end_col -// Ending col of the mark, 0-based inclusive. int type. +// Ending col of the mark, 0-based inclusive. // // hl_group -// Name ar ID of the highlight group used to highlight this mark. string or int type. +// Name of the highlight group used to highlight this mark. // // virt_text -// virtual text to link to this mark. TextChunk type. +// Virtual text to link to this mark. +// +// virt_text_pos +// Positioning of virtual text. +// Possible values: +// "eol" +// right after eol character (default) +// "overlay" +// display over the specified column, without shifting the underlying text. +// +// virt_text_hide +// Hide the virtual text when the background text is selected or hidden due to horizontal scroll 'nowrap'. +// +// hl_mode +// Control how highlights are combined with the highlights of the text. Currently only affects +// virt_text highlights, but might affect "hl_group" in later versions. +// Possible values: +// "replace" +// only show the virt_text color. This is the default. +// "combine" +// combine with background text color +// "blend" +// blend with background text color. // // ephemeral -// For use with SetDecorationProvider callbacks. bool type. -// The mark will only be used for the current redraw cycle, and not be permantently stored in the buffer. +// For use with "nvim_set_decoration_provider" callbacks. The mark will only be used for the current redraw cycle, +// and not be permantently stored in the buffer. +// +// right_gravity +// Boolean that indicates the direction the extmark will be shifted in when new text is +// inserted (true for right, false for left). defaults to true. +// +// end_right_gravity +// Boolean that indicates the direction the extmark end position (if it exists) will be +// shifted in when new text is inserted (true for right, false for left). Defaults to false. func (b *Batch) SetBufferExtmark(buffer Buffer, nsID int, line int, col int, opts map[string]interface{}, id *int) { b.call("nvim_buf_set_extmark", id, buffer, nsID, line, col, opts) } diff --git a/nvim/api_def.go b/nvim/api_def.go index fa90aa44..b4d0be18 100644 --- a/nvim/api_def.go +++ b/nvim/api_def.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore // This file defines the Nvim remote API using Go syntax. Run the 'go generate' @@ -53,7 +54,7 @@ func HLByName(name string, rgb bool) (highlight HLAttrs) { // in addition the following keys are also recognized: // // default -// don't override existing definition, like `hi default`. +// don't override existing definition, like "hi default". func SetHighlight(nsID int, name string, val *HLAttrs) { name(nvim_set_hl) } @@ -89,7 +90,7 @@ func SetHighlightNameSpace(nsID int) { // Handle keys as if typed; otherwise they are handled as if coming from a mapping. // This matters for undo, opening folds, etc. // -// The escape_csi arg is whether the escape K_SPECIAL/CSI bytes in keys arg. +// The escapeCSI arg is whether the escape K_SPECIAL/CSI bytes in keys arg. func FeedKeys(keys, mode string, escapeCSI bool) { name(nvim_feedkeys) } @@ -106,6 +107,33 @@ func Input(keys string) (written int) { // // This API is non-blocking. It doesn't wait on any resulting action, but // queues the event to be processed soon by the event loop. +// +// The button arg is mouse button. One of +// "left" +// "right" +// "middle" +// "wheel" +// +// The action arg is for ordinary buttons. One of +// "press" +// "drag" +// "release" +// For the wheel, One of +// "up" +// "down +// "left" +// "right" +// +// The modifier arg is string of modifiers each represented by a single char. +// The same specifiers are used as for a key press, except +// that the "-" separator is optional, so "C-A-", "c-a" +// and "CA" can all be used to specify Ctrl+Alt+click. +// +// The grid arg is grid number if the client uses "ui-multigrid", else 0. +// +// The row arg is mouse row-position (zero-based, like redraw events). +// +// The col arg is mouse column-position (zero-based, like redraw events). func InputMouse(button, action, modifier string, grid, row, col int) { name(nvim_input_mouse) } @@ -121,6 +149,12 @@ func InputMouse(button, action, modifier string, grid, row, col int) { // -> '\x80ku' // // The returned sequences can be used as input to feedkeys. +// +// The fromPart arg is legacy Vim parameter. Usually true. +// +// The doLT arg is also translate . Ignored if "special" is false. +// +// The special arg is replace "keycodes", e.g. becomes a "\n" char. func ReplaceTermcodes(str string, fromPart, doLT, special bool) (input string) { name(nvim_replace_termcodes) } @@ -137,6 +171,8 @@ func CommandOutput(cmd string) (out string) { // // Dictionaries and Lists are recursively expanded. // +// The expr arg is VimL expression string. +// // :help expression func Eval(expr string) (result interface{}) { name(nvim_eval) @@ -318,7 +354,7 @@ func SetOption(name string, value interface{}) { // The chunks is a list of [text, hl_group] arrays, each representing a // text chunk with specified highlight. hl_group element can be omitted for no highlight. // -// If history is true, add to |message-history|. +// If history is true, add to "message-history". // // The opts arg is optional parameters. Reserved for future use. func Echo(chunks []TextChunk, history bool, opts map[string]interface{}) { @@ -380,8 +416,8 @@ func SetCurrentWindow(window Window) { // // The listed arg sets buflisted buffer opttion. // -// The scratch arg creates a "throwaway" |scratch-buffer| for temporary work (always 'nomodified'). -// Also sets 'nomodeline' on the buffer. +// The scratch arg creates a "throwaway" "scratch-buffer" for temporary work (always "nomodified"). +// Also sets "nomodeline" on the buffer. func CreateBuffer(listed, scratch bool) (buffer Buffer) { name(nvim_create_buf) } @@ -395,7 +431,7 @@ func CreateBuffer(listed, scratch bool) (buffer Buffer) { // External windows are only supported with multigrid GUIs, and are displayed as separate top-level windows. // // For a general overview of floats, see -// help api-floatwin +// :help api-floatwin // // Exactly one of `external` and `relative` must be specified. // The `width` and `height` of the new window must be specified. @@ -408,6 +444,7 @@ func CreateBuffer(listed, scratch bool) (buffer Buffer) { // // Out-of-bounds values, and configurations that make the float not fit inside // the main editor, are allowed. +// // The builtin implementation truncates values so floats are fully within the main screen grid. // External GUIs could let floats hover outside of the main window like a tooltip, but // this should not be used to specify arbitrary WM screen positions. @@ -436,8 +473,8 @@ func SetCurrentTabpage(tabpage Tabpage) { // AddBufferHighlight and SetBufferVirtualText. // // Namespaces can be named or anonymous. -// If `name` matches an existing namespace, the associated id is returned. -// If `name` is an empty string a new, anonymous namespace is created. +// If "name" matches an existing namespace, the associated id is returned. +// If "name" is an empty string a new, anonymous namespace is created. // // The returns the namespace ID. func CreateNamespace(name string) (nsID int) { @@ -471,13 +508,10 @@ func Namespaces() (namespaces map[string]int) { // -1 is paste in a single call (i.e. without streaming). // // To `stream` a paste, call Paste sequentially with these `phase` args: -// // 1 // starts the paste (exactly once) -// // 2 // continues the paste (zero or more times) -// // 3 // ends the paste (exactly once) // @@ -498,14 +532,19 @@ func Paste(data string, crlf bool, phase int) (state bool) { // // lines is readfile() style list of lines. // -// type is edit behavior: any getregtype() result, or: -// "b": blockwise-visual mode (may include width, e.g. "b3") -// "c": characterwise mode -// "l": linewise mode -// "" : guess by contents, see setreg() -// after is insert after cursor (like `p`), or before (like `P`). +// typ is edit behavior: any getregtype() result, or: +// "b" +// blockwise-visual mode (may include width, e.g. "b3") +// "c" +// characterwise mode +// "l" +// linewise mode +// "" +// guess by contents, see setreg(). +// +// After is insert after cursor (like `p`), or before (like `P`). // -// follow is place cursor at end of inserted text. +// follow arg is place cursor at end of inserted text. func Put(lines []string, typ string, after, follow bool) { name(nvim_put) } @@ -588,7 +627,7 @@ func KeyMap(mode string) (maps []*Mapping) { // Right-hand-side {rhs} of the mapping. // // opts -// Optional parameters map. Accepts all :map-arguments as keys excluding but including noremap. +// Optional parameters map. Accepts all ":map-arguments" as keys excluding "buffer" but including "noremap". // Values are Booleans. Unknown key is an error. func SetKeyMap(mode, lhs, rhs string, opts map[string]bool) { name(nvim_set_keymap) @@ -607,13 +646,16 @@ func DeleteKeyMap(mode, lhs string) { // Commands gets a map of global (non-buffer-local) Ex commands. // Currently only user-commands are supported, not builtin Ex commands. // -// opts is optional parameters. Currently only supports {"builtin":false}. +// opts is optional parameters. Currently only supports: +// {"builtin":false} func Commands(opts map[string]interface{}) (commands map[string]*Command) { name(nvim_get_commands) } // APIInfo returns a 2-tuple (Array), where item 0 is the current channel id and item -// 1 is the |api-metadata| map (Dictionary). +// 1 is the "pi-metadata|" map (Dictionary). +// +// Returns 2-tuple [{channel-id}, {api-metadata}]. func APIInfo() (apiInfo []interface{}) { name(nvim_get_api_info) } @@ -631,6 +673,40 @@ func SetClientInfo(name string, version *ClientVersion, typ string, methods map[ } // ChannelInfo get information about a channel. +// +// Rreturns Dictionary describing a channel, with these keys: +// +// "stream" +// The stream underlying the channel. value are: +// "stdio" +// stdin and stdout of this Nvim instance. +// "stderr" +// stderr of this Nvim instance. +// "socket" +// TCP/IP socket or named pipe. +// "job" +// job with communication over its stdio. +// +// "mode" +// How data received on the channel is interpreted. value are: +// "bytes" +// send and receive raw bytes. +// "terminal" +// A terminal instance interprets ASCII sequences. +// "rpc" +// RPC communication on the channel is active. +// +// "pty" +// Name of pseudoterminal, if one is used (optional). +// On a POSIX system, this will be a device path like /dev/pts/1. +// Even if the name is unknown, the key will still be present to indicate a pty is used. +// This is currently the case when using winpty on windows. +// +// "buffer" +// Buffer with connected |terminal| instance (optional). +// +// "client" +// Information about the client on the other end of the RPC channel, if it has added it using SetClientInfo() (optional). func ChannelInfo(channelID int) (channel Channel) { name(nvim_get_chan_info) returnPtr() @@ -945,23 +1021,53 @@ func BufferExtmarks(buffer Buffer, nsID int, start, end interface{}, opt map[str // The opts arg is optional parameters. // // id -// ID of the extmark to edit. int type. +// ID of the extmark to edit. // // end_line -// Ending line of the mark, 0-based inclusive. int type. +// Ending line of the mark, 0-based inclusive. // // end_col -// Ending col of the mark, 0-based inclusive. int type. +// Ending col of the mark, 0-based inclusive. // // hl_group -// Name ar ID of the highlight group used to highlight this mark. string or int type. +// Name of the highlight group used to highlight this mark. // // virt_text -// virtual text to link to this mark. TextChunk type. +// Virtual text to link to this mark. +// +// virt_text_pos +// Positioning of virtual text. +// Possible values: +// "eol" +// right after eol character (default) +// "overlay" +// display over the specified column, without shifting the underlying text. +// +// virt_text_hide +// Hide the virtual text when the background text is selected or hidden due to horizontal scroll 'nowrap'. +// +// hl_mode +// Control how highlights are combined with the highlights of the text. Currently only affects +// virt_text highlights, but might affect "hl_group" in later versions. +// Possible values: +// "replace" +// only show the virt_text color. This is the default. +// "combine" +// combine with background text color +// "blend" +// blend with background text color. // // ephemeral -// For use with SetDecorationProvider callbacks. bool type. -// The mark will only be used for the current redraw cycle, and not be permantently stored in the buffer. +// For use with "nvim_set_decoration_provider" callbacks. The mark will only be used for the current redraw cycle, +// and not be permantently stored in the buffer. +// +// right_gravity +// Boolean that indicates the direction the extmark will be shifted in when new text is +// inserted (true for right, false for left). defaults to true. +// +// end_right_gravity +// Boolean that indicates the direction the extmark end position (if it exists) will be +// shifted in when new text is inserted (true for right, false for left). Defaults to false. func SetBufferExtmark(buffer Buffer, nsID, line, col int, opts map[string]interface{}) (id int) { name(nvim_buf_set_extmark) } diff --git a/nvim/helpers.go b/nvim/helpers.go index b24b62c8..31bfd1d0 100644 --- a/nvim/helpers.go +++ b/nvim/helpers.go @@ -5,10 +5,10 @@ import ( ) type bufferReader struct { + err error v *Nvim - b Buffer lines [][]byte - err error + b Buffer } // compile time check whether the bufferReader implements io.Reader interface. diff --git a/nvim/nvim.go b/nvim/nvim.go index dd60579b..1ae066fc 100644 --- a/nvim/nvim.go +++ b/nvim/nvim.go @@ -28,13 +28,11 @@ var embedProcAttr *syscall.SysProcAttr type Nvim struct { ep *rpc.Endpoint - channelIDMu sync.Mutex - channelID int - // cmd is the child process, if any. - cmd *exec.Cmd - - serveCh chan error + cmd *exec.Cmd + serveCh chan error + channelID int + channelIDMu sync.Mutex // readMu prevents concurrent calls to read on the child process stdout pipe and // calls to cmd.Wait(). @@ -44,9 +42,8 @@ type Nvim struct { // Serve serves incoming mesages from the peer. Serve blocks until Nvim // disconnects or there is an error. // -// By default, the NewChildProcess and Dial functions start a goroutine to run -// Serve(). Callers of the low-level New function are responsible for running -// Serve(). +// By default, the NewChildProcess and Dial functions start a goroutine to run Serve(). +// Callers of the low-level New function are responsible for running Serve(). func (v *Nvim) Serve() error { v.readMu.Lock() defer v.readMu.Unlock() @@ -121,12 +118,12 @@ type ChildProcessOption struct { } type childProcessOptions struct { - args []string - command string ctx context.Context + logf func(string, ...interface{}) + command string dir string + args []string env []string - logf func(string, ...interface{}) serve bool } @@ -235,23 +232,24 @@ func NewChildProcess(options ...ChildProcessOption) (*Nvim, error) { // // Deprecated: Use ChildProcessOption instead. type EmbedOptions struct { - // Args specifies the command line arguments. Do not include the program - // name (the first argument) or the --embed option. - Args []string + // Logf log function for rpc.WithLogf. + Logf func(string, ...interface{}) // Dir specifies the working directory of the command. The working // directory in the current process is used if Dir is "". Dir string - // Env specifies the environment of the Nvim process. The current process - // environment is used if Env is nil. - Env []string - // Path is the path of the command to run. If Path = "", then // StartEmbeddedNvim searches for "nvim" on $PATH. Path string - Logf func(string, ...interface{}) + // Args specifies the command line arguments. Do not include the program + // name (the first argument) or the --embed option. + Args []string + + // Env specifies the environment of the Nvim process. The current process + // environment is used if Env is nil. + Env []string } // NewEmbedded starts an embedded instance of Nvim using the specified options. @@ -392,8 +390,8 @@ func (v *Nvim) ChannelID() int { return v.channelID } var info struct { - ChannelID int `msgpack:",array"` - Info interface{} + ChannelID int `msgpack:",array"` + Info interface{} `msgpack:"-"` } if err := v.ep.Call("nvim_get_api_info", &info); err != nil { // TODO: log error and exit process? @@ -427,12 +425,12 @@ func (v *Nvim) NewBatch() *Batch { // // A Batch does not support concurrent calls by the application. type Batch struct { + err error ep *rpc.Endpoint - buf bytes.Buffer enc *msgpack.Encoder sms []string results []interface{} - err error + buf bytes.Buffer } // Execute executes the API function calls in the batch. @@ -484,6 +482,7 @@ func (b *Batch) Execute() error { } } +// emptyArgs represents a empty interface slice which use to empty args. var emptyArgs = []interface{}{} func (b *Batch) call(sm string, result interface{}, args ...interface{}) { @@ -500,6 +499,7 @@ func (b *Batch) call(sm string, result interface{}, args ...interface{}) { b.err = b.enc.Encode(args) } +// batchArg represents a batch call arguments. type batchArg struct { n int p []byte @@ -516,12 +516,12 @@ func (a *batchArg) MarshalMsgPack(enc *msgpack.Encoder) error { // BatchError represents an error from a API function call in a Batch. type BatchError struct { + // Err is the error. + Err error + // Index is a zero-based index of the function call which resulted in the // error. Index int - - // Err is the error. - Err error } // Error implements the error interface. @@ -551,12 +551,25 @@ func (el ErrorList) Error() string { return el[0].Error() } -// Request makes a RPC request. +// Request makes a any RPC request. func (v *Nvim) Request(procedure string, result interface{}, args ...interface{}) error { return v.call(procedure, result, args...) } -// Call calls a vimscript function. +// Request makes a any RPC request atomically as a part of batch request. +func (b *Batch) Request(procedure string, result interface{}, args ...interface{}) { + b.call(procedure, result, args...) +} + +// Call calls a VimL function with the given arguments. +// +// On execution error: fails with VimL error, does not update v:errmsg. +// +// The fn arg is Function to call. +// +// The args arg is Function arguments packed in an Array. +// +// The result is result of the function call. func (v *Nvim) Call(fname string, result interface{}, args ...interface{}) error { if args == nil { args = []interface{}{} @@ -564,12 +577,15 @@ func (v *Nvim) Call(fname string, result interface{}, args ...interface{}) error return v.call("nvim_call_function", result, fname, args) } -// Request makes a RPC request atomically as a part of batch request. -func (b *Batch) Request(procedure string, result interface{}, args ...interface{}) { - b.call(procedure, result, args...) -} - -// Call calls a vimscript function. +// Call calls a VimL function with the given arguments. +// +// On execution error: fails with VimL error, does not update v:errmsg. +// +// The fn arg is Function to call. +// +// The args arg is Function arguments packed in an Array. +// +// The result is result of the function call. func (b *Batch) Call(fname string, result interface{}, args ...interface{}) { if args == nil { args = []interface{}{} @@ -577,7 +593,15 @@ func (b *Batch) Call(fname string, result interface{}, args ...interface{}) { b.call("nvim_call_function", result, fname, args) } -// CallDict calls a vimscript Dictionary function. +// CallDict calls a VimL Dictionary function with the given arguments. +// +// The dict arg is Dictionary, or String evaluating to a VimL "self" dict. +// +// The fn arg is name of the function defined on the VimL dict. +// +// The args arg is Function arguments packed in an Array. +// +// The result is result of the function call. func (v *Nvim) CallDict(dict []interface{}, fname string, result interface{}, args ...interface{}) error { if args == nil { args = []interface{}{} @@ -585,7 +609,15 @@ func (v *Nvim) CallDict(dict []interface{}, fname string, result interface{}, ar return v.call("nvim_call_dict_function", result, fname, dict, args) } -// CallDict calls a vimscript Dictionary function. +// CallDict calls a VimL Dictionary function with the given arguments. +// +// The dict arg is Dictionary, or String evaluating to a VimL "self" dict. +// +// The fn arg is name of the function defined on the VimL dict. +// +// The args arg is Function arguments packed in an Array. +// +// The result is result of the function call. func (b *Batch) CallDict(dict []interface{}, fname string, result interface{}, args ...interface{}) { if args == nil { args = []interface{}{} @@ -593,7 +625,13 @@ func (b *Batch) CallDict(dict []interface{}, fname string, result interface{}, a b.call("nvim_call_dict_function", result, fname, dict, args) } -// ExecLua executes a Lua block. +// ExecLua execute Lua code. +// +// The code arg is Lua code to execute. +// +// The args arg is arguments to the code. +// +// Parameters (if any) are available as "..." inside the chunk. The chunk can return a value. func (v *Nvim) ExecLua(code string, result interface{}, args ...interface{}) error { if args == nil { args = []interface{}{} @@ -601,7 +639,13 @@ func (v *Nvim) ExecLua(code string, result interface{}, args ...interface{}) err return v.call("nvim_exec_lua", result, code, args) } -// ExecLua executes a Lua block. +// ExecLua execute Lua code. +// +// The code arg is Lua code to execute. +// +// The args arg is arguments to the code. +// +// Parameters (if any) are available as "..." inside the chunk. The chunk can return a value. func (b *Batch) ExecLua(code string, result interface{}, args ...interface{}) { if args == nil { args = []interface{}{} diff --git a/nvim/types.go b/nvim/types.go index 0e916540..d5608613 100644 --- a/nvim/types.go +++ b/nvim/types.go @@ -433,10 +433,38 @@ type TextChunk struct { // Nvim will display the window with many UI options disabled. // This is useful when displaying a temporary float where the text should not be edited. // -// Disables `number`, `relativenumber`, `cursorline`, `cursorcolumn`, `foldcolumn`, `spell` and `list` options. -// And, `signcolumn` is changed to `auto` and `colorcolumn` is cleared. +// Disables "number", "relativenumber", "cursorline", "cursorcolumn", "foldcolumn", "spell" and "list" options. +// And, "signcolumn" is changed to "auto" and "colorcolumn" is cleared. // -// The end-of-buffer region is hidden by setting `eob` flag of `fillchars` to a space char, and clearing the EndOfBuffer region in `winhighlight`. +// The end-of-buffer region is hidden by setting "eob" flag of "fillchars" to a space char, and clearing the EndOfBuffer region in "winhighlight". +// +// border +// Style of (optional) window border. This can either be a string or an array. +// The string values are: +// "none" +// No border. This is the default. +// "single" +// A single line box. +// "double" +// A double line box. +// +// If it is an array it should be an array of eight items or any divisor of +// eight. The array will specifify the eight chars building up the border +// in a clockwise fashion starting with the top-left corner. +// As, an example, the double box style could be specified as: +// [ "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" ] +// +// If the number of chars are less than eight, they will be repeated. +// Thus an ASCII border could be specified as: +// [ "/", "-", "\\", "|" ] +// +// Or all chars the same as: +// [ "x" ] +// +// By default "FloatBorder" highlight is used which links to "VertSplit" +// when not defined. +// It could also be specified by character: +// [ {"+", "MyCorner"}, {"x", "MyBorder"} ] type WindowConfig struct { // Relative is the specifies the type of positioning method used for the floating window. Relative string `msgpack:"relative,omitempty"` @@ -470,6 +498,9 @@ type WindowConfig struct { // Style is the Configure the appearance of the window. Style string `msgpack:"style,omitempty"` + + // Border is the style of window border. + Border []string `msgpack:"border,omitempty"` } // ExtMark represents a extmarks type.