aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/buffer.c520
-rw-r--r--src/nvim/api/deprecated.c367
-rw-r--r--src/nvim/api/deprecated.h11
-rw-r--r--src/nvim/api/private/dispatch.c1
-rw-r--r--src/nvim/api/private/helpers.c4
-rw-r--r--src/nvim/api/private/helpers.h5
-rw-r--r--src/nvim/api/tabpage.c42
-rw-r--r--src/nvim/api/vim.c86
-rw-r--r--src/nvim/api/window.c44
9 files changed, 717 insertions, 363 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 1011f050fd..8d82d22040 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -1,7 +1,7 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-// Much of this code was adapted from 'if_py_both.h' from the original
+// Some of this code was adapted from 'if_py_both.h' from the original
// vim source
#include <stdbool.h>
#include <stdint.h>
@@ -80,34 +80,6 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err)
return buf->b_ml.ml_line_count;
}
-/// Gets a buffer line
-///
-/// @deprecated use nvim_buf_get_lines instead.
-/// for positive indices (including 0) use
-/// "nvim_buf_get_lines(buffer, index, index+1, true)"
-/// for negative indices use
-/// "nvim_buf_get_lines(buffer, index-1, index, true)"
-///
-/// @param buffer Buffer handle
-/// @param index Line index
-/// @param[out] err Error details, if any
-/// @return Line string
-String buffer_get_line(Buffer buffer, Integer index, Error *err)
-{
- String rv = { .size = 0 };
-
- index = convert_index(index);
- Array slice = nvim_buf_get_lines(0, buffer, index, index+1, true, err);
-
- if (!ERROR_SET(err) && slice.size) {
- rv = slice.items[0].data.string;
- }
-
- xfree(slice.items);
-
- return rv;
-}
-
/// Activates buffer-update events on a channel, or as Lua callbacks.
///
/// Example (Lua): capture buffer updates in a global `events` variable
@@ -149,6 +121,8 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
/// - buffer handle
/// - utf_sizes: include UTF-32 and UTF-16 size of the replaced
/// region, as args to `on_lines`.
+/// - preview: also attach to command preview (i.e. 'inccommand')
+/// events.
/// @param[out] err Error details, if any
/// @return False if attach failed (invalid parameter, or buffer isn't loaded);
/// otherwise True. TODO: LUA_API_NO_EVAL
@@ -204,6 +178,12 @@ Boolean nvim_buf_attach(uint64_t channel_id,
goto error;
}
cb.utf_sizes = v->data.boolean;
+ } else if (is_lua && strequal("preview", k.data)) {
+ if (v->type != kObjectTypeBoolean) {
+ api_set_error(err, kErrorTypeValidation, "preview must be boolean");
+ goto error;
+ }
+ cb.preview = v->data.boolean;
} else {
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
goto error;
@@ -258,68 +238,6 @@ void nvim__buf_redraw_range(Buffer buffer, Integer first, Integer last,
redraw_buf_range_later(buf, (linenr_T)first+1, (linenr_T)last);
}
-/// Sets a buffer line
-///
-/// @deprecated use nvim_buf_set_lines instead.
-/// for positive indices use
-/// "nvim_buf_set_lines(buffer, index, index+1, true, [line])"
-/// for negative indices use
-/// "nvim_buf_set_lines(buffer, index-1, index, true, [line])"
-///
-/// @param buffer Buffer handle
-/// @param index Line index
-/// @param line Contents of the new line
-/// @param[out] err Error details, if any
-void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
-{
- Object l = STRING_OBJ(line);
- Array array = { .items = &l, .size = 1 };
- index = convert_index(index);
- nvim_buf_set_lines(0, buffer, index, index+1, true, array, err);
-}
-
-/// Deletes a buffer line
-///
-/// @deprecated use nvim_buf_set_lines instead.
-/// for positive indices use
-/// "nvim_buf_set_lines(buffer, index, index+1, true, [])"
-/// for negative indices use
-/// "nvim_buf_set_lines(buffer, index-1, index, true, [])"
-/// @param buffer buffer handle
-/// @param index line index
-/// @param[out] err Error details, if any
-void buffer_del_line(Buffer buffer, Integer index, Error *err)
-{
- Array array = ARRAY_DICT_INIT;
- index = convert_index(index);
- nvim_buf_set_lines(0, buffer, index, index+1, true, array, err);
-}
-
-/// Retrieves a line range from the buffer
-///
-/// @deprecated use nvim_buf_get_lines(buffer, newstart, newend, false)
-/// where newstart = start + int(not include_start) - int(start < 0)
-/// newend = end + int(include_end) - int(end < 0)
-/// int(bool) = 1 if bool is true else 0
-/// @param buffer Buffer handle
-/// @param start First line index
-/// @param end Last line index
-/// @param include_start True if the slice includes the `start` parameter
-/// @param include_end True if the slice includes the `end` parameter
-/// @param[out] err Error details, if any
-/// @return Array of lines
-ArrayOf(String) buffer_get_line_slice(Buffer buffer,
- Integer start,
- Integer end,
- Boolean include_start,
- Boolean include_end,
- Error *err)
-{
- start = convert_index(start) + !include_start;
- end = convert_index(end) + include_end;
- return nvim_buf_get_lines(0, buffer, start , end, false, err);
-}
-
/// Gets a line-range from the buffer.
///
/// Indexing is zero-based, end-exclusive. Negative indices are interpreted
@@ -391,36 +309,28 @@ end:
return rv;
}
-
-/// Replaces a line range on the buffer
-///
-/// @deprecated use nvim_buf_set_lines(buffer, newstart, newend, false, lines)
-/// where newstart = start + int(not include_start) + int(start < 0)
-/// newend = end + int(include_end) + int(end < 0)
-/// int(bool) = 1 if bool is true else 0
-///
-/// @param buffer Buffer handle, or 0 for current buffer
-/// @param start First line index
-/// @param end Last line index
-/// @param include_start True if the slice includes the `start` parameter
-/// @param include_end True if the slice includes the `end` parameter
-/// @param replacement Array of lines to use as replacement (0-length
-// array will delete the line range)
-/// @param[out] err Error details, if any
-void buffer_set_line_slice(Buffer buffer,
- Integer start,
- Integer end,
- Boolean include_start,
- Boolean include_end,
- ArrayOf(String) replacement,
- Error *err)
+static bool check_string_array(Array arr, bool disallow_nl, Error *err)
{
- start = convert_index(start) + !include_start;
- end = convert_index(end) + include_end;
- nvim_buf_set_lines(0, buffer, start, end, false, replacement, err);
+ for (size_t i = 0; i < arr.size; i++) {
+ if (arr.items[i].type != kObjectTypeString) {
+ api_set_error(err,
+ kErrorTypeValidation,
+ "All items in the replacement array must be strings");
+ return false;
+ }
+ // Disallow newlines in the middle of the line.
+ if (disallow_nl) {
+ const String l = arr.items[i].data.string;
+ if (memchr(l.data, NL, l.size)) {
+ api_set_error(err, kErrorTypeValidation,
+ "String cannot contain newlines");
+ return false;
+ }
+ }
+ }
+ return true;
}
-
/// Sets (replaces) a line-range in the buffer.
///
/// Indexing is zero-based, end-exclusive. Negative indices are interpreted
@@ -448,6 +358,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
ArrayOf(String) replacement,
Error *err)
FUNC_API_SINCE(1)
+ FUNC_API_CHECK_TEXTLOCK
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -472,22 +383,9 @@ void nvim_buf_set_lines(uint64_t channel_id,
return;
}
- for (size_t i = 0; i < replacement.size; i++) {
- if (replacement.items[i].type != kObjectTypeString) {
- api_set_error(err,
- kErrorTypeValidation,
- "All items in the replacement array must be strings");
- return;
- }
- // Disallow newlines in the middle of the line.
- if (channel_id != VIML_INTERNAL_CALL) {
- const String l = replacement.items[i].data.string;
- if (memchr(l.data, NL, l.size)) {
- api_set_error(err, kErrorTypeValidation,
- "String cannot contain newlines");
- return;
- }
- }
+ bool disallow_nl = (channel_id != VIML_INTERNAL_CALL);
+ if (!check_string_array(replacement, disallow_nl, err)) {
+ return;
}
size_t new_len = replacement.size;
@@ -597,6 +495,250 @@ end:
try_end(err);
}
+/// Sets (replaces) a range in the buffer
+///
+/// This is recommended over nvim_buf_set_lines when only modifying parts of a
+/// line, as extmarks will be preserved on non-modified parts of the touched
+/// lines.
+///
+/// Indexing is zero-based and end-exclusive.
+///
+/// To insert text at a given index, set `start` and `end` ranges to the same
+/// index. To delete a range, set `replacement` to an array containing
+/// an empty string, or simply an empty array.
+///
+/// Prefer nvim_buf_set_lines when adding or deleting entire lines only.
+///
+/// @param channel_id
+/// @param buffer Buffer handle, or 0 for current buffer
+/// @param start_row First line index
+/// @param start_column Last column
+/// @param end_row Last line index
+/// @param end_column Last column
+/// @param replacement Array of lines to use as replacement
+/// @param[out] err Error details, if any
+void nvim_buf_set_text(uint64_t channel_id, Buffer buffer,
+ Integer start_row, Integer start_col,
+ Integer end_row, Integer end_col,
+ ArrayOf(String) replacement, Error *err)
+ FUNC_API_SINCE(7)
+{
+ FIXED_TEMP_ARRAY(scratch, 1);
+ if (replacement.size == 0) {
+ scratch.items[0] = STRING_OBJ(STATIC_CSTR_AS_STRING(""));
+ replacement = scratch;
+ }
+
+ buf_T *buf = find_buffer_by_handle(buffer, err);
+ if (!buf) {
+ return;
+ }
+
+ bool oob = false;
+
+ // check range is ordered and everything!
+ // start_row, end_row within buffer len (except add text past the end?)
+ start_row = normalize_index(buf, start_row, &oob);
+ if (oob || start_row == buf->b_ml.ml_line_count + 1) {
+ api_set_error(err, kErrorTypeValidation, "start_row out of bounds");
+ return;
+ }
+
+ end_row = normalize_index(buf, end_row, &oob);
+ if (oob || end_row == buf->b_ml.ml_line_count + 1) {
+ api_set_error(err, kErrorTypeValidation, "end_row out of bounds");
+ return;
+ }
+
+ char *str_at_start = (char *)ml_get_buf(buf, start_row, false);
+ if (start_col < 0 || (size_t)start_col > strlen(str_at_start)) {
+ api_set_error(err, kErrorTypeValidation, "start_col out of bounds");
+ return;
+ }
+
+ char *str_at_end = (char *)ml_get_buf(buf, end_row, false);
+ size_t len_at_end = strlen(str_at_end);
+ if (end_col < 0 || (size_t)end_col > len_at_end) {
+ api_set_error(err, kErrorTypeValidation, "end_col out of bounds");
+ return;
+ }
+
+ if (start_row > end_row || (end_row == start_row && start_col > end_col)) {
+ api_set_error(err, kErrorTypeValidation, "start is higher than end");
+ return;
+ }
+
+ bool disallow_nl = (channel_id != VIML_INTERNAL_CALL);
+ if (!check_string_array(replacement, disallow_nl, err)) {
+ return;
+ }
+
+ size_t new_len = replacement.size;
+
+ bcount_t new_byte = 0;
+ bcount_t old_byte = 0;
+
+ // calculate byte size of old region before it gets modified/deleted
+ if (start_row == end_row) {
+ old_byte = (bcount_t)end_col - start_col;
+ } else {
+ const char *bufline;
+ old_byte += (bcount_t)strlen(str_at_start) - start_col;
+ for (int64_t i = 1; i < end_row - start_row; i++) {
+ int64_t lnum = start_row + i;
+
+ bufline = (char *)ml_get_buf(buf, lnum, false);
+ old_byte += (bcount_t)(strlen(bufline))+1;
+ }
+ old_byte += (bcount_t)end_col+1;
+ }
+
+ String first_item = replacement.items[0].data.string;
+ String last_item = replacement.items[replacement.size-1].data.string;
+
+ size_t firstlen = (size_t)start_col+first_item.size;
+ size_t last_part_len = strlen(str_at_end) - (size_t)end_col;
+ if (replacement.size == 1) {
+ firstlen += last_part_len;
+ }
+ char *first = xmallocz(firstlen), *last = NULL;
+ memcpy(first, str_at_start, (size_t)start_col);
+ memcpy(first+start_col, first_item.data, first_item.size);
+ memchrsub(first+start_col, NUL, NL, first_item.size);
+ if (replacement.size == 1) {
+ memcpy(first+start_col+first_item.size, str_at_end+end_col, last_part_len);
+ } else {
+ last = xmallocz(last_item.size+last_part_len);
+ memcpy(last, last_item.data, last_item.size);
+ memchrsub(last, NUL, NL, last_item.size);
+ memcpy(last+last_item.size, str_at_end+end_col, last_part_len);
+ }
+
+ char **lines = (new_len != 0) ? xcalloc(new_len, sizeof(char *)) : NULL;
+ lines[0] = first;
+ new_byte += (bcount_t)(first_item.size);
+ for (size_t i = 1; i < new_len-1; i++) {
+ const String l = replacement.items[i].data.string;
+
+ // Fill lines[i] with l's contents. Convert NULs to newlines as required by
+ // NL-used-for-NUL.
+ lines[i] = xmemdupz(l.data, l.size);
+ memchrsub(lines[i], NUL, NL, l.size);
+ new_byte += (bcount_t)(l.size)+1;
+ }
+ if (replacement.size > 1) {
+ lines[replacement.size-1] = last;
+ new_byte += (bcount_t)(last_item.size)+1;
+ }
+
+ try_start();
+ aco_save_T aco;
+ aucmd_prepbuf(&aco, (buf_T *)buf);
+
+ if (!MODIFIABLE(buf)) {
+ api_set_error(err, kErrorTypeException, "Buffer is not 'modifiable'");
+ goto end;
+ }
+
+ // Small note about undo states: unlike set_lines, we want to save the
+ // undo state of one past the end_row, since end_row is inclusive.
+ if (u_save((linenr_T)start_row - 1, (linenr_T)end_row + 1) == FAIL) {
+ api_set_error(err, kErrorTypeException, "Failed to save undo information");
+ goto end;
+ }
+
+ ptrdiff_t extra = 0; // lines added to text, can be negative
+ size_t old_len = (size_t)(end_row-start_row+1);
+
+ // If the size of the range is reducing (ie, new_len < old_len) we
+ // need to delete some old_len. We do this at the start, by
+ // repeatedly deleting line "start".
+ size_t to_delete = (new_len < old_len) ? (size_t)(old_len - new_len) : 0;
+ for (size_t i = 0; i < to_delete; i++) {
+ if (ml_delete((linenr_T)start_row, false) == FAIL) {
+ api_set_error(err, kErrorTypeException, "Failed to delete line");
+ goto end;
+ }
+ }
+
+ if (to_delete > 0) {
+ extra -= (ptrdiff_t)to_delete;
+ }
+
+ // For as long as possible, replace the existing old_len with the
+ // new old_len. This is a more efficient operation, as it requires
+ // less memory allocation and freeing.
+ size_t to_replace = old_len < new_len ? old_len : new_len;
+ for (size_t i = 0; i < to_replace; i++) {
+ int64_t lnum = start_row + (int64_t)i;
+
+ if (lnum >= MAXLNUM) {
+ api_set_error(err, kErrorTypeValidation, "Index value is too high");
+ goto end;
+ }
+
+ if (ml_replace((linenr_T)lnum, (char_u *)lines[i], false) == FAIL) {
+ api_set_error(err, kErrorTypeException, "Failed to replace line");
+ goto end;
+ }
+ // Mark lines that haven't been passed to the buffer as they need
+ // to be freed later
+ lines[i] = NULL;
+ }
+
+ // Now we may need to insert the remaining new old_len
+ for (size_t i = to_replace; i < new_len; i++) {
+ int64_t lnum = start_row + (int64_t)i - 1;
+
+ if (lnum >= MAXLNUM) {
+ api_set_error(err, kErrorTypeValidation, "Index value is too high");
+ goto end;
+ }
+
+ if (ml_append((linenr_T)lnum, (char_u *)lines[i], 0, false) == FAIL) {
+ api_set_error(err, kErrorTypeException, "Failed to insert line");
+ goto end;
+ }
+
+ // Same as with replacing, but we also need to free lines
+ xfree(lines[i]);
+ lines[i] = NULL;
+ extra++;
+ }
+
+ // Adjust marks. Invalidate any which lie in the
+ // changed range, and move any in the remainder of the buffer.
+ mark_adjust((linenr_T)start_row,
+ (linenr_T)end_row,
+ MAXLNUM,
+ (long)extra,
+ kExtmarkNOOP);
+
+ colnr_T col_extent = (colnr_T)(end_col
+ - ((end_row == start_row) ? start_col : 0));
+ extmark_splice(buf, (int)start_row-1, (colnr_T)start_col,
+ (int)(end_row-start_row), col_extent, old_byte,
+ (int)new_len-1, (colnr_T)last_item.size, new_byte,
+ kExtmarkUndo);
+
+
+ changed_lines((linenr_T)start_row, 0, (linenr_T)end_row, (long)extra, true);
+
+ // adjust cursor like an extmark ( i e it was inside last_part_len)
+ if (curwin->w_cursor.lnum == end_row && curwin->w_cursor.col > end_col) {
+ curwin->w_cursor.col -= col_extent - (colnr_T)last_item.size;
+ }
+ fix_cursor((linenr_T)start_row, (linenr_T)end_row, (linenr_T)extra);
+
+end:
+ for (size_t i = 0; i < new_len; i++) {
+ xfree(lines[i]);
+ }
+ xfree(lines);
+ aucmd_restbuf(&aco);
+ try_end(err);
+}
+
/// Returns the byte offset of a line (0-indexed). |api-indexing|
///
/// Line 1 (index=0) has offset 0. UTF-8 bytes are counted. EOL is one byte.
@@ -787,48 +929,6 @@ void nvim_buf_del_var(Buffer buffer, String name, Error *err)
dict_set_var(buf->b_vars, name, NIL, true, false, err);
}
-/// Sets a buffer-scoped (b:) variable
-///
-/// @deprecated
-///
-/// @param buffer Buffer handle, or 0 for current buffer
-/// @param name Variable name
-/// @param value Variable value
-/// @param[out] err Error details, if any
-/// @return Old value or 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`.
-Object buffer_set_var(Buffer buffer, String name, Object value, Error *err)
-{
- buf_T *buf = find_buffer_by_handle(buffer, err);
-
- if (!buf) {
- return (Object) OBJECT_INIT;
- }
-
- return dict_set_var(buf->b_vars, name, value, false, true, err);
-}
-
-/// Removes a buffer-scoped (b:) variable
-///
-/// @deprecated
-///
-/// @param buffer Buffer handle, or 0 for current buffer
-/// @param name Variable name
-/// @param[out] err Error details, if any
-/// @return Old value
-Object buffer_del_var(Buffer buffer, String name, Error *err)
-{
- buf_T *buf = find_buffer_by_handle(buffer, err);
-
- if (!buf) {
- return (Object) OBJECT_INIT;
- }
-
- return dict_set_var(buf->b_vars, name, NIL, true, true, err);
-}
-
/// Gets a buffer option value
///
@@ -869,28 +969,6 @@ void nvim_buf_set_option(uint64_t channel_id, Buffer buffer,
set_option_to(channel_id, buf, SREQ_BUF, name, value, err);
}
-/// Gets the buffer number
-///
-/// @deprecated The buffer number now is equal to the object id,
-/// so there is no need to use this function.
-///
-/// @param buffer Buffer handle, or 0 for current buffer
-/// @param[out] err Error details, if any
-/// @return Buffer number
-Integer nvim_buf_get_number(Buffer buffer, Error *err)
- FUNC_API_SINCE(1)
- FUNC_API_DEPRECATED_SINCE(2)
-{
- Integer rv = 0;
- buf_T *buf = find_buffer_by_handle(buffer, err);
-
- if (!buf) {
- return rv;
- }
-
- return buf->b_fnum;
-}
-
/// Gets the full file name for the buffer
///
/// @param buffer Buffer handle, or 0 for current buffer
@@ -962,6 +1040,7 @@ Boolean nvim_buf_is_loaded(Buffer buffer)
/// - unload: Unloaded only, do not delete. See |:bunload|
void nvim_buf_delete(Buffer buffer, Dictionary opts, Error *err)
FUNC_API_SINCE(7)
+ FUNC_API_CHECK_TEXTLOCK
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -1017,25 +1096,6 @@ Boolean nvim_buf_is_valid(Buffer buffer)
return ret;
}
-/// Inserts a sequence of lines to a buffer at a certain index
-///
-/// @deprecated use nvim_buf_set_lines(buffer, lnum, lnum, true, lines)
-///
-/// @param buffer Buffer handle
-/// @param lnum Insert the lines after `lnum`. If negative, appends to
-/// the end of the buffer.
-/// @param lines Array of lines
-/// @param[out] err Error details, if any
-void buffer_insert(Buffer buffer,
- Integer lnum,
- ArrayOf(String) lines,
- Error *err)
-{
- // "lnum" will be the index of the line after inserting,
- // no matter if it is negative or not
- nvim_buf_set_lines(0, buffer, lnum, lnum, true, lines, err);
-}
-
/// Return a tuple (row,col) representing the position of the named mark.
///
/// Marks are (1,0)-indexed. |api-indexing|
@@ -1667,27 +1727,6 @@ void nvim_buf_clear_namespace(Buffer buffer,
(int)line_end-1, MAXCOL);
}
-/// Clears highlights and virtual text from namespace and range of lines
-///
-/// @deprecated use |nvim_buf_clear_namespace()|.
-///
-/// @param buffer Buffer handle, or 0 for current buffer
-/// @param ns_id Namespace to clear, or -1 to clear all.
-/// @param line_start Start of range of lines to clear
-/// @param line_end End of range of lines to clear (exclusive) or -1 to clear
-/// to end of file.
-/// @param[out] err Error details, if any
-void nvim_buf_clear_highlight(Buffer buffer,
- Integer ns_id,
- Integer line_start,
- Integer line_end,
- Error *err)
- FUNC_API_SINCE(1)
-{
- nvim_buf_clear_namespace(buffer, ns_id, line_start, line_end, err);
-}
-
-
/// Set the virtual text (annotation) for a buffer line.
///
/// By default (and currently the only option) the text will be placed after
@@ -1873,8 +1912,3 @@ static int64_t normalize_index(buf_T *buf, int64_t index, bool *oob)
index++;
return index;
}
-
-static int64_t convert_index(int64_t index)
-{
- return index < 0 ? index - 1 : index;
-}
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c
new file mode 100644
index 0000000000..3989386bb9
--- /dev/null
+++ b/src/nvim/api/deprecated.c
@@ -0,0 +1,367 @@
+// This is an open source non-commercial project. Dear PVS-Studio, please check
+// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include "nvim/api/deprecated.h"
+#include "nvim/api/buffer.h"
+#include "nvim/api/vim.h"
+#include "nvim/api/private/helpers.h"
+#include "nvim/api/private/defs.h"
+#include "nvim/lua/executor.h"
+
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "api/deprecated.c.generated.h"
+#endif
+
+/// @deprecated
+/// @see nvim_exec
+String nvim_command_output(String command, Error *err)
+ FUNC_API_SINCE(1)
+ FUNC_API_DEPRECATED_SINCE(7)
+{
+ return nvim_exec(command, true, err);
+}
+
+/// @deprecated Use nvim_exec_lua() instead.
+/// @see nvim_exec_lua
+Object nvim_execute_lua(String code, Array args, Error *err)
+ FUNC_API_SINCE(3)
+ FUNC_API_DEPRECATED_SINCE(7)
+ FUNC_API_REMOTE_ONLY
+{
+ return nlua_exec(code, args, err);
+}
+
+/// Gets the buffer number
+///
+/// @deprecated The buffer number now is equal to the object id,
+/// so there is no need to use this function.
+///
+/// @param buffer Buffer handle, or 0 for current buffer
+/// @param[out] err Error details, if any
+/// @return Buffer number
+Integer nvim_buf_get_number(Buffer buffer, Error *err)
+ FUNC_API_SINCE(1)
+ FUNC_API_DEPRECATED_SINCE(2)
+{
+ Integer rv = 0;
+ buf_T *buf = find_buffer_by_handle(buffer, err);
+
+ if (!buf) {
+ return rv;
+ }
+
+ return buf->b_fnum;
+}
+
+/// Clears highlights and virtual text from namespace and range of lines
+///
+/// @deprecated use |nvim_buf_clear_namespace()|.
+///
+/// @param buffer Buffer handle, or 0 for current buffer
+/// @param ns_id Namespace to clear, or -1 to clear all.
+/// @param line_start Start of range of lines to clear
+/// @param line_end End of range of lines to clear (exclusive) or -1 to clear
+/// to end of file.
+/// @param[out] err Error details, if any
+void nvim_buf_clear_highlight(Buffer buffer,
+ Integer ns_id,
+ Integer line_start,
+ Integer line_end,
+ Error *err)
+ FUNC_API_SINCE(1)
+ FUNC_API_DEPRECATED_SINCE(7)
+{
+ nvim_buf_clear_namespace(buffer, ns_id, line_start, line_end, err);
+}
+
+
+/// Inserts a sequence of lines to a buffer at a certain index
+///
+/// @deprecated use nvim_buf_set_lines(buffer, lnum, lnum, true, lines)
+///
+/// @param buffer Buffer handle
+/// @param lnum Insert the lines after `lnum`. If negative, appends to
+/// the end of the buffer.
+/// @param lines Array of lines
+/// @param[out] err Error details, if any
+void buffer_insert(Buffer buffer,
+ Integer lnum,
+ ArrayOf(String) lines,
+ Error *err)
+{
+ // "lnum" will be the index of the line after inserting,
+ // no matter if it is negative or not
+ nvim_buf_set_lines(0, buffer, lnum, lnum, true, lines, err);
+}
+
+/// Gets a buffer line
+///
+/// @deprecated use nvim_buf_get_lines instead.
+/// for positive indices (including 0) use
+/// "nvim_buf_get_lines(buffer, index, index+1, true)"
+/// for negative indices use
+/// "nvim_buf_get_lines(buffer, index-1, index, true)"
+///
+/// @param buffer Buffer handle
+/// @param index Line index
+/// @param[out] err Error details, if any
+/// @return Line string
+String buffer_get_line(Buffer buffer, Integer index, Error *err)
+{
+ String rv = { .size = 0 };
+
+ index = convert_index(index);
+ Array slice = nvim_buf_get_lines(0, buffer, index, index+1, true, err);
+
+ if (!ERROR_SET(err) && slice.size) {
+ rv = slice.items[0].data.string;
+ }
+
+ xfree(slice.items);
+
+ return rv;
+}
+
+/// Sets a buffer line
+///
+/// @deprecated use nvim_buf_set_lines instead.
+/// for positive indices use
+/// "nvim_buf_set_lines(buffer, index, index+1, true, [line])"
+/// for negative indices use
+/// "nvim_buf_set_lines(buffer, index-1, index, true, [line])"
+///
+/// @param buffer Buffer handle
+/// @param index Line index
+/// @param line Contents of the new line
+/// @param[out] err Error details, if any
+void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
+{
+ Object l = STRING_OBJ(line);
+ Array array = { .items = &l, .size = 1 };
+ index = convert_index(index);
+ nvim_buf_set_lines(0, buffer, index, index+1, true, array, err);
+}
+
+/// Deletes a buffer line
+///
+/// @deprecated use nvim_buf_set_lines instead.
+/// for positive indices use
+/// "nvim_buf_set_lines(buffer, index, index+1, true, [])"
+/// for negative indices use
+/// "nvim_buf_set_lines(buffer, index-1, index, true, [])"
+/// @param buffer buffer handle
+/// @param index line index
+/// @param[out] err Error details, if any
+void buffer_del_line(Buffer buffer, Integer index, Error *err)
+{
+ Array array = ARRAY_DICT_INIT;
+ index = convert_index(index);
+ nvim_buf_set_lines(0, buffer, index, index+1, true, array, err);
+}
+
+/// Retrieves a line range from the buffer
+///
+/// @deprecated use nvim_buf_get_lines(buffer, newstart, newend, false)
+/// where newstart = start + int(not include_start) - int(start < 0)
+/// newend = end + int(include_end) - int(end < 0)
+/// int(bool) = 1 if bool is true else 0
+/// @param buffer Buffer handle
+/// @param start First line index
+/// @param end Last line index
+/// @param include_start True if the slice includes the `start` parameter
+/// @param include_end True if the slice includes the `end` parameter
+/// @param[out] err Error details, if any
+/// @return Array of lines
+ArrayOf(String) buffer_get_line_slice(Buffer buffer,
+ Integer start,
+ Integer end,
+ Boolean include_start,
+ Boolean include_end,
+ Error *err)
+{
+ start = convert_index(start) + !include_start;
+ end = convert_index(end) + include_end;
+ return nvim_buf_get_lines(0, buffer, start , end, false, err);
+}
+
+/// Replaces a line range on the buffer
+///
+/// @deprecated use nvim_buf_set_lines(buffer, newstart, newend, false, lines)
+/// where newstart = start + int(not include_start) + int(start < 0)
+/// newend = end + int(include_end) + int(end < 0)
+/// int(bool) = 1 if bool is true else 0
+///
+/// @param buffer Buffer handle, or 0 for current buffer
+/// @param start First line index
+/// @param end Last line index
+/// @param include_start True if the slice includes the `start` parameter
+/// @param include_end True if the slice includes the `end` parameter
+/// @param replacement Array of lines to use as replacement (0-length
+// array will delete the line range)
+/// @param[out] err Error details, if any
+void buffer_set_line_slice(Buffer buffer,
+ Integer start,
+ Integer end,
+ Boolean include_start,
+ Boolean include_end,
+ ArrayOf(String) replacement,
+ Error *err)
+{
+ start = convert_index(start) + !include_start;
+ end = convert_index(end) + include_end;
+ nvim_buf_set_lines(0, buffer, start, end, false, replacement, err);
+}
+
+
+/// Sets a buffer-scoped (b:) variable
+///
+/// @deprecated
+///
+/// @param buffer Buffer handle, or 0 for current buffer
+/// @param name Variable name
+/// @param value Variable value
+/// @param[out] err Error details, if any
+/// @return Old value or 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`.
+Object buffer_set_var(Buffer buffer, String name, Object value, Error *err)
+{
+ buf_T *buf = find_buffer_by_handle(buffer, err);
+
+ if (!buf) {
+ return NIL;
+ }
+
+ return dict_set_var(buf->b_vars, name, value, false, true, err);
+}
+
+/// Removes a buffer-scoped (b:) variable
+///
+/// @deprecated
+///
+/// @param buffer Buffer handle, or 0 for current buffer
+/// @param name Variable name
+/// @param[out] err Error details, if any
+/// @return Old value
+Object buffer_del_var(Buffer buffer, String name, Error *err)
+{
+ buf_T *buf = find_buffer_by_handle(buffer, err);
+
+ if (!buf) {
+ return NIL;
+ }
+
+ return dict_set_var(buf->b_vars, name, NIL, true, true, err);
+}
+
+/// Sets a window-scoped (w:) variable
+///
+/// @deprecated
+///
+/// @param window Window handle, or 0 for current window
+/// @param name Variable name
+/// @param value Variable value
+/// @param[out] err Error details, if any
+/// @return Old value or 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`.
+Object window_set_var(Window window, String name, Object value, Error *err)
+{
+ win_T *win = find_window_by_handle(window, err);
+
+ if (!win) {
+ return NIL;
+ }
+
+ return dict_set_var(win->w_vars, name, value, false, true, err);
+}
+
+/// Removes a window-scoped (w:) variable
+///
+/// @deprecated
+///
+/// @param window Window handle, or 0 for current window
+/// @param name variable name
+/// @param[out] err Error details, if any
+/// @return Old value
+Object window_del_var(Window window, String name, Error *err)
+{
+ win_T *win = find_window_by_handle(window, err);
+
+ if (!win) {
+ return NIL;
+ }
+
+ return dict_set_var(win->w_vars, name, NIL, true, true, err);
+}
+
+/// Sets a tab-scoped (t:) variable
+///
+/// @deprecated
+///
+/// @param tabpage Tabpage handle, or 0 for current tabpage
+/// @param name Variable name
+/// @param value Variable value
+/// @param[out] err Error details, if any
+/// @return Old value or 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`.
+Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err)
+{
+ tabpage_T *tab = find_tab_by_handle(tabpage, err);
+
+ if (!tab) {
+ return NIL;
+ }
+
+ return dict_set_var(tab->tp_vars, name, value, false, true, err);
+}
+
+/// Removes a tab-scoped (t:) variable
+///
+/// @deprecated
+///
+/// @param tabpage Tabpage handle, or 0 for current tabpage
+/// @param name Variable name
+/// @param[out] err Error details, if any
+/// @return Old value
+Object tabpage_del_var(Tabpage tabpage, String name, Error *err)
+{
+ tabpage_T *tab = find_tab_by_handle(tabpage, err);
+
+ if (!tab) {
+ return NIL;
+ }
+
+ return dict_set_var(tab->tp_vars, name, NIL, true, true, err);
+}
+
+/// @deprecated
+/// @see nvim_set_var
+/// @warning May return nil if there was no previous value
+/// OR if previous value was `v:null`.
+/// @return Old value or nil if there was no previous value.
+Object vim_set_var(String name, Object value, Error *err)
+{
+ return dict_set_var(&globvardict, name, value, false, true, err);
+}
+
+/// @deprecated
+/// @see nvim_del_var
+Object vim_del_var(String name, Error *err)
+{
+ return dict_set_var(&globvardict, name, NIL, true, true, err);
+}
+
+static int64_t convert_index(int64_t index)
+{
+ return index < 0 ? index - 1 : index;
+}
diff --git a/src/nvim/api/deprecated.h b/src/nvim/api/deprecated.h
new file mode 100644
index 0000000000..79095167e1
--- /dev/null
+++ b/src/nvim/api/deprecated.h
@@ -0,0 +1,11 @@
+#ifndef NVIM_API_DEPRECATED_H
+#define NVIM_API_DEPRECATED_H
+
+#include <stdint.h>
+
+#include "nvim/api/private/defs.h"
+
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "api/deprecated.h.generated.h"
+#endif
+#endif // NVIM_API_DEPRECATED_H
diff --git a/src/nvim/api/private/dispatch.c b/src/nvim/api/private/dispatch.c
index 2975df3c68..eae4581f42 100644
--- a/src/nvim/api/private/dispatch.c
+++ b/src/nvim/api/private/dispatch.c
@@ -19,6 +19,7 @@
#include "nvim/api/ui.h"
#include "nvim/api/vim.h"
#include "nvim/api/window.h"
+#include "nvim/api/deprecated.h"
static Map(String, MsgpackRpcRequestHandler) *methods = NULL;
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 2c99d3426c..8f224e8c78 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -820,6 +820,10 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs,
}
buf_T *target_buf = find_buffer_by_handle(buffer, err);
+ if (!target_buf) {
+ return;
+ }
+
MapArguments parsed_args;
memset(&parsed_args, 0, sizeof(parsed_args));
if (parse_keymap_opts(opts, &parsed_args, err)) {
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h
index 271fd5b485..055abb797f 100644
--- a/src/nvim/api/private/helpers.h
+++ b/src/nvim/api/private/helpers.h
@@ -16,6 +16,7 @@
#define BOOLEAN_OBJ(b) ((Object) { \
.type = kObjectTypeBoolean, \
.data.boolean = b })
+#define BOOL(b) BOOLEAN_OBJ(b)
#define INTEGER_OBJ(i) ((Object) { \
.type = kObjectTypeInteger, \
@@ -29,6 +30,8 @@
.type = kObjectTypeString, \
.data.string = s })
+#define CSTR_TO_OBJ(s) STRING_OBJ(cstr_to_string(s))
+
#define BUFFER_OBJ(s) ((Object) { \
.type = kObjectTypeBuffer, \
.data.integer = s })
@@ -59,6 +62,8 @@
#define PUT(dict, k, v) \
kv_push(dict, ((KeyValuePair) { .key = cstr_to_string(k), .value = v }))
+#define PUT_BOOL(dict, name, condition) PUT(dict, name, BOOLEAN_OBJ(condition));
+
#define ADD(array, item) \
kv_push(array, item)
diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c
index dd17bc03e5..5f727dbc38 100644
--- a/src/nvim/api/tabpage.c
+++ b/src/nvim/api/tabpage.c
@@ -97,48 +97,6 @@ void nvim_tabpage_del_var(Tabpage tabpage, String name, Error *err)
dict_set_var(tab->tp_vars, name, NIL, true, false, err);
}
-/// Sets a tab-scoped (t:) variable
-///
-/// @deprecated
-///
-/// @param tabpage Tabpage handle, or 0 for current tabpage
-/// @param name Variable name
-/// @param value Variable value
-/// @param[out] err Error details, if any
-/// @return Old value or 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`.
-Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err)
-{
- tabpage_T *tab = find_tab_by_handle(tabpage, err);
-
- if (!tab) {
- return (Object) OBJECT_INIT;
- }
-
- return dict_set_var(tab->tp_vars, name, value, false, true, err);
-}
-
-/// Removes a tab-scoped (t:) variable
-///
-/// @deprecated
-///
-/// @param tabpage Tabpage handle, or 0 for current tabpage
-/// @param name Variable name
-/// @param[out] err Error details, if any
-/// @return Old value
-Object tabpage_del_var(Tabpage tabpage, String name, Error *err)
-{
- tabpage_T *tab = find_tab_by_handle(tabpage, err);
-
- if (!tab) {
- return (Object) OBJECT_INIT;
- }
-
- return dict_set_var(tab->tp_vars, name, NIL, true, true, err);
-}
-
/// Gets the current window in a tabpage
///
/// @param tabpage Tabpage handle, or 0 for current tabpage
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 77002697fe..1e972e01be 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -15,6 +15,7 @@
#include "nvim/api/private/dispatch.h"
#include "nvim/api/buffer.h"
#include "nvim/api/window.h"
+#include "nvim/api/deprecated.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/lua/executor.h"
@@ -479,15 +480,6 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt,
return cstr_as_string(ptr);
}
-/// @deprecated
-/// @see nvim_exec
-String nvim_command_output(String command, Error *err)
- FUNC_API_SINCE(1)
- FUNC_API_DEPRECATED_SINCE(7)
-{
- return nvim_exec(command, true, err);
-}
-
/// Evaluates a VimL |expression|.
/// Dictionaries and Lists are recursively expanded.
///
@@ -534,16 +526,6 @@ Object nvim_eval(String expr, Error *err)
return rv;
}
-/// @deprecated Use nvim_exec_lua() instead.
-/// @see nvim_exec_lua
-Object nvim_execute_lua(String code, Array args, Error *err)
- FUNC_API_SINCE(3)
- FUNC_API_DEPRECATED_SINCE(7)
- FUNC_API_REMOTE_ONLY
-{
- return nlua_exec(code, args, err);
-}
-
/// Execute Lua code. Parameters (if any) are available as `...` inside the
/// chunk. The chunk can return a value.
///
@@ -875,6 +857,7 @@ String nvim_get_current_line(Error *err)
/// @param[out] err Error details, if any
void nvim_set_current_line(String line, Error *err)
FUNC_API_SINCE(1)
+ FUNC_API_CHECK_TEXTLOCK
{
buffer_set_line(curbuf->handle, curwin->w_cursor.lnum - 1, line, err);
}
@@ -884,6 +867,7 @@ void nvim_set_current_line(String line, Error *err)
/// @param[out] err Error details, if any
void nvim_del_current_line(Error *err)
FUNC_API_SINCE(1)
+ FUNC_API_CHECK_TEXTLOCK
{
buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, err);
}
@@ -920,23 +904,6 @@ void nvim_del_var(String name, Error *err)
dict_set_var(&globvardict, name, NIL, true, false, err);
}
-/// @deprecated
-/// @see nvim_set_var
-/// @warning May return nil if there was no previous value
-/// OR if previous value was `v:null`.
-/// @return Old value or nil if there was no previous value.
-Object vim_set_var(String name, Object value, Error *err)
-{
- return dict_set_var(&globvardict, name, value, false, true, err);
-}
-
-/// @deprecated
-/// @see nvim_del_var
-Object vim_del_var(String name, Error *err)
-{
- return dict_set_var(&globvardict, name, NIL, true, true, err);
-}
-
/// Gets a v: variable.
///
/// @param name Variable name
@@ -970,6 +937,47 @@ Object nvim_get_option(String name, Error *err)
return get_option_from(NULL, SREQ_GLOBAL, name, err);
}
+/// Gets the option information for all options.
+///
+/// The dictionary has the full option names as keys and option metadata
+/// dictionaries as detailed at |nvim_get_option_info|.
+///
+/// @return dictionary of all options
+Dictionary nvim_get_all_options_info(Error *err)
+ FUNC_API_SINCE(7)
+{
+ return get_all_vimoptions();
+}
+
+/// Gets the option information for one option
+///
+/// Resulting dictionary has keys:
+/// - name: Name of the option (like 'filetype')
+/// - shortname: Shortened name of the option (like 'ft')
+/// - type: type of option ("string", "integer" or "boolean")
+/// - default: The default value for the option
+/// - was_set: Whether the option was set.
+///
+/// - last_set_sid: Last set script id (if any)
+/// - last_set_linenr: line number where option was set
+/// - last_set_chan: Channel where option was set (0 for local)
+///
+/// - scope: one of "global", "win", or "buf"
+/// - global_local: whether win or buf option has a global value
+///
+/// - commalist: List of comma separated values
+/// - flaglist: List of single char flags
+///
+///
+/// @param name Option name
+/// @param[out] err Error details, if any
+/// @return Option Information
+Dictionary nvim_get_option_info(String name, Error *err)
+ FUNC_API_SINCE(7)
+{
+ return get_vimoption(name, err);
+}
+
/// Sets an option value.
///
/// @param channel_id
@@ -1054,6 +1062,7 @@ Buffer nvim_get_current_buf(void)
/// @param[out] err Error details, if any
void nvim_set_current_buf(Buffer buffer, Error *err)
FUNC_API_SINCE(1)
+ FUNC_API_CHECK_TEXTLOCK
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -1108,6 +1117,7 @@ Window nvim_get_current_win(void)
/// @param[out] err Error details, if any
void nvim_set_current_win(Window window, Error *err)
FUNC_API_SINCE(1)
+ FUNC_API_CHECK_TEXTLOCK
{
win_T *win = find_window_by_handle(window, err);
@@ -1257,6 +1267,7 @@ fail:
Window nvim_open_win(Buffer buffer, Boolean enter, Dictionary config,
Error *err)
FUNC_API_SINCE(6)
+ FUNC_API_CHECK_TEXTLOCK
{
FloatConfig fconfig = FLOAT_CONFIG_INIT;
if (!parse_float_config(config, &fconfig, false, err)) {
@@ -1321,6 +1332,7 @@ Tabpage nvim_get_current_tabpage(void)
/// @param[out] err Error details, if any
void nvim_set_current_tabpage(Tabpage tabpage, Error *err)
FUNC_API_SINCE(1)
+ FUNC_API_CHECK_TEXTLOCK
{
tabpage_T *tp = find_tab_by_handle(tabpage, err);
@@ -1405,6 +1417,7 @@ Dictionary nvim_get_namespaces(void)
/// - false: Client must cancel the paste.
Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err)
FUNC_API_SINCE(6)
+ FUNC_API_CHECK_TEXTLOCK
{
static bool draining = false;
bool cancel = false;
@@ -1477,6 +1490,7 @@ theend:
void nvim_put(ArrayOf(String) lines, String type, Boolean after,
Boolean follow, Error *err)
FUNC_API_SINCE(6)
+ FUNC_API_CHECK_TEXTLOCK
{
yankreg_T *reg = xcalloc(sizeof(yankreg_T), 1);
if (!prepare_yankreg_from_object(reg, type, lines.size)) {
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index f09a03f592..f4af1632ec 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -44,6 +44,7 @@ Buffer nvim_win_get_buf(Window window, Error *err)
/// @param[out] err Error details, if any
void nvim_win_set_buf(Window window, Buffer buffer, Error *err)
FUNC_API_SINCE(5)
+ FUNC_API_CHECK_TEXTLOCK
{
win_T *win = find_window_by_handle(window, err), *save_curwin = curwin;
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -288,48 +289,6 @@ void nvim_win_del_var(Window window, String name, Error *err)
dict_set_var(win->w_vars, name, NIL, true, false, err);
}
-/// Sets a window-scoped (w:) variable
-///
-/// @deprecated
-///
-/// @param window Window handle, or 0 for current window
-/// @param name Variable name
-/// @param value Variable value
-/// @param[out] err Error details, if any
-/// @return Old value or 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`.
-Object window_set_var(Window window, String name, Object value, Error *err)
-{
- win_T *win = find_window_by_handle(window, err);
-
- if (!win) {
- return (Object) OBJECT_INIT;
- }
-
- return dict_set_var(win->w_vars, name, value, false, true, err);
-}
-
-/// Removes a window-scoped (w:) variable
-///
-/// @deprecated
-///
-/// @param window Window handle, or 0 for current window
-/// @param name variable name
-/// @param[out] err Error details, if any
-/// @return Old value
-Object window_del_var(Window window, String name, Error *err)
-{
- win_T *win = find_window_by_handle(window, err);
-
- if (!win) {
- return (Object) OBJECT_INIT;
- }
-
- return dict_set_var(win->w_vars, name, NIL, true, true, err);
-}
-
/// Gets a window option value
///
/// @param window Window handle, or 0 for current window
@@ -542,6 +501,7 @@ Dictionary nvim_win_get_config(Window window, Error *err)
/// @param[out] err Error details, if any
void nvim_win_close(Window window, Boolean force, Error *err)
FUNC_API_SINCE(6)
+ FUNC_API_CHECK_TEXTLOCK
{
win_T *win = find_window_by_handle(window, err);
if (!win) {