Skip to content

Commit ffc112b

Browse files
committed
nvim: fix some documentations
1 parent 717ac65 commit ffc112b

File tree

1 file changed

+97
-47
lines changed

1 file changed

+97
-47
lines changed

nvim/api_def.go

Lines changed: 97 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ package main
1414
// vim.c
1515

1616
// Exec executes Vimscript (multiline block of Ex-commands), like anonymous source.
17+
// Exec executes Vimscript (multiline block of Ex-commands), like anonymous |:source|.
18+
//
19+
// Unlike Command, this function supports heredocs, script-scope (s:), etc.
20+
//
21+
// On execution error: fails with VimL error, does not update v:errmsg.
1722
func Exec(src string, output bool) (out string) {
1823
name(nvim_exec)
1924
}
2025

21-
// Command executes a single ex command.
26+
// Command executes an ex-command.
2227
func Command(cmd string) {
2328
name(nvim_command)
2429
}
2530

26-
// HLByID gets a highlight definition by id.
31+
// HLByID gets a highlight definition by name.
2732
func HLByID(id int, rgb bool) (highlight HLAttrs) {
2833
name(nvim_get_hl_by_id)
2934
returnPtr()
@@ -34,7 +39,7 @@ func HLIDByName(name string) (highlightID int) {
3439
name(nvim_get_hl_id_by_name)
3540
}
3641

37-
// HLByName gets a highlight definition by name.
42+
// HLByName gets a highlight definition by id.
3843
func HLByName(name string, rgb bool) (highlight HLAttrs) {
3944
name(nvim_get_hl_by_name)
4045
returnPtr()
@@ -45,6 +50,11 @@ func HLByName(name string, rgb bool) (highlight HLAttrs) {
4550
// name arg is highlight group name, like ErrorMsg.
4651
//
4752
// val arg is highlight definiton map, like HLByName.
53+
//
54+
// in addition the following keys are also recognized:
55+
//
56+
// default
57+
// don't override existing definition, like `hi default`.
4858
func SetHighlight(nsID int, name string, val *HLAttrs) {
4959
name(nvim_set_hl)
5060
}
@@ -56,13 +66,21 @@ func SetHighlight(nsID int, name string, val *HLAttrs) {
5666
// To start with SetDecorationProvider on_win and on_line callbacks
5767
// are explicitly allowed to change the namespace during a redraw cycle.
5868
//
59-
// The `nsID` arg is the namespace to activate.
69+
// The nsID arg is the namespace to activate.
6070
func SetHighlightNameSpace(nsID int) {
6171
name(nvim_set_hl_ns)
6272
}
6373

64-
// FeedKeys Pushes keys to the Nvim user input buffer. Options can be a string
65-
// with the following character flags:
74+
// FeedKeys sends input-keys to Nvim, subject to various quirks controlled by mode flags.
75+
// This is a blocking call, unlike Input.
76+
//
77+
// On execution error: does not fail, but updates v:errmsg.
78+
//
79+
// If you need to input sequences like <C-o> use ReplaceTermcodes to
80+
// replace the termcodes and then pass the resulting string to nvim_feedkeys.
81+
// You'll also want to enable escape_csi.
82+
//
83+
// mode is following character flags:
6684
//
6785
// m
6886
// Remap keys. This is default.
@@ -71,28 +89,30 @@ func SetHighlightNameSpace(nsID int) {
7189
// t
7290
// Handle keys as if typed; otherwise they are handled as if coming from a mapping.
7391
// This matters for undo, opening folds, etc.
92+
//
93+
// The escape_csi arg is whether the escape K_SPECIAL/CSI bytes in keys arg.
7494
func FeedKeys(keys, mode string, escapeCSI bool) {
7595
name(nvim_feedkeys)
7696
}
7797

78-
// Input pushes bytes to the Nvim low level input buffer.
98+
// Input queues raw user-input.
7999
//
80-
// Unlike FeedKeys, this uses the lowest level input buffer and the call is not
81-
// deferred. It returns the number of bytes actually written(which can be less
82-
// than what was requested if the buffer is full).
100+
// Unlike FeedKeys, this uses a low-level input buffer and the call
101+
// is non-blocking (input is processed asynchronously by the eventloop).
83102
func Input(keys string) (written int) {
84103
name(nvim_input)
85104
}
86105

87106
// InputMouse send mouse event from GUI.
88107
//
89-
// The call is non-blocking. It doesn't wait on any resulting action, but
108+
// This API is non-blocking. It doesn't wait on any resulting action, but
90109
// queues the event to be processed soon by the event loop.
91110
func InputMouse(button, action, modifier string, grid, row, col int) {
92111
name(nvim_input_mouse)
93112
}
94113

95-
// ReplaceTermcodes replaces any terminal code strings by byte sequences.
114+
// ReplaceTermcodes replaces terminal codes and |keycodes| (<CR>, <Esc>, ...) in a string with
115+
// the internal representation.
96116
//
97117
// The returned sequences are Nvim's internal representation of keys, for example:
98118
//
@@ -114,66 +134,56 @@ func CommandOutput(cmd string) (out string) {
114134
deprecatedSince(7)
115135
}
116136

117-
// Eval evaluates the expression expr using the Vim internal expression
118-
// evaluator.
137+
// Eval evaluates a VimL expression.
138+
//
139+
// Dictionaries and Lists are recursively expanded.
119140
//
120141
// :help expression
121142
func Eval(expr string) (result interface{}) {
122143
name(nvim_eval)
123144
}
124145

125-
// SetPumBounds tells Nvim the geometry of the popumenu, to align floating windows with an
126-
// external popup menu.
127-
//
128-
// Note that this method is not to be confused with SetPumHeight,
129-
// which sets the number of visible items in the popup menu, while this
130-
// function sets the bounding box of the popup menu, including visual
131-
// elements such as borders and sliders.
146+
// StringWidth calculates the number of display cells occupied by `text`.
132147
//
133-
// Floats need not use the same font size, nor be anchored to exact grid corners, so one can set floating-point
134-
// numbers to the popup menu geometry.
135-
func SetPumBounds(width, height, row, col float64) {
136-
name(nvim_ui_pum_set_bounds)
137-
}
138-
139-
// StringWidth returns the number of display cells the string occupies. Tab is
140-
// counted as one cell.
148+
// <Tab> counts as one cell.
141149
func StringWidth(s string) (width int) {
142150
name(nvim_strwidth)
143151
}
144152

145-
// RuntimePaths returns a list of paths contained in the runtimepath option.
153+
// RuntimePaths gets the paths contained in 'runtimepath'.
146154
func RuntimePaths() (paths []string) {
147155
name(nvim_list_runtime_paths)
148156
}
149157

150158
// RuntimeFiles finds files in runtime directories and returns list of absolute paths to the found files.
151159
//
152160
// The name arg is can contain wildcards. For example,
161+
//
153162
// RuntimeFiles("colors/*.vim", true)
163+
//
154164
// will return all color scheme files.
155165
//
156166
// The all arg is whether to return all matches or only the first.
157167
func RuntimeFiles(name string, all bool) (files []string) {
158168
name(nvim_get_runtime_file)
159169
}
160170

161-
// SetCurrentDirectory changes the Vim working directory.
171+
// SetCurrentDirectory changes the global working directory.
162172
func SetCurrentDirectory(dir string) {
163173
name(nvim_set_current_dir)
164174
}
165175

166-
// CurrentLine gets the current line in the current buffer.
176+
// CurrentLine gets the current line.
167177
func CurrentLine() (line []byte) {
168178
name(nvim_get_current_line)
169179
}
170180

171-
// SetCurrentLine sets the current line in the current buffer.
181+
// SetCurrentLine sets the current line.
172182
func SetCurrentLine(line []byte) {
173183
name(nvim_set_current_line)
174184
}
175185

176-
// DeleteCurrentLine deletes the current line in the current buffer.
186+
// DeleteCurrentLine deletes the current line.
177187
func DeleteCurrentLine() {
178188
name(nvim_del_current_line)
179189
}
@@ -193,7 +203,7 @@ func DeleteVar(name string) {
193203
name(nvim_del_var)
194204
}
195205

196-
// VVar gets a vim (v:) variable.
206+
// VVar gets a v: variable.
197207
func VVar(name string) (value interface{}) {
198208
name(nvim_get_vvar)
199209
}
@@ -203,7 +213,7 @@ func SetVVar(name string, value interface{}) {
203213
name(nvim_set_vvar)
204214
}
205215

206-
// Option gets an option.
216+
// Option gets an option value string.
207217
func Option(name string) (option interface{}) {
208218
name(nvim_get_option)
209219
}
@@ -217,67 +227,89 @@ func Option(name string) (option interface{}) {
217227
//
218228
// name
219229
// Name of the option (like 'filetype').
230+
//
220231
// shortname
221232
// Shortened name of the option (like 'ft').
233+
//
222234
// type
223235
// type of option ("string", "number" or "boolean").
236+
//
224237
// default
225238
// The default value for the option.
239+
//
226240
// was_set
227241
// Whether the option was set.
242+
//
228243
// last_set_sid
229244
// Last set script id (if any).
245+
//
230246
// last_set_linenr
231247
// line number where option was set.
248+
//
232249
// last_set_chan
233250
// Channel where option was set (0 for local).
251+
//
234252
// scope
235253
// one of "global", "win", or "buf".
254+
//
236255
// global_local
237256
// whether win or buf option has a global value.
257+
//
238258
// commalist
239259
// List of comma separated values.
260+
//
240261
// flaglist
241262
// List of single char flags.
242263
func AllOptionsInfo() (opinfo OptionInfo) {
243264
name(nvim_get_all_options_info)
244265
returnPtr()
245266
}
246267

247-
// OptionInfo Gets the option information for one option.
268+
// OptionInfo gets the option information for one option.
248269
//
249270
// Resulting dictionary has keys:
250271
//
251272
// name
252273
// Name of the option (like 'filetype').
274+
//
253275
// shortname
254276
// Shortened name of the option (like 'ft').
277+
//
255278
// type
256279
// type of option ("string", "number" or "boolean").
280+
//
257281
// default
258282
// The default value for the option.
283+
//
259284
// was_set
260285
// Whether the option was set.
286+
//
261287
// last_set_sid
262288
// Last set script id (if any).
289+
//
263290
// last_set_linenr
264291
// line number where option was set.
292+
//
265293
// last_set_chan
266294
// Channel where option was set (0 for local).
295+
//
267296
// scope
268297
// one of "global", "win", or "buf".
298+
//
269299
// global_local
270300
// whether win or buf option has a global value.
301+
//
271302
// commalist
272303
// List of comma separated values.
304+
//
273305
// flaglist
274-
// List of single char flags.
306+
// List of single char flags.
275307
func OptionInfo(name string) (opinfo OptionInfo) {
276308
name(nvim_get_option_info)
277309
returnPtr()
278310
}
279311

280-
// SetOption sets an option.
312+
// SetOption sets an option value.
281313
func SetOption(name string, value interface{}) {
282314
name(nvim_set_option)
283315
}
@@ -506,10 +538,11 @@ func ColorMap() (colorMap map[string]int) {
506538
// Context gets a map of the current editor state.
507539
// This API still under development.
508540
//
509-
// The `opts` is optional parameters.
541+
// The opts arg is optional parameters.
542+
// Key is `types`.
543+
//
544+
// List of context-types to gather, or empty for `all` context.
510545
//
511-
// types
512-
// List of context-types to gather, or empty for all context.
513546
// regs
514547
// jumps
515548
// bufs
@@ -525,7 +558,7 @@ func LoadContext(dict map[string]interface{}) (contextMap interface{}) {
525558
name(nvim_load_context)
526559
}
527560

528-
// Mode gets Nvim's current mode.
561+
// Mode gets the current mode.
529562
func Mode() (mode Mode) {
530563
name(nvim_get_mode)
531564
returnPtr()
@@ -586,11 +619,14 @@ func APIInfo() (apiInfo []interface{}) {
586619
name(nvim_get_api_info)
587620
}
588621

589-
// SetClientInfo identify the client for nvim.
622+
// SetClientInfo self-identifies the client.
623+
//
624+
// The client/plugin/application should call this after connecting, to provide
625+
// hints about its identity and purpose, for debugging and orchestration.
590626
//
591-
// Can be called more than once, but subsequent calls will remove earlier info,
592-
// which should be resent if it is still valid. (This could happen if a library first identifies the channel,
593-
// and a plugin using that library later overrides that info.)
627+
// Can be called more than once; the caller should merge old info if
628+
// appropriate. Example: library first identifies the channel, then a plugin
629+
// using that library later identifies itself.
594630
func SetClientInfo(name string, version *ClientVersion, typ string, methods map[string]*ClientMethod, attributes ClientAttributes) {
595631
name(nvim_set_client_info)
596632
}
@@ -1213,3 +1249,17 @@ func TryResizeUIGrid(grid, width, height int) {
12131249
func SetPumHeight(height int) {
12141250
name(nvim_ui_pum_set_height)
12151251
}
1252+
1253+
// SetPumBounds tells Nvim the geometry of the popumenu, to align floating windows with an
1254+
// external popup menu.
1255+
//
1256+
// Note that this method is not to be confused with SetPumHeight,
1257+
// which sets the number of visible items in the popup menu, while this
1258+
// function sets the bounding box of the popup menu, including visual
1259+
// elements such as borders and sliders.
1260+
//
1261+
// Floats need not use the same font size, nor be anchored to exact grid corners, so one can set floating-point
1262+
// numbers to the popup menu geometry.
1263+
func SetPumBounds(width, height, row, col float64) {
1264+
name(nvim_ui_pum_set_bounds)
1265+
}

0 commit comments

Comments
 (0)