Merge #5523 from justinmk/test-system

test: system(): Avoid indeterminism. Also adjust docs.
This commit is contained in:
Justin M. Keyes 2016-10-23 00:33:51 +02:00 committed by GitHub
commit fdc48cad7d
6 changed files with 327 additions and 301 deletions

View File

@ -28,9 +28,9 @@
/// Gets the buffer line count /// Gets the buffer line count
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The line count /// @return Line count
Integer nvim_buf_line_count(Buffer buffer, Error *err) Integer nvim_buf_line_count(Buffer buffer, Error *err)
{ {
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
@ -50,10 +50,10 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err)
/// for negative indices use /// for negative indices use
/// "nvim_buf_get_lines(buffer, index-1, index, true)" /// "nvim_buf_get_lines(buffer, index-1, index, true)"
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param index The line index /// @param index Line index
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The line string /// @return Line string
String buffer_get_line(Buffer buffer, Integer index, Error *err) String buffer_get_line(Buffer buffer, Integer index, Error *err)
{ {
String rv = { .size = 0 }; String rv = { .size = 0 };
@ -78,10 +78,10 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
/// for negative indices use /// for negative indices use
/// "nvim_buf_set_lines(buffer, index-1, index, true, [line])" /// "nvim_buf_set_lines(buffer, index-1, index, true, [line])"
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param index The line index /// @param index Line index
/// @param line The new line. /// @param line Contents of the new line
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void buffer_set_line(Buffer buffer, Integer index, String line, Error *err) void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
{ {
Object l = STRING_OBJ(line); Object l = STRING_OBJ(line);
@ -97,9 +97,9 @@ void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
/// "nvim_buf_set_lines(buffer, index, index+1, true, [])" /// "nvim_buf_set_lines(buffer, index, index+1, true, [])"
/// for negative indices use /// for negative indices use
/// "nvim_buf_set_lines(buffer, index-1, index, true, [])" /// "nvim_buf_set_lines(buffer, index-1, index, true, [])"
/// @param buffer The buffer handle /// @param buffer buffer handle
/// @param index The line index /// @param index line index
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void buffer_del_line(Buffer buffer, Integer index, Error *err) void buffer_del_line(Buffer buffer, Integer index, Error *err)
{ {
Array array = ARRAY_DICT_INIT; Array array = ARRAY_DICT_INIT;
@ -113,13 +113,13 @@ void buffer_del_line(Buffer buffer, Integer index, Error *err)
/// where newstart = start + int(not include_start) - int(start < 0) /// where newstart = start + int(not include_start) - int(start < 0)
/// newend = end + int(include_end) - int(end < 0) /// newend = end + int(include_end) - int(end < 0)
/// int(bool) = 1 if bool is true else 0 /// int(bool) = 1 if bool is true else 0
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param start The first line index /// @param start First line index
/// @param end The last line index /// @param end Last line index
/// @param include_start True if the slice includes the `start` parameter /// @param include_start True if the slice includes the `start` parameter
/// @param include_end True if the slice includes the `end` parameter /// @param include_end True if the slice includes the `end` parameter
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return An array of lines /// @return Array of lines
ArrayOf(String) buffer_get_line_slice(Buffer buffer, ArrayOf(String) buffer_get_line_slice(Buffer buffer,
Integer start, Integer start,
Integer end, Integer end,
@ -142,12 +142,12 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer,
/// Out-of-bounds indices are clamped to the nearest valid value, unless /// Out-of-bounds indices are clamped to the nearest valid value, unless
/// `strict_indexing` is set. /// `strict_indexing` is set.
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param start The first line index /// @param start First line index
/// @param end The last line index (exclusive) /// @param end Last line index (exclusive)
/// @param strict_indexing whether out-of-bounds should be an error. /// @param strict_indexing Whether out-of-bounds should be an error.
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return An array of lines /// @return Array of lines
ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id, ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
Buffer buffer, Buffer buffer,
Integer start, Integer start,
@ -219,14 +219,14 @@ end:
/// newend = end + int(include_end) + int(end < 0) /// newend = end + int(include_end) + int(end < 0)
/// int(bool) = 1 if bool is true else 0 /// int(bool) = 1 if bool is true else 0
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param start The first line index /// @param start First line index
/// @param end The last line index /// @param end Last line index
/// @param include_start True if the slice includes the `start` parameter /// @param include_start True if the slice includes the `start` parameter
/// @param include_end True if the slice includes the `end` parameter /// @param include_end True if the slice includes the `end` parameter
/// @param replacement An array of lines to use as replacement(A 0-length /// @param replacement Array of lines to use as replacement (0-length
// array will simply delete the line range) // array will delete the line range)
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void buffer_set_line_slice(Buffer buffer, void buffer_set_line_slice(Buffer buffer,
Integer start, Integer start,
Integer end, Integer end,
@ -253,12 +253,12 @@ void buffer_set_line_slice(Buffer buffer,
/// Out-of-bounds indices are clamped to the nearest valid value, unless /// Out-of-bounds indices are clamped to the nearest valid value, unless
/// `strict_indexing` is set. /// `strict_indexing` is set.
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param start The first line index /// @param start First line index
/// @param end The last line index (exclusive) /// @param end Last line index (exclusive)
/// @param strict_indexing whether out-of-bounds should be an error. /// @param strict_indexing Whether out-of-bounds should be an error.
/// @param replacement An array of lines to use as replacement /// @param replacement Array of lines to use as replacement
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_buf_set_lines(uint64_t channel_id, void nvim_buf_set_lines(uint64_t channel_id,
Buffer buffer, Buffer buffer,
Integer start, Integer start,
@ -411,10 +411,10 @@ end:
/// Gets a buffer-scoped (b:) variable. /// Gets a buffer-scoped (b:) variable.
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The variable value /// @return Variable value
Object nvim_buf_get_var(Buffer buffer, String name, Error *err) Object nvim_buf_get_var(Buffer buffer, String name, Error *err)
{ {
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
@ -428,10 +428,10 @@ Object nvim_buf_get_var(Buffer buffer, String name, Error *err)
/// Sets a buffer-scoped (b:) variable /// Sets a buffer-scoped (b:) variable
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param name The variable name /// @param name Variable name
/// @param value The variable value /// @param value Variable value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_buf_set_var(Buffer buffer, String name, Object value, Error *err) void nvim_buf_set_var(Buffer buffer, String name, Object value, Error *err)
{ {
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
@ -445,9 +445,9 @@ void nvim_buf_set_var(Buffer buffer, String name, Object value, Error *err)
/// Removes a buffer-scoped (b:) variable /// Removes a buffer-scoped (b:) variable
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_buf_del_var(Buffer buffer, String name, Error *err) void nvim_buf_del_var(Buffer buffer, String name, Error *err)
{ {
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
@ -463,11 +463,11 @@ void nvim_buf_del_var(Buffer buffer, String name, Error *err)
/// ///
/// @deprecated /// @deprecated
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param name The variable name /// @param name Variable name
/// @param value The variable value /// @param value Variable value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The old value or nil if there was no previous value. /// @return Old value or nil if there was no previous value.
/// ///
/// @warning It may return nil if there was no previous value /// @warning It may return nil if there was no previous value
/// or if previous value was `v:null`. /// or if previous value was `v:null`.
@ -486,10 +486,10 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err)
/// ///
/// @deprecated /// @deprecated
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The old value /// @return Old value
Object buffer_del_var(Buffer buffer, String name, Error *err) Object buffer_del_var(Buffer buffer, String name, Error *err)
{ {
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
@ -504,10 +504,10 @@ Object buffer_del_var(Buffer buffer, String name, Error *err)
/// Gets a buffer option value /// Gets a buffer option value
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param name The option name /// @param name Option name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The option value /// @return Option value
Object nvim_buf_get_option(Buffer buffer, String name, Error *err) Object nvim_buf_get_option(Buffer buffer, String name, Error *err)
{ {
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
@ -519,13 +519,13 @@ Object nvim_buf_get_option(Buffer buffer, String name, Error *err)
return get_option_from(buf, SREQ_BUF, name, err); return get_option_from(buf, SREQ_BUF, name, err);
} }
/// Sets a buffer option value. Passing 'nil' as value deletes the option(only /// Sets a buffer option value. Passing 'nil' as value deletes the option (only
/// works if there's a global fallback) /// works if there's a global fallback)
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param name The option name /// @param name Option name
/// @param value The option value /// @param value Option value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_buf_set_option(Buffer buffer, String name, Object value, Error *err) void nvim_buf_set_option(Buffer buffer, String name, Object value, Error *err)
{ {
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
@ -539,9 +539,9 @@ void nvim_buf_set_option(Buffer buffer, String name, Object value, Error *err)
/// Gets the buffer number /// Gets the buffer number
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The buffer number /// @return Buffer number
Integer nvim_buf_get_number(Buffer buffer, Error *err) Integer nvim_buf_get_number(Buffer buffer, Error *err)
{ {
Integer rv = 0; Integer rv = 0;
@ -556,9 +556,9 @@ Integer nvim_buf_get_number(Buffer buffer, Error *err)
/// Gets the full file name for the buffer /// Gets the full file name for the buffer
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The buffer name /// @return Buffer name
String nvim_buf_get_name(Buffer buffer, Error *err) String nvim_buf_get_name(Buffer buffer, Error *err)
{ {
String rv = STRING_INIT; String rv = STRING_INIT;
@ -573,9 +573,9 @@ String nvim_buf_get_name(Buffer buffer, Error *err)
/// Sets the full file name for a buffer /// Sets the full file name for a buffer
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param name The buffer name /// @param name Buffer name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_buf_set_name(Buffer buffer, String name, Error *err) void nvim_buf_set_name(Buffer buffer, String name, Error *err)
{ {
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
@ -603,7 +603,7 @@ void nvim_buf_set_name(Buffer buffer, String name, Error *err)
/// Checks if a buffer is valid /// Checks if a buffer is valid
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @return true if the buffer is valid, false otherwise /// @return true if the buffer is valid, false otherwise
Boolean nvim_buf_is_valid(Buffer buffer) Boolean nvim_buf_is_valid(Buffer buffer)
{ {
@ -615,11 +615,11 @@ Boolean nvim_buf_is_valid(Buffer buffer)
/// ///
/// @deprecated use nvim_buf_set_lines(buffer, lnum, lnum, true, lines) /// @deprecated use nvim_buf_set_lines(buffer, lnum, lnum, true, lines)
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param lnum Insert the lines after `lnum`. If negative, it will append /// @param lnum Insert the lines after `lnum`. If negative, appends to
/// to the end of the buffer. /// the end of the buffer.
/// @param lines An array of lines /// @param lines Array of lines
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void buffer_insert(Buffer buffer, void buffer_insert(Buffer buffer,
Integer lnum, Integer lnum,
ArrayOf(String) lines, ArrayOf(String) lines,
@ -632,10 +632,10 @@ void buffer_insert(Buffer buffer,
/// Return a tuple (row,col) representing the position of the named mark /// Return a tuple (row,col) representing the position of the named mark
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param name The mark's name /// @param name Mark name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The (row, col) tuple /// @return (row, col) tuple
ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err) ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err)
{ {
Array rv = ARRAY_DICT_INIT; Array rv = ARRAY_DICT_INIT;
@ -694,15 +694,15 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err)
/// request an unique src_id at initialization, and later asynchronously add and /// request an unique src_id at initialization, and later asynchronously add and
/// clear highlights in response to buffer changes. /// clear highlights in response to buffer changes.
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param src_id Source group to use or 0 to use a new group, /// @param src_id Source group to use or 0 to use a new group,
/// or -1 for ungrouped highlight /// or -1 for ungrouped highlight
/// @param hl_group Name of the highlight group to use /// @param hl_group Name of the highlight group to use
/// @param line The line to highlight /// @param line Line to highlight
/// @param col_start Start of range of columns to highlight /// @param col_start Start of range of columns to highlight
/// @param col_end End of range of columns to highlight, /// @param col_end End of range of columns to highlight,
/// or -1 to highlight to end of line /// or -1 to highlight to end of line
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The src_id that was used /// @return The src_id that was used
Integer nvim_buf_add_highlight(Buffer buffer, Integer nvim_buf_add_highlight(Buffer buffer,
Integer src_id, Integer src_id,
@ -740,12 +740,12 @@ Integer nvim_buf_add_highlight(Buffer buffer,
/// To clear a source group in the entire buffer, pass in 1 and -1 to /// To clear a source group in the entire buffer, pass in 1 and -1 to
/// line_start and line_end respectively. /// line_start and line_end respectively.
/// ///
/// @param buffer The buffer handle /// @param buffer Buffer handle
/// @param src_id Highlight source group to clear, or -1 to clear all groups. /// @param src_id Highlight source group to clear, or -1 to clear all.
/// @param line_start Start of range of lines to clear /// @param line_start Start of range of lines to clear
/// @param line_end End of range of lines to clear (exclusive) /// @param line_end End of range of lines to clear (exclusive) or -1 to clear
/// or -1 to clear to end of file. /// to end of file.
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_buf_clear_highlight(Buffer buffer, void nvim_buf_clear_highlight(Buffer buffer,
Integer src_id, Integer src_id,
Integer line_start, Integer line_start,

View File

@ -11,9 +11,9 @@
/// Gets the windows in a tabpage /// Gets the windows in a tabpage
/// ///
/// @param tabpage The tabpage /// @param tabpage Tabpage
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The windows in `tabpage` /// @return List of windows in `tabpage`
ArrayOf(Window) nvim_tabpage_list_wins(Tabpage tabpage, Error *err) ArrayOf(Window) nvim_tabpage_list_wins(Tabpage tabpage, Error *err)
{ {
Array rv = ARRAY_DICT_INIT; Array rv = ARRAY_DICT_INIT;
@ -39,10 +39,10 @@ ArrayOf(Window) nvim_tabpage_list_wins(Tabpage tabpage, Error *err)
/// Gets a tab-scoped (t:) variable /// Gets a tab-scoped (t:) variable
/// ///
/// @param tabpage The tab page handle /// @param tabpage Tabpage handle
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The variable value /// @return Variable value
Object nvim_tabpage_get_var(Tabpage tabpage, String name, Error *err) Object nvim_tabpage_get_var(Tabpage tabpage, String name, Error *err)
{ {
tabpage_T *tab = find_tab_by_handle(tabpage, err); tabpage_T *tab = find_tab_by_handle(tabpage, err);
@ -56,10 +56,10 @@ Object nvim_tabpage_get_var(Tabpage tabpage, String name, Error *err)
/// Sets a tab-scoped (t:) variable /// Sets a tab-scoped (t:) variable
/// ///
/// @param tabpage handle /// @param tabpage Tabpage handle
/// @param name The variable name /// @param name Variable name
/// @param value The variable value /// @param value Variable value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_tabpage_set_var(Tabpage tabpage, void nvim_tabpage_set_var(Tabpage tabpage,
String name, String name,
Object value, Object value,
@ -76,9 +76,9 @@ void nvim_tabpage_set_var(Tabpage tabpage,
/// Removes a tab-scoped (t:) variable /// Removes a tab-scoped (t:) variable
/// ///
/// @param tabpage handle /// @param tabpage Tabpage handle
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_tabpage_del_var(Tabpage tabpage, String name, Error *err) void nvim_tabpage_del_var(Tabpage tabpage, String name, Error *err)
{ {
tabpage_T *tab = find_tab_by_handle(tabpage, err); tabpage_T *tab = find_tab_by_handle(tabpage, err);
@ -94,11 +94,11 @@ void nvim_tabpage_del_var(Tabpage tabpage, String name, Error *err)
/// ///
/// @deprecated /// @deprecated
/// ///
/// @param tabpage handle /// @param tabpage Tabpage handle
/// @param name The variable name /// @param name Variable name
/// @param value The variable value /// @param value Variable value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The old value or nil if there was no previous value. /// @return Old value or nil if there was no previous value.
/// ///
/// @warning It may return nil if there was no previous value /// @warning It may return nil if there was no previous value
/// or if previous value was `v:null`. /// or if previous value was `v:null`.
@ -117,10 +117,10 @@ Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err)
/// ///
/// @deprecated /// @deprecated
/// ///
/// @param tabpage handle /// @param tabpage Tabpage handle
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The old value /// @return Old value
Object tabpage_del_var(Tabpage tabpage, String name, Error *err) Object tabpage_del_var(Tabpage tabpage, String name, Error *err)
{ {
tabpage_T *tab = find_tab_by_handle(tabpage, err); tabpage_T *tab = find_tab_by_handle(tabpage, err);
@ -132,11 +132,11 @@ Object tabpage_del_var(Tabpage tabpage, String name, Error *err)
return dict_set_value(tab->tp_vars, name, NIL, true, true, err); return dict_set_value(tab->tp_vars, name, NIL, true, true, err);
} }
/// Gets the current window in a tab page /// Gets the current window in a tabpage
/// ///
/// @param tabpage The tab page handle /// @param tabpage Tabpage handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The Window handle /// @return Window handle
Window nvim_tabpage_get_win(Tabpage tabpage, Error *err) Window nvim_tabpage_get_win(Tabpage tabpage, Error *err)
{ {
Window rv = 0; Window rv = 0;
@ -159,11 +159,11 @@ Window nvim_tabpage_get_win(Tabpage tabpage, Error *err)
} }
} }
/// Gets the tab page number /// Gets the tabpage number
/// ///
/// @param tabpage The tabpage handle /// @param tabpage Tabpage handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The tabpage number /// @return Tabpage number
Integer nvim_tabpage_get_number(Tabpage tabpage, Error *err) Integer nvim_tabpage_get_number(Tabpage tabpage, Error *err)
{ {
Integer rv = 0; Integer rv = 0;
@ -176,10 +176,10 @@ Integer nvim_tabpage_get_number(Tabpage tabpage, Error *err)
return tabpage_index(tab); return tabpage_index(tab);
} }
/// Checks if a tab page is valid /// Checks if a tabpage is valid
/// ///
/// @param tabpage The tab page handle /// @param tabpage Tabpage handle
/// @return true if the tab page is valid, false otherwise /// @return true if the tabpage is valid, false otherwise
Boolean nvim_tabpage_is_valid(Tabpage tabpage) Boolean nvim_tabpage_is_valid(Tabpage tabpage)
{ {
Error stub = ERROR_INIT; Error stub = ERROR_INIT;

View File

@ -33,24 +33,26 @@
# include "api/vim.c.generated.h" # include "api/vim.c.generated.h"
#endif #endif
/// Executes an ex-mode command str /// Executes an ex-command.
/// On VimL error: Returns the VimL error and updates v:errmsg.
/// ///
/// @param str The command str /// @param command Ex-command string
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details (including actual VimL error), if any
void nvim_command(String str, Error *err) void nvim_command(String command, Error *err)
{ {
// Run the command // Run the command
try_start(); try_start();
do_cmdline_cmd(str.data); do_cmdline_cmd(command.data);
update_screen(VALID); update_screen(VALID);
try_end(err); try_end(err);
} }
/// Passes input keys to Neovim /// Passes input keys to Nvim.
/// On VimL error: Does not fail, but updates v:errmsg.
/// ///
/// @param keys to be typed /// @param keys to be typed
/// @param mode specifies the mapping options /// @param mode mapping options
/// @param escape_csi the string needs escaping for K_SPECIAL/CSI bytes /// @param escape_csi If true, escape K_SPECIAL/CSI bytes in `keys`
/// @see feedkeys() /// @see feedkeys()
/// @see vim_strsave_escape_csi /// @see vim_strsave_escape_csi
void nvim_feedkeys(String keys, String mode, Boolean escape_csi) void nvim_feedkeys(String keys, String mode, Boolean escape_csi)
@ -102,13 +104,15 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi)
} }
} }
/// Passes input keys to Neovim. Unlike `nvim_feedkeys`, this will use a /// Passes keys to Nvim as raw user-input.
/// lower-level input buffer and the call is not deferred. /// On VimL error: Does not fail, but updates v:errmsg.
/// This is the most reliable way to emulate real user input. ///
/// Unlike `nvim_feedkeys`, this uses a lower-level input buffer and the call
/// is not deferred. This is the most reliable way to emulate real user input.
/// ///
/// @param keys to be typed /// @param keys to be typed
/// @return The number of bytes actually written, which can be lower than /// @return Number of bytes actually written (can be fewer than
/// requested if the buffer becomes full. /// requested if the buffer becomes full).
Integer nvim_input(String keys) Integer nvim_input(String keys)
FUNC_API_ASYNC FUNC_API_ASYNC
{ {
@ -152,19 +156,19 @@ String nvim_command_output(String str, Error *err)
return cstr_to_string((char *)get_vim_var_str(VV_COMMAND_OUTPUT)); return cstr_to_string((char *)get_vim_var_str(VV_COMMAND_OUTPUT));
} }
/// Evaluates the expression str using the Vim internal expression /// Evaluates a VimL expression (:help expression).
/// evaluator (see |expression|). /// Dictionaries and Lists are recursively expanded.
/// Dictionaries and lists are recursively expanded. /// On VimL error: Returns a generic error; v:errmsg is not updated.
/// ///
/// @param str The expression str /// @param expr VimL expression string
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The expanded object /// @return Evaluation result or expanded object
Object nvim_eval(String str, Error *err) Object nvim_eval(String expr, Error *err)
{ {
Object rv = OBJECT_INIT; Object rv = OBJECT_INIT;
// Evaluate the expression // Evaluate the expression
try_start(); try_start();
typval_T *expr_result = eval_expr((char_u *) str.data, NULL); typval_T *expr_result = eval_expr((char_u *)expr.data, NULL);
if (!expr_result) { if (!expr_result) {
api_set_error(err, Exception, _("Failed to evaluate expression")); api_set_error(err, Exception, _("Failed to evaluate expression"));
@ -180,11 +184,12 @@ Object nvim_eval(String str, Error *err)
return rv; return rv;
} }
/// Call the given function with the given arguments stored in an array. /// Calls a VimL function with the given arguments.
/// On VimL error: Returns a generic error; v:errmsg is not updated.
/// ///
/// @param fname Function to call /// @param fname Function to call
/// @param args Functions arguments packed in an Array /// @param args Function arguments packed in an Array
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return Result of the function call /// @return Result of the function call
Object nvim_call_function(String fname, Array args, Error *err) Object nvim_call_function(String fname, Array args, Error *err)
{ {
@ -229,12 +234,12 @@ free_vim_args:
return rv; return rv;
} }
/// Calculates the number of display cells `str` occupies, tab is counted as /// Calculates the number of display cells occupied by `text`.
/// one cell. /// <Tab> counts as one cell.
/// ///
/// @param str Some text /// @param text Some text
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The number of cells /// @return Number of cells
Integer nvim_strwidth(String str, Error *err) Integer nvim_strwidth(String str, Error *err)
{ {
if (str.size > INT_MAX) { if (str.size > INT_MAX) {
@ -245,9 +250,9 @@ Integer nvim_strwidth(String str, Error *err)
return (Integer) mb_string2cells((char_u *) str.data); return (Integer) mb_string2cells((char_u *) str.data);
} }
/// Gets a list of paths contained in 'runtimepath' /// Gets the paths contained in 'runtimepath'.
/// ///
/// @return The list of paths /// @return List of paths
ArrayOf(String) nvim_list_runtime_paths(void) ArrayOf(String) nvim_list_runtime_paths(void)
{ {
Array rv = ARRAY_DICT_INIT; Array rv = ARRAY_DICT_INIT;
@ -285,10 +290,10 @@ ArrayOf(String) nvim_list_runtime_paths(void)
return rv; return rv;
} }
/// Changes Vim working directory /// Changes the global working directory.
/// ///
/// @param dir The new working directory /// @param dir Directory path
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_set_current_dir(String dir, Error *err) void nvim_set_current_dir(String dir, Error *err)
{ {
if (dir.size >= MAXPATHL) { if (dir.size >= MAXPATHL) {
@ -315,8 +320,8 @@ void nvim_set_current_dir(String dir, Error *err)
/// Gets the current line /// Gets the current line
/// ///
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The current line string /// @return Current line string
String nvim_get_current_line(Error *err) String nvim_get_current_line(Error *err)
{ {
return buffer_get_line(curbuf->handle, curwin->w_cursor.lnum - 1, err); return buffer_get_line(curbuf->handle, curwin->w_cursor.lnum - 1, err);
@ -324,8 +329,8 @@ String nvim_get_current_line(Error *err)
/// Sets the current line /// Sets the current line
/// ///
/// @param line The line contents /// @param line Line contents
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_set_current_line(String line, Error *err) void nvim_set_current_line(String line, Error *err)
{ {
buffer_set_line(curbuf->handle, curwin->w_cursor.lnum - 1, line, err); buffer_set_line(curbuf->handle, curwin->w_cursor.lnum - 1, line, err);
@ -333,36 +338,36 @@ void nvim_set_current_line(String line, Error *err)
/// Deletes the current line /// Deletes the current line
/// ///
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_del_current_line(Error *err) void nvim_del_current_line(Error *err)
{ {
buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, err); buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, err);
} }
/// Gets a global variable /// Gets a global (g:) variable
/// ///
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The variable value /// @return Variable value
Object nvim_get_var(String name, Error *err) Object nvim_get_var(String name, Error *err)
{ {
return dict_get_value(&globvardict, name, err); return dict_get_value(&globvardict, name, err);
} }
/// Sets a global variable /// Sets a global (g:) variable
/// ///
/// @param name The variable name /// @param name Variable name
/// @param value The variable value /// @param value Variable value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_set_var(String name, Object value, Error *err) void nvim_set_var(String name, Object value, Error *err)
{ {
dict_set_value(&globvardict, name, value, false, false, err); dict_set_value(&globvardict, name, value, false, false, err);
} }
/// Removes a global variable /// Removes a global (g:) variable
/// ///
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_del_var(String name, Error *err) void nvim_del_var(String name, Error *err)
{ {
dict_set_value(&globvardict, name, NIL, true, false, err); dict_set_value(&globvardict, name, NIL, true, false, err);
@ -372,10 +377,10 @@ void nvim_del_var(String name, Error *err)
/// ///
/// @deprecated /// @deprecated
/// ///
/// @param name The variable name /// @param name Variable name
/// @param value The variable value /// @param value Variable value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The old value or nil if there was no previous value. /// @return Old value or nil if there was no previous value.
/// ///
/// @warning It may return nil if there was no previous value /// @warning It may return nil if there was no previous value
/// or if previous value was `v:null`. /// or if previous value was `v:null`.
@ -388,19 +393,19 @@ Object vim_set_var(String name, Object value, Error *err)
/// ///
/// @deprecated /// @deprecated
/// ///
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The old value /// @return Old value
Object vim_del_var(String name, Error *err) Object vim_del_var(String name, Error *err)
{ {
return dict_set_value(&globvardict, name, NIL, true, true, err); return dict_set_value(&globvardict, name, NIL, true, true, err);
} }
/// Gets a vim variable /// Gets a v: variable
/// ///
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The variable value /// @return Variable value
Object nvim_get_vvar(String name, Error *err) Object nvim_get_vvar(String name, Error *err)
{ {
return dict_get_value(&vimvardict, name, err); return dict_get_value(&vimvardict, name, err);
@ -408,9 +413,9 @@ Object nvim_get_vvar(String name, Error *err)
/// Gets an option value string /// Gets an option value string
/// ///
/// @param name The option name /// @param name Option name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The option value /// @return Option value
Object nvim_get_option(String name, Error *err) Object nvim_get_option(String name, Error *err)
{ {
return get_option_from(NULL, SREQ_GLOBAL, name, err); return get_option_from(NULL, SREQ_GLOBAL, name, err);
@ -418,9 +423,9 @@ Object nvim_get_option(String name, Error *err)
/// Sets an option value /// Sets an option value
/// ///
/// @param name The option name /// @param name Option name
/// @param value The new option value /// @param value New option value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_set_option(String name, Object value, Error *err) void nvim_set_option(String name, Object value, Error *err)
{ {
set_option_to(NULL, SREQ_GLOBAL, name, value, err); set_option_to(NULL, SREQ_GLOBAL, name, value, err);
@ -428,7 +433,7 @@ void nvim_set_option(String name, Object value, Error *err)
/// Writes a message to vim output buffer /// Writes a message to vim output buffer
/// ///
/// @param str The message /// @param str Message
void nvim_out_write(String str) void nvim_out_write(String str)
{ {
write_msg(str, false); write_msg(str, false);
@ -436,16 +441,17 @@ void nvim_out_write(String str)
/// Writes a message to vim error buffer /// Writes a message to vim error buffer
/// ///
/// @param str The message /// @param str Message
void nvim_err_write(String str) void nvim_err_write(String str)
{ {
write_msg(str, true); write_msg(str, true);
} }
/// Higher level error reporting function that ensures all str contents /// Writes a message to vim error buffer. Appends a linefeed to ensure all
/// are written by sending a trailing linefeed to `nvim_err_write` /// contents are written.
/// ///
/// @param str The message /// @param str Message
/// @see nvim_err_write()
void nvim_err_writeln(String str) void nvim_err_writeln(String str)
{ {
nvim_err_write(str); nvim_err_write(str);
@ -454,7 +460,7 @@ void nvim_err_writeln(String str)
/// Gets the current list of buffer handles /// Gets the current list of buffer handles
/// ///
/// @return The number of buffers /// @return List of buffer handles
ArrayOf(Buffer) nvim_list_bufs(void) ArrayOf(Buffer) nvim_list_bufs(void)
{ {
Array rv = ARRAY_DICT_INIT; Array rv = ARRAY_DICT_INIT;
@ -475,7 +481,7 @@ ArrayOf(Buffer) nvim_list_bufs(void)
/// Gets the current buffer /// Gets the current buffer
/// ///
/// @reqturn The buffer handle /// @return Buffer handle
Buffer nvim_get_current_buf(void) Buffer nvim_get_current_buf(void)
{ {
return curbuf->handle; return curbuf->handle;
@ -483,8 +489,8 @@ Buffer nvim_get_current_buf(void)
/// Sets the current buffer /// Sets the current buffer
/// ///
/// @param id The buffer handle /// @param id Buffer handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_set_current_buf(Buffer buffer, Error *err) void nvim_set_current_buf(Buffer buffer, Error *err)
{ {
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
@ -505,7 +511,7 @@ void nvim_set_current_buf(Buffer buffer, Error *err)
/// Gets the current list of window handles /// Gets the current list of window handles
/// ///
/// @return The number of windows /// @return List of window handles
ArrayOf(Window) nvim_list_wins(void) ArrayOf(Window) nvim_list_wins(void)
{ {
Array rv = ARRAY_DICT_INIT; Array rv = ARRAY_DICT_INIT;
@ -526,7 +532,7 @@ ArrayOf(Window) nvim_list_wins(void)
/// Gets the current window /// Gets the current window
/// ///
/// @return The window handle /// @return Window handle
Window nvim_get_current_win(void) Window nvim_get_current_win(void)
{ {
return curwin->handle; return curwin->handle;
@ -534,7 +540,7 @@ Window nvim_get_current_win(void)
/// Sets the current window /// Sets the current window
/// ///
/// @param handle The window handle /// @param handle Window handle
void nvim_set_current_win(Window window, Error *err) void nvim_set_current_win(Window window, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -555,7 +561,7 @@ void nvim_set_current_win(Window window, Error *err)
/// Gets the current list of tabpage handles /// Gets the current list of tabpage handles
/// ///
/// @return The number of tab pages /// @return List of tabpage handles
ArrayOf(Tabpage) nvim_list_tabpages(void) ArrayOf(Tabpage) nvim_list_tabpages(void)
{ {
Array rv = ARRAY_DICT_INIT; Array rv = ARRAY_DICT_INIT;
@ -574,18 +580,18 @@ ArrayOf(Tabpage) nvim_list_tabpages(void)
return rv; return rv;
} }
/// Gets the current tab page /// Gets the current tabpage
/// ///
/// @return The tab page handle /// @return Tabpage handle
Tabpage nvim_get_current_tabpage(void) Tabpage nvim_get_current_tabpage(void)
{ {
return curtab->handle; return curtab->handle;
} }
/// Sets the current tab page /// Sets the current tabpage
/// ///
/// @param handle The tab page handle /// @param handle Tabpage handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_set_current_tabpage(Tabpage tabpage, Error *err) void nvim_set_current_tabpage(Tabpage tabpage, Error *err)
{ {
tabpage_T *tp = find_tab_by_handle(tabpage, err); tabpage_T *tp = find_tab_by_handle(tabpage, err);
@ -606,8 +612,8 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err)
/// Subscribes to event broadcasts /// Subscribes to event broadcasts
/// ///
/// @param channel_id The channel id (passed automatically by the dispatcher) /// @param channel_id Channel id (passed automatically by the dispatcher)
/// @param event The event type string /// @param event Event type string
void nvim_subscribe(uint64_t channel_id, String event) void nvim_subscribe(uint64_t channel_id, String event)
FUNC_API_NOEVAL FUNC_API_NOEVAL
{ {
@ -620,8 +626,8 @@ void nvim_subscribe(uint64_t channel_id, String event)
/// Unsubscribes to event broadcasts /// Unsubscribes to event broadcasts
/// ///
/// @param channel_id The channel id (passed automatically by the dispatcher) /// @param channel_id Channel id (passed automatically by the dispatcher)
/// @param event The event type string /// @param event Event type string
void nvim_unsubscribe(uint64_t channel_id, String event) void nvim_unsubscribe(uint64_t channel_id, String event)
FUNC_API_NOEVAL FUNC_API_NOEVAL
{ {
@ -756,9 +762,8 @@ validation_error:
/// and flushed after each newline. Incomplete lines are kept for writing /// and flushed after each newline. Incomplete lines are kept for writing
/// later. /// later.
/// ///
/// @param message The message to write /// @param message Message to write
/// @param to_err true if it should be treated as an error message (use /// @param to_err true: message is an error (uses `emsg` instead of `msg`)
/// `emsg` instead of `msg` to print each line)
static void write_msg(String message, bool to_err) static void write_msg(String message, bool to_err)
{ {
static size_t out_pos = 0, err_pos = 0; static size_t out_pos = 0, err_pos = 0;

View File

@ -15,9 +15,9 @@
/// Gets the current buffer in a window /// Gets the current buffer in a window
/// ///
/// @param window The window handle /// @param window Window handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The buffer handle /// @return Buffer handle
Buffer nvim_win_get_buf(Window window, Error *err) Buffer nvim_win_get_buf(Window window, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -31,9 +31,9 @@ Buffer nvim_win_get_buf(Window window, Error *err)
/// Gets the cursor position in the window /// Gets the cursor position in the window
/// ///
/// @param window The window handle /// @param window Window handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return the (row, col) tuple /// @return (row, col) tuple
ArrayOf(Integer, 2) nvim_win_get_cursor(Window window, Error *err) ArrayOf(Integer, 2) nvim_win_get_cursor(Window window, Error *err)
{ {
Array rv = ARRAY_DICT_INIT; Array rv = ARRAY_DICT_INIT;
@ -49,9 +49,9 @@ ArrayOf(Integer, 2) nvim_win_get_cursor(Window window, Error *err)
/// Sets the cursor position in the window /// Sets the cursor position in the window
/// ///
/// @param window The window handle /// @param window Window handle
/// @param pos the (row, col) tuple representing the new position /// @param pos (row, col) tuple representing the new position
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err) void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -95,9 +95,9 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
/// Gets the window height /// Gets the window height
/// ///
/// @param window The window handle /// @param window Window handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return the height in rows /// @return Height as a count of rows
Integer nvim_win_get_height(Window window, Error *err) Integer nvim_win_get_height(Window window, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -112,9 +112,9 @@ Integer nvim_win_get_height(Window window, Error *err)
/// Sets the window height. This will only succeed if the screen is split /// Sets the window height. This will only succeed if the screen is split
/// horizontally. /// horizontally.
/// ///
/// @param window The window handle /// @param window Window handle
/// @param height the new height in rows /// @param height Height as a count of rows
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_win_set_height(Window window, Integer height, Error *err) void nvim_win_set_height(Window window, Integer height, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -138,9 +138,9 @@ void nvim_win_set_height(Window window, Integer height, Error *err)
/// Gets the window width /// Gets the window width
/// ///
/// @param window The window handle /// @param window Window handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return the width in columns /// @return Width as a count of columns
Integer nvim_win_get_width(Window window, Error *err) Integer nvim_win_get_width(Window window, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -155,9 +155,9 @@ Integer nvim_win_get_width(Window window, Error *err)
/// Sets the window width. This will only succeed if the screen is split /// Sets the window width. This will only succeed if the screen is split
/// vertically. /// vertically.
/// ///
/// @param window The window handle /// @param window Window handle
/// @param width the new width in columns /// @param width Width as a count of columns
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_win_set_width(Window window, Integer width, Error *err) void nvim_win_set_width(Window window, Integer width, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -181,10 +181,10 @@ void nvim_win_set_width(Window window, Integer width, Error *err)
/// Gets a window-scoped (w:) variable /// Gets a window-scoped (w:) variable
/// ///
/// @param window The window handle /// @param window Window handle
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The variable value /// @return Variable value
Object nvim_win_get_var(Window window, String name, Error *err) Object nvim_win_get_var(Window window, String name, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -198,10 +198,10 @@ Object nvim_win_get_var(Window window, String name, Error *err)
/// Sets a window-scoped (w:) variable /// Sets a window-scoped (w:) variable
/// ///
/// @param window The window handle /// @param window Window handle
/// @param name The variable name /// @param name Variable name
/// @param value The variable value /// @param value Variable value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_win_set_var(Window window, String name, Object value, Error *err) void nvim_win_set_var(Window window, String name, Object value, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -215,9 +215,9 @@ void nvim_win_set_var(Window window, String name, Object value, Error *err)
/// Removes a window-scoped (w:) variable /// Removes a window-scoped (w:) variable
/// ///
/// @param window The window handle /// @param window Window handle
/// @param name The variable name /// @param name Variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_win_del_var(Window window, String name, Error *err) void nvim_win_del_var(Window window, String name, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -233,11 +233,11 @@ void nvim_win_del_var(Window window, String name, Error *err)
/// ///
/// @deprecated /// @deprecated
/// ///
/// @param window The window handle /// @param window Window handle
/// @param name The variable name /// @param name Variable name
/// @param value The variable value /// @param value Variable value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The old value or nil if there was no previous value. /// @return Old value or nil if there was no previous value.
/// ///
/// @warning It may return nil if there was no previous value /// @warning It may return nil if there was no previous value
/// or if previous value was `v:null`. /// or if previous value was `v:null`.
@ -256,10 +256,10 @@ Object window_set_var(Window window, String name, Object value, Error *err)
/// ///
/// @deprecated /// @deprecated
/// ///
/// @param window The window handle /// @param window Window handle
/// @param name The variable name /// @param name variable name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The old value /// @return Old value
Object window_del_var(Window window, String name, Error *err) Object window_del_var(Window window, String name, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -273,10 +273,10 @@ Object window_del_var(Window window, String name, Error *err)
/// Gets a window option value /// Gets a window option value
/// ///
/// @param window The window handle /// @param window Window handle
/// @param name The option name /// @param name Option name
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The option value /// @return Option value
Object nvim_win_get_option(Window window, String name, Error *err) Object nvim_win_get_option(Window window, String name, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -291,10 +291,10 @@ Object nvim_win_get_option(Window window, String name, Error *err)
/// Sets a window option value. Passing 'nil' as value deletes the option(only /// Sets a window option value. Passing 'nil' as value deletes the option(only
/// works if there's a global fallback) /// works if there's a global fallback)
/// ///
/// @param window The window handle /// @param window Window handle
/// @param name The option name /// @param name Option name
/// @param value The option value /// @param value Option value
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
void nvim_win_set_option(Window window, String name, Object value, Error *err) void nvim_win_set_option(Window window, String name, Object value, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
@ -308,9 +308,9 @@ void nvim_win_set_option(Window window, String name, Object value, Error *err)
/// Gets the window position in display cells. First position is zero. /// Gets the window position in display cells. First position is zero.
/// ///
/// @param window The window handle /// @param window Window handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The (row, col) tuple with the window position /// @return (row, col) tuple with the window position
ArrayOf(Integer, 2) nvim_win_get_position(Window window, Error *err) ArrayOf(Integer, 2) nvim_win_get_position(Window window, Error *err)
{ {
Array rv = ARRAY_DICT_INIT; Array rv = ARRAY_DICT_INIT;
@ -324,11 +324,11 @@ ArrayOf(Integer, 2) nvim_win_get_position(Window window, Error *err)
return rv; return rv;
} }
/// Gets the window tab page /// Gets the window tabpage
/// ///
/// @param window The window handle /// @param window Window handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The tab page that contains the window /// @return Tabpage that contains the window
Tabpage nvim_win_get_tabpage(Window window, Error *err) Tabpage nvim_win_get_tabpage(Window window, Error *err)
{ {
Tabpage rv = 0; Tabpage rv = 0;
@ -343,9 +343,9 @@ Tabpage nvim_win_get_tabpage(Window window, Error *err)
/// Gets the window number /// Gets the window number
/// ///
/// @param window The window handle /// @param window Window handle
/// @param[out] err Details of an error that may have occurred /// @param[out] err Error details, if any
/// @return The window number /// @return Window number
Integer nvim_win_get_number(Window window, Error *err) Integer nvim_win_get_number(Window window, Error *err)
{ {
Integer rv = 0; Integer rv = 0;
@ -363,7 +363,7 @@ Integer nvim_win_get_number(Window window, Error *err)
/// Checks if a window is valid /// Checks if a window is valid
/// ///
/// @param window The window handle /// @param window Window handle
/// @return true if the window is valid, false otherwise /// @return true if the window is valid, false otherwise
Boolean nvim_win_is_valid(Window window) Boolean nvim_win_is_valid(Window window)
{ {

View File

@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local eq, clear, eval, feed, nvim = local eq, clear, eval, execute, feed, nvim =
helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.nvim helpers.eq, helpers.clear, helpers.eval, helpers.execute, helpers.feed,
helpers.nvim
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
@ -117,8 +118,12 @@ describe('system()', function()
eq("echoed", eval('system("echo -n echoed")')) eq("echoed", eval('system("echo -n echoed")'))
end) end)
it('to backgrounded command does not crash', function() it('to backgrounded command does not crash', function()
-- This is indeterminate, just exercise the codepath. -- This is indeterminate, just exercise the codepath. May get E5677.
eval('system("echo -n echoed &")') execute('call system("echo -n echoed &")')
local v_errnum = string.match(eval("v:errmsg"), "^E%d*:")
if v_errnum then
eq("E5677:", v_errnum)
end
eq(2, eval("1+1")) -- Still alive? eq(2, eval("1+1")) -- Still alive?
end) end)
end) end)
@ -128,8 +133,12 @@ describe('system()', function()
eq("input", eval('system("cat -", "input")')) eq("input", eval('system("cat -", "input")'))
end) end)
it('to backgrounded command does not crash', function() it('to backgrounded command does not crash', function()
-- This is indeterminate, just exercise the codepath. -- This is indeterminate, just exercise the codepath. May get E5677.
eval('system("cat - &", "input")') execute('call system("cat - &")')
local v_errnum = string.match(eval("v:errmsg"), "^E%d*:")
if v_errnum then
eq("E5677:", v_errnum)
end
eq(2, eval("1+1")) -- Still alive? eq(2, eval("1+1")) -- Still alive?
end) end)
end) end)

View File

@ -1,11 +1,13 @@
require('coxpcall') require('coxpcall')
local lfs = require('lfs') local lfs = require('lfs')
local ChildProcessStream = require('nvim.child_process_stream')
local SocketStream = require('nvim.socket_stream')
local TcpStream = require('nvim.tcp_stream')
local Session = require('nvim.session')
local global_helpers = require('test.helpers') local global_helpers = require('test.helpers')
-- nvim client: Found in .deps/usr/share/lua/<version>/nvim/ if "bundled".
local Session = require('nvim.session')
local TcpStream = require('nvim.tcp_stream')
local SocketStream = require('nvim.socket_stream')
local ChildProcessStream = require('nvim.child_process_stream')
local check_logs = global_helpers.check_logs local check_logs = global_helpers.check_logs
local neq = global_helpers.neq local neq = global_helpers.neq
local eq = global_helpers.eq local eq = global_helpers.eq
@ -134,10 +136,14 @@ local function stop()
session:stop() session:stop()
end end
-- Executes an ex-command. VimL errors will manifest as client (lua) errors, and
-- v:errmsg will be updated.
local function nvim_command(cmd) local function nvim_command(cmd)
request('nvim_command', cmd) request('nvim_command', cmd)
end end
-- Evaluates a VimL expression.
-- Fails on VimL error, but does not update v:errmsg.
local function nvim_eval(expr) local function nvim_eval(expr)
return request('nvim_eval', expr) return request('nvim_eval', expr)
end end
@ -158,10 +164,14 @@ local os_name = (function()
end) end)
end)() end)()
-- Executes a VimL function.
-- Fails on VimL error, but does not update v:errmsg.
local function nvim_call(name, ...) local function nvim_call(name, ...)
return request('nvim_call_function', name, {...}) return request('nvim_call_function', name, {...})
end end
-- Sends user input to Nvim.
-- Does not fail on VimL error, but v:errmsg will be updated.
local function nvim_feed(input) local function nvim_feed(input)
while #input > 0 do while #input > 0 do
local written = request('nvim_input', input) local written = request('nvim_input', input)
@ -279,6 +289,8 @@ local function insert(...)
nvim_feed('<ESC>') nvim_feed('<ESC>')
end end
-- Executes an ex-command by user input. Because nvim_input() is used, VimL
-- errors will not manifest as client (lua) errors. Use command() for that.
local function execute(...) local function execute(...)
for _, v in ipairs({...}) do for _, v in ipairs({...}) do
if v:sub(1, 1) ~= '/' then if v:sub(1, 1) ~= '/' then