From 46a87a5d2bac598fed0870f0d3c926087f95d30f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 05:19:04 -0500 Subject: refactor(api): VALIDATE macros #22187 Problem: - API validation involves too much boilerplate. - API validation errors are not consistently worded. Solution: Introduce some macros. Currently these are clumsy, but they at least help with consistency and avoid some nesting. --- src/nvim/api/buffer.c | 153 +++++++++++++++++++------------------------------- 1 file changed, 59 insertions(+), 94 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index fe9e6077d6..b2e78db278 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -16,6 +16,7 @@ #include "nvim/api/buffer.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" +#include "nvim/api/private/validate.h" #include "nvim/ascii.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" @@ -179,11 +180,9 @@ Boolean nvim_buf_attach(uint64_t channel_id, Buffer buffer, Boolean send_buffer, if (is_lua) { for (size_t j = 0; cbs[j].name; j++) { if (strequal(cbs[j].name, k.data)) { - if (v->type != kObjectTypeLuaRef) { - api_set_error(err, kErrorTypeValidation, - "%s is not a function", cbs[j].name); + VALIDATE_T(cbs[j].name, kObjectTypeLuaRef, v->type, { goto error; - } + }); *(cbs[j].dest) = v->data.luaref; v->data.luaref = LUA_NOREF; key_used = true; @@ -194,26 +193,23 @@ Boolean nvim_buf_attach(uint64_t channel_id, Buffer buffer, Boolean send_buffer, if (key_used) { continue; } else if (strequal("utf_sizes", k.data)) { - if (v->type != kObjectTypeBoolean) { - api_set_error(err, kErrorTypeValidation, "utf_sizes must be boolean"); + VALIDATE_T("utf_sizes", kObjectTypeBoolean, v->type, { goto error; - } + }); cb.utf_sizes = v->data.boolean; key_used = true; } else if (strequal("preview", k.data)) { - if (v->type != kObjectTypeBoolean) { - api_set_error(err, kErrorTypeValidation, "preview must be boolean"); + VALIDATE_T("preview", kObjectTypeBoolean, v->type, { goto error; - } + }); cb.preview = v->data.boolean; key_used = true; } } - if (!key_used) { - api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); + VALIDATE_S(key_used, "key", k.data, { goto error; - } + }); } return buf_updates_register(buf, channel_id, cb, send_buffer); @@ -297,10 +293,9 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id, start = normalize_index(buf, start, true, &oob); end = normalize_index(buf, end, true, &oob); - if (strict_indexing && oob) { - api_set_error(err, kErrorTypeValidation, "Index out of bounds"); + VALIDATE((!strict_indexing || !oob), "Index out of bounds", { return rv; - } + }); if (start >= end) { // Return 0-length array @@ -328,20 +323,15 @@ end: static bool check_string_array(Array arr, bool disallow_nl, Error *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"); + VALIDATE_T("replacement item", kObjectTypeString, arr.items[i].type, { 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"); + VALIDATE(!memchr(l.data, NL, l.size), "String cannot contain newlines", { return false; - } + }); } } return true; @@ -383,17 +373,12 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ start = normalize_index(buf, start, true, &oob); end = normalize_index(buf, end, true, &oob); - if (strict_indexing && oob) { - api_set_error(err, kErrorTypeValidation, "Index out of bounds"); + VALIDATE((!strict_indexing || !oob), "Index out of bounds", { return; - } - - if (start > end) { - api_set_error(err, - kErrorTypeValidation, - "Argument \"start\" is higher than \"end\""); + }); + VALIDATE((start <= end), "\"start\" is higher than \"end\"", { return; - } + }); bool disallow_nl = (channel_id != VIML_INTERNAL_CALL); if (!check_string_array(replacement, disallow_nl, err)) { @@ -453,10 +438,9 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ for (size_t i = 0; i < to_replace; i++) { int64_t lnum = start + (int64_t)i; - if (lnum >= MAXLNUM) { - api_set_error(err, kErrorTypeValidation, "Index value is too high"); + VALIDATE(lnum < MAXLNUM, "Index value is too high", { goto end; - } + }); if (ml_replace((linenr_T)lnum, lines[i], false) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to replace line"); @@ -473,10 +457,9 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ for (size_t i = to_replace; i < new_len; i++) { int64_t lnum = start + (int64_t)i - 1; - if (lnum >= MAXLNUM) { - api_set_error(err, kErrorTypeValidation, "Index value is too high"); + VALIDATE(lnum < MAXLNUM, "Index value is too high", { goto end; - } + }); if (ml_append((linenr_T)lnum, lines[i], 0, false) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to insert line"); @@ -563,16 +546,14 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In // 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, false, &oob); - if (oob) { - api_set_error(err, kErrorTypeValidation, "start_row out of bounds"); + VALIDATE((!oob), "start_row out of bounds", { return; - } + }); end_row = normalize_index(buf, end_row, false, &oob); - if (oob) { - api_set_error(err, kErrorTypeValidation, "end_row out of bounds"); + VALIDATE((!oob), "end_row out of bounds", { return; - } + }); char *str_at_start = NULL; char *str_at_end = NULL; @@ -580,23 +561,21 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In // Another call to ml_get_buf() may free the line, so make a copy. str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row, false)); size_t len_at_start = strlen(str_at_start); - if (start_col < 0 || (size_t)start_col > len_at_start) { - api_set_error(err, kErrorTypeValidation, "start_col out of bounds"); + VALIDATE((start_col >= 0 && (size_t)start_col <= len_at_start), "start_col out of bounds", { goto early_end; - } + }); // Another call to ml_get_buf() may free the line, so make a copy. str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)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"); + VALIDATE((end_col >= 0 && (size_t)end_col <= len_at_end), "end_col out of bounds", { goto early_end; - } + }); - if (start_row > end_row || (end_row == start_row && start_col > end_col)) { - api_set_error(err, kErrorTypeValidation, "start is higher than end"); + VALIDATE((start_row <= end_row && !(end_row == start_row && start_col > end_col)), + "start is higher than end", { goto early_end; - } + }); bool disallow_nl = (channel_id != VIML_INTERNAL_CALL); if (!check_string_array(replacement, disallow_nl, err)) { @@ -702,10 +681,9 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In 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"); + VALIDATE((lnum < MAXLNUM), "Index value is too high", { goto end; - } + }); if (ml_replace((linenr_T)lnum, lines[i], false) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to replace line"); @@ -720,10 +698,9 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In 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"); + VALIDATE((lnum < MAXLNUM), "Index value is too high", { goto end; - } + }); if (ml_append((linenr_T)lnum, lines[i], 0, false) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to insert line"); @@ -800,10 +777,9 @@ ArrayOf(String) nvim_buf_get_text(uint64_t channel_id, Buffer buffer, { Array rv = ARRAY_DICT_INIT; - if (opts.size > 0) { - api_set_error(err, kErrorTypeValidation, "opts dict isn't empty"); + VALIDATE((opts.size == 0), "opts dict isn't empty", { return rv; - } + }); buf_T *buf = find_buffer_by_handle(buffer, err); @@ -820,18 +796,16 @@ ArrayOf(String) nvim_buf_get_text(uint64_t channel_id, Buffer buffer, start_row = normalize_index(buf, start_row, false, &oob); end_row = normalize_index(buf, end_row, false, &oob); - if (oob) { - api_set_error(err, kErrorTypeValidation, "Index out of bounds"); + VALIDATE((!oob), "Index out of bounds", { return rv; - } + }); // nvim_buf_get_lines doesn't care if the start row is greater than the end // row (it will just return an empty array), but nvim_buf_get_text does in // order to maintain symmetry with nvim_buf_set_text. - if (start_row > end_row) { - api_set_error(err, kErrorTypeValidation, "start is higher than end"); + VALIDATE((start_row <= end_row), "start is higher than end", { return rv; - } + }); bool replace_nl = (channel_id != VIML_INTERNAL_CALL); @@ -907,10 +881,9 @@ Integer nvim_buf_get_offset(Buffer buffer, Integer index, Error *err) return -1; } - if (index < 0 || index > buf->b_ml.ml_line_count) { - api_set_error(err, kErrorTypeValidation, "Index out of bounds"); + VALIDATE((index >= 0 && index <= buf->b_ml.ml_line_count), "Index out of bounds", { return 0; - } + }); return ml_find_line_or_offset(buf, (int)index + 1, NULL, true); } @@ -1118,8 +1091,9 @@ void nvim_buf_delete(Buffer buffer, Dictionary opts, Error *err) } else if (strequal("unload", k.data)) { unload = api_object_to_bool(v, "unload", false, err); } else { - api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); - return; + VALIDATE_S(false, "key", k.data, { + return; + }); } } @@ -1174,20 +1148,16 @@ Boolean nvim_buf_del_mark(Buffer buffer, String name, Error *err) return res; } - if (name.size != 1) { - api_set_error(err, kErrorTypeValidation, - "Mark name must be a single character"); + VALIDATE_S((name.size == 1), "mark name (must be a single char)", name.data, { return res; - } + }); fmark_T *fm = mark_get(buf, curwin, NULL, kMarkAllNoResolve, *name.data); // fm is NULL when there's no mark with the given name - if (fm == NULL) { - api_set_error(err, kErrorTypeValidation, "Invalid mark name: '%c'", - *name.data); + VALIDATE_S((fm != NULL), "mark name", name.data, { return res; - } + }); // mark.lnum is 0 when the mark is not valid in the buffer, or is not set. if (fm->mark.lnum != 0 && fm->fnum == buf->handle) { @@ -1224,11 +1194,9 @@ Boolean nvim_buf_set_mark(Buffer buffer, String name, Integer line, Integer col, return res; } - if (name.size != 1) { - api_set_error(err, kErrorTypeValidation, - "Mark name must be a single character"); + VALIDATE_S((name.size == 1), "mark name (must be a single char)", name.data, { return res; - } + }); res = set_mark(buf, name, line, col, err); @@ -1257,21 +1225,18 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err) return rv; } - if (name.size != 1) { - api_set_error(err, kErrorTypeValidation, - "Mark name must be a single character"); + VALIDATE_S((name.size == 1), "mark name (must be a single char)", name.data, { return rv; - } + }); fmark_T *fm; pos_T pos; char mark = *name.data; fm = mark_get(buf, curwin, NULL, kMarkAllNoResolve, mark); - if (fm == NULL) { - api_set_error(err, kErrorTypeValidation, "Invalid mark name"); + VALIDATE_S((fm != NULL), "mark name", name.data, { return rv; - } + }); // (0, 0) uppercase/file mark set in another buffer. if (fm->fnum != buf->handle) { pos.lnum = 0; -- cgit From ff3d04b75b4a9314815c37d53ebc4d035a043335 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 08:07:38 -0500 Subject: refactor(api): VALIDATE macros #22256 - VALIDATE() takes a format string - deduplicate check_string_array - VALIDATE_RANGE - validate UI args --- src/nvim/api/buffer.c | 53 +++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index b2e78db278..9c2d14d30f 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -293,7 +293,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id, start = normalize_index(buf, start, true, &oob); end = normalize_index(buf, end, true, &oob); - VALIDATE((!strict_indexing || !oob), "Index out of bounds", { + VALIDATE((!strict_indexing || !oob), "%s", "Index out of bounds", { return rv; }); @@ -320,23 +320,6 @@ end: return rv; } -static bool check_string_array(Array arr, bool disallow_nl, Error *err) -{ - for (size_t i = 0; i < arr.size; i++) { - VALIDATE_T("replacement item", kObjectTypeString, arr.items[i].type, { - return false; - }); - // Disallow newlines in the middle of the line. - if (disallow_nl) { - const String l = arr.items[i].data.string; - VALIDATE(!memchr(l.data, NL, l.size), "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 @@ -373,15 +356,15 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ start = normalize_index(buf, start, true, &oob); end = normalize_index(buf, end, true, &oob); - VALIDATE((!strict_indexing || !oob), "Index out of bounds", { + VALIDATE((!strict_indexing || !oob), "%s", "Index out of bounds", { return; }); - VALIDATE((start <= end), "\"start\" is higher than \"end\"", { + VALIDATE((start <= end), "%s", "'start' is higher than 'end'", { return; }); bool disallow_nl = (channel_id != VIML_INTERNAL_CALL); - if (!check_string_array(replacement, disallow_nl, err)) { + if (!check_string_array(replacement, "replacement string", disallow_nl, err)) { return; } @@ -438,7 +421,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ for (size_t i = 0; i < to_replace; i++) { int64_t lnum = start + (int64_t)i; - VALIDATE(lnum < MAXLNUM, "Index value is too high", { + VALIDATE(lnum < MAXLNUM, "%s", "Index out of bounds", { goto end; }); @@ -457,7 +440,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ for (size_t i = to_replace; i < new_len; i++) { int64_t lnum = start + (int64_t)i - 1; - VALIDATE(lnum < MAXLNUM, "Index value is too high", { + VALIDATE(lnum < MAXLNUM, "%s", "Index out of bounds", { goto end; }); @@ -546,12 +529,12 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In // 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, false, &oob); - VALIDATE((!oob), "start_row out of bounds", { + VALIDATE_RANGE((!oob), "start_row", { return; }); end_row = normalize_index(buf, end_row, false, &oob); - VALIDATE((!oob), "end_row out of bounds", { + VALIDATE_RANGE((!oob), "end_row", { return; }); @@ -561,24 +544,24 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In // Another call to ml_get_buf() may free the line, so make a copy. str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row, false)); size_t len_at_start = strlen(str_at_start); - VALIDATE((start_col >= 0 && (size_t)start_col <= len_at_start), "start_col out of bounds", { + VALIDATE_RANGE((start_col >= 0 && (size_t)start_col <= len_at_start), "start_col", { goto early_end; }); // Another call to ml_get_buf() may free the line, so make a copy. str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)end_row, false)); size_t len_at_end = strlen(str_at_end); - VALIDATE((end_col >= 0 && (size_t)end_col <= len_at_end), "end_col out of bounds", { + VALIDATE_RANGE((end_col >= 0 && (size_t)end_col <= len_at_end), "end_col", { goto early_end; }); VALIDATE((start_row <= end_row && !(end_row == start_row && start_col > end_col)), - "start is higher than end", { + "%s", "'start' is higher than 'end'", { goto early_end; }); bool disallow_nl = (channel_id != VIML_INTERNAL_CALL); - if (!check_string_array(replacement, disallow_nl, err)) { + if (!check_string_array(replacement, "replacement string", disallow_nl, err)) { goto early_end; } @@ -681,7 +664,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In for (size_t i = 0; i < to_replace; i++) { int64_t lnum = start_row + (int64_t)i; - VALIDATE((lnum < MAXLNUM), "Index value is too high", { + VALIDATE((lnum < MAXLNUM), "%s", "Index out of bounds", { goto end; }); @@ -698,7 +681,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In for (size_t i = to_replace; i < new_len; i++) { int64_t lnum = start_row + (int64_t)i - 1; - VALIDATE((lnum < MAXLNUM), "Index value is too high", { + VALIDATE((lnum < MAXLNUM), "%s", "Index out of bounds", { goto end; }); @@ -777,7 +760,7 @@ ArrayOf(String) nvim_buf_get_text(uint64_t channel_id, Buffer buffer, { Array rv = ARRAY_DICT_INIT; - VALIDATE((opts.size == 0), "opts dict isn't empty", { + VALIDATE((opts.size == 0), "%s", "opts dict isn't empty", { return rv; }); @@ -796,14 +779,14 @@ ArrayOf(String) nvim_buf_get_text(uint64_t channel_id, Buffer buffer, start_row = normalize_index(buf, start_row, false, &oob); end_row = normalize_index(buf, end_row, false, &oob); - VALIDATE((!oob), "Index out of bounds", { + VALIDATE((!oob), "%s", "Index out of bounds", { return rv; }); // nvim_buf_get_lines doesn't care if the start row is greater than the end // row (it will just return an empty array), but nvim_buf_get_text does in // order to maintain symmetry with nvim_buf_set_text. - VALIDATE((start_row <= end_row), "start is higher than end", { + VALIDATE((start_row <= end_row), "%s", "'start' is higher than 'end'", { return rv; }); @@ -881,7 +864,7 @@ Integer nvim_buf_get_offset(Buffer buffer, Integer index, Error *err) return -1; } - VALIDATE((index >= 0 && index <= buf->b_ml.ml_line_count), "Index out of bounds", { + VALIDATE((index >= 0 && index <= buf->b_ml.ml_line_count), "%s", "Index out of bounds", { return 0; }); -- cgit From 556f8646c01d1751cf39fe4df9c622899dceab9d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 14:19:28 -0500 Subject: refactor(api): consistent VALIDATE messages #22262 Problem: Validation messages are not consistently formatted. - Parameter names sometimes are NOT quoted. - Descriptive names (non-parameters) sometimes ARE quoted. Solution: Always quote the `name` value passed to a VALIDATE macro _unless_ the value has whitespace. --- src/nvim/api/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 9c2d14d30f..bbdb66988b 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -207,7 +207,7 @@ Boolean nvim_buf_attach(uint64_t channel_id, Buffer buffer, Boolean send_buffer, } } - VALIDATE_S(key_used, "key", k.data, { + VALIDATE_S(key_used, "'opts' key", k.data, { goto error; }); } @@ -1074,7 +1074,7 @@ void nvim_buf_delete(Buffer buffer, Dictionary opts, Error *err) } else if (strequal("unload", k.data)) { unload = api_object_to_bool(v, "unload", false, err); } else { - VALIDATE_S(false, "key", k.data, { + VALIDATE_S(false, "'opts' key", k.data, { return; }); } -- cgit From 7e19cabeb192d2e7f20d7bb965a3f62e1543d2ac Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 28 Feb 2023 12:38:33 +0100 Subject: perf(lsp): only redraw the windows containing LSP tokens redraw! redraws the entire screen instead of just the windows with the buffer which were actually changed. I considered trying to calculating the range for the delta but it looks tricky. Could a follow-up. --- src/nvim/api/buffer.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index bbdb66988b..ca3cf76388 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -248,6 +248,9 @@ void nvim__buf_redraw_range(Buffer buffer, Integer first, Integer last, Error *e if (!buf) { return; } + if (last < 0) { + last = buf->b_ml.ml_line_count; + } redraw_buf_range_later(buf, (linenr_T)first + 1, (linenr_T)last); } -- cgit From a1b045f60a22d366e255dfff1c54ed42ebe49284 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 18:28:49 +0200 Subject: refactor(clang-tidy): remove redundant casts --- src/nvim/api/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index ca3cf76388..10c684941c 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -404,7 +404,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ // 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; + size_t to_delete = (new_len < old_len) ? old_len - new_len : 0; for (size_t i = 0; i < to_delete; i++) { if (ml_delete((linenr_T)start, false) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to delete line"); @@ -648,7 +648,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In // 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; + size_t to_delete = (new_len < old_len) ? 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"); -- cgit From cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 23 May 2023 14:25:10 +0600 Subject: refactor(api): new helper macros Adds new API helper macros `CSTR_AS_OBJ()`, `STATIC_CSTR_AS_OBJ()`, and `STATIC_CSTR_TO_OBJ()`, which cleans up a lot of the current code. These macros will also be used extensively in the upcoming option refactor PRs because then API Objects will be used to get/set options. This PR also modifies pre-existing code to use old API helper macros like `CSTR_TO_OBJ()` to make them cleaner. --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 10c684941c..82a62c3192 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -518,7 +518,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In { MAXSIZE_TEMP_ARRAY(scratch, 1); if (replacement.size == 0) { - ADD_C(scratch, STRING_OBJ(STATIC_CSTR_AS_STRING(""))); + ADD_C(scratch, STATIC_CSTR_AS_OBJ("")); replacement = scratch; } -- cgit From 4e6356559c8cd44dbcaa765d1f39e176064526ec Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 22 Jun 2023 03:44:51 -0700 Subject: test: spellcheck :help (vimdoc) files #24109 Enforce consistent terminology (defined in `gen_help_html.lua:spell_dict`) for common misspellings. This does not spellcheck English in general (perhaps a future TODO, though it may be noisy). --- src/nvim/api/buffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 82a62c3192..4c3faf8d8b 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -112,7 +112,7 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err) /// - byte count of previous contents /// - deleted_codepoints (if `utf_sizes` is true) /// - deleted_codeunits (if `utf_sizes` is true) -/// - on_bytes: lua callback invoked on change. +/// - on_bytes: Lua callback invoked on change. /// This callback receives more granular information about the /// change compared to on_lines. /// Return `true` to detach. @@ -1250,11 +1250,11 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err) /// buffer/window currently, like |termopen()|. /// /// @param buffer Buffer handle, or 0 for current buffer -/// @param fun Function to call inside the buffer (currently lua callable +/// @param fun Function to call inside the buffer (currently Lua callable /// only) /// @param[out] err Error details, if any -/// @return Return value of function. NB: will deepcopy lua values -/// currently, use upvalues to send lua references in and out. +/// @return Return value of function. NB: will deepcopy Lua values +/// currently, use upvalues to send Lua references in and out. Object nvim_buf_call(Buffer buffer, LuaRef fun, Error *err) FUNC_API_SINCE(7) FUNC_API_LUA_ONLY -- cgit From 49a7585981cdf7403e76a614558e602a98e64301 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 23 Jun 2023 12:16:55 +0200 Subject: docs: autocmds, misc --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 4c3faf8d8b..c1aef53dc0 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -84,7 +84,7 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err) /// Activates buffer-update events on a channel, or as Lua callbacks. /// /// Example (Lua): capture buffer updates in a global `events` variable -/// (use "print(vim.inspect(events))" to see its contents): +/// (use "vim.print(events)" to see its contents): ///
lua
 ///   events = {}
 ///   vim.api.nvim_buf_attach(0, false, {
-- 
cgit 


From b6878f5d6387bad667edf75cf6c70e846c3b0428 Mon Sep 17 00:00:00 2001
From: Christian Clason 
Date: Mon, 26 Jun 2023 11:16:55 +0200
Subject: docs: fix misparsed headings (#24162)

Problem: vimdoc parser requires space between column heading and `~`.

Solution: Add space to docs (and mention it). Also edit `luaref.txt`
headings for consistency.
---
 src/nvim/api/buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index c1aef53dc0..5bf7295bb3 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -48,7 +48,7 @@
 ///
 /// \brief For more information on buffers, see |buffers|
 ///
-/// Unloaded Buffers:~
+/// Unloaded Buffers: ~
 ///
 /// Buffers may be unloaded by the |:bunload| command or the buffer's
 /// |'bufhidden'| option. When a buffer is unloaded its file contents are freed
-- 
cgit 


From 3ecd45ded044c47efa76b74e9e3b720fbe27adc7 Mon Sep 17 00:00:00 2001
From: notomo 
Date: Tue, 4 Jul 2023 23:07:55 +0900
Subject: fix(api): allow negative column arguments for nvim_buf_set_text
 (#23501)

---
 src/nvim/api/buffer.c | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 5bf7295bb3..8774aee20b 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -547,6 +547,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
   // Another call to ml_get_buf() may free the line, so make a copy.
   str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row, false));
   size_t len_at_start = strlen(str_at_start);
+  start_col = start_col < 0 ? (int64_t)len_at_start + start_col + 1 : start_col;
   VALIDATE_RANGE((start_col >= 0 && (size_t)start_col <= len_at_start), "start_col", {
     goto early_end;
   });
@@ -554,6 +555,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
   // Another call to ml_get_buf() may free the line, so make a copy.
   str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)end_row, false));
   size_t len_at_end = strlen(str_at_end);
+  end_col = end_col < 0 ? (int64_t)len_at_end + end_col + 1 : end_col;
   VALIDATE_RANGE((end_col >= 0 && (size_t)end_col <= len_at_end), "end_col", {
     goto early_end;
   });
-- 
cgit 


From 77118d0da8badc4135be430f4cbb15bc95bc760f Mon Sep 17 00:00:00 2001
From: Sean Dewar 
Date: Thu, 20 Apr 2023 21:17:25 +0100
Subject: fix(api): use text_locked() to check textlock

Problem: some API functions that check textlock (usually those that can change
curwin or curbuf) can break the cmdwin.

Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already
checks for textlock, cmdwin and `` status.

Add FUNC_API_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the
cmdwin if they can work properly there; the opt-in nature of this attribute
should hopefully help mitigate future bugs.

Also fix a regression in #22634 that made functions checking textlock usable in
`` mappings, and rename FUNC_API_CHECK_TEXTLOCK to FUNC_API_TEXTLOCK.
---
 src/nvim/api/buffer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 8774aee20b..7cd9686544 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -347,7 +347,7 @@ end:
 void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integer end,
                         Boolean strict_indexing, ArrayOf(String) replacement, Error *err)
   FUNC_API_SINCE(1)
-  FUNC_API_CHECK_TEXTLOCK
+  FUNC_API_TEXTLOCK_ALLOW_CMDWIN
 {
   buf_T *buf = find_buffer_by_handle(buffer, err);
 
@@ -1061,7 +1061,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
+  FUNC_API_TEXTLOCK
 {
   buf_T *buf = find_buffer_by_handle(buffer, err);
 
-- 
cgit 


From aa4e47f704c53ab1d825260d2bf34e2872e3ca89 Mon Sep 17 00:00:00 2001
From: Sean Dewar 
Date: Fri, 23 Jun 2023 22:32:07 +0100
Subject: fix(api): disallow some more functions during textlock

Problem: nvim_buf_set_text(), nvim_open_term() and termopen() all change buffer
text, which is forbidden during textlock. Additionally, nvim_open_term() and
termopen() may be used to convert the cmdwin buffer into a terminal buffer,
which is weird.

Solution: Allow nvim_buf_set_text() and nvim_open_term() in the cmdwin, but
disallow nvim_open_term() from converting the cmdwin buffer into a terminal
buffer. termopen() is not allowed in the cmdwin (as it always operates on
curbuf), so just check text_locked().

Also happens to improve the error in #21055: nvim_buf_set_text() was callable
during textlock, but happened to check textlock indirectly via u_save();
however, this caused the error to be overwritten by an unhelpful "Failed to
save undo information" message when msg_list == NULL (e.g: an `` mapping
invoked outside of do_cmdline()).
---
 src/nvim/api/buffer.c | 1 +
 1 file changed, 1 insertion(+)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 7cd9686544..02b97b0ae1 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -515,6 +515,7 @@ end:
 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)
+  FUNC_API_TEXTLOCK_ALLOW_CMDWIN
 {
   MAXSIZE_TEMP_ARRAY(scratch, 1);
   if (replacement.size == 0) {
-- 
cgit 


From 00d2f4b96eb9c8dcb6b9f67e256bb7faa19354db Mon Sep 17 00:00:00 2001
From: "Justin M. Keyes" 
Date: Tue, 4 Jul 2023 19:22:04 +0200
Subject: docs: MAINTAIN.md, nvim_get_mark

---
 src/nvim/api/buffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 02b97b0ae1..a0322556b4 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -1192,8 +1192,9 @@ Boolean nvim_buf_set_mark(Buffer buffer, String name, Integer line, Integer col,
   return res;
 }
 
-/// Returns a tuple (row,col) representing the position of the named mark. See
-/// |mark-motions|.
+/// Returns a `(row,col)` tuple representing the position of the named mark.
+/// "End of line" column position is returned as |v:maxcol| (big number).
+/// See |mark-motions|.
 ///
 /// Marks are (1,0)-indexed. |api-indexing|
 ///
-- 
cgit 


From db8fe63a9398efd57c3ff28aa3d93e45fb70ee1a Mon Sep 17 00:00:00 2001
From: zeertzjq 
Date: Tue, 11 Jul 2023 07:15:46 +0800
Subject: feat(api): add nvim_win_text_height (#24236)

It uses the same code as "scroll_delta" of "win_viewport" UI event to
calculate text height, but is more flexible.
---
 src/nvim/api/buffer.c | 21 ---------------------
 1 file changed, 21 deletions(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index a0322556b4..3b73237b06 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -1334,27 +1334,6 @@ static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra)
   invalidate_botline();
 }
 
-// Normalizes 0-based indexes to buffer line numbers
-static int64_t normalize_index(buf_T *buf, int64_t index, bool end_exclusive, bool *oob)
-{
-  assert(buf->b_ml.ml_line_count > 0);
-  int64_t max_index = buf->b_ml.ml_line_count + (int)end_exclusive - 1;
-  // Fix if < 0
-  index = index < 0 ? max_index + index + 1 : index;
-
-  // Check for oob
-  if (index > max_index) {
-    *oob = true;
-    index = max_index;
-  } else if (index < 0) {
-    *oob = true;
-    index = 0;
-  }
-  // Convert the index to a vim line number
-  index++;
-  return index;
-}
-
 /// Initialise a string array either:
 /// - on the Lua stack (as a table) (if lstate is not NULL)
 /// - as an API array object (if lstate is NULL).
-- 
cgit 


From ca9f4a7cb1fea1ef1f22c011679fd8afa0a5d161 Mon Sep 17 00:00:00 2001
From: zeertzjq 
Date: Fri, 21 Jul 2023 16:30:05 +0800
Subject: docs: also change "vimL" and "viml" to "Vimscript" (#24414)

---
 src/nvim/api/buffer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 3b73237b06..e6c91df521 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -1250,8 +1250,8 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err)
 /// Otherwise a temporary scratch window (called the "autocmd window" for
 /// historical reasons) will be used.
 ///
-/// This is useful e.g. to call vimL functions that only work with the current
-/// buffer/window currently, like |termopen()|.
+/// This is useful e.g. to call Vimscript functions that only work with the
+/// current buffer/window currently, like |termopen()|.
 ///
 /// @param buffer     Buffer handle, or 0 for current buffer
 /// @param fun        Function to call inside the buffer (currently Lua callable
-- 
cgit 


From cefd774fac76b91f5368833555818c80c992c3b1 Mon Sep 17 00:00:00 2001
From: bfredl 
Date: Thu, 24 Aug 2023 15:14:23 +0200
Subject: refactor(memline): distinguish mutating uses of ml_get_buf()

ml_get_buf() takes a third parameters to indicate whether the
caller wants to mutate the memline data in place. However
the vast majority of the call sites is using this function
just to specify a buffer but without any mutation. This makes
it harder to grep for the places which actually perform mutation.

Solution: Remove the bool param from ml_get_buf(). it now works
like ml_get() except for a non-current buffer. Add a new
ml_get_buf_mut() function for the mutating use-case, which can
be grepped along with the other ml_replace() etc functions which
can modify the memline.
---
 src/nvim/api/buffer.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index e6c91df521..4e3468f8d1 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -546,7 +546,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
   char *str_at_end = NULL;
 
   // Another call to ml_get_buf() may free the line, so make a copy.
-  str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row, false));
+  str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row));
   size_t len_at_start = strlen(str_at_start);
   start_col = start_col < 0 ? (int64_t)len_at_start + start_col + 1 : start_col;
   VALIDATE_RANGE((start_col >= 0 && (size_t)start_col <= len_at_start), "start_col", {
@@ -554,7 +554,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
   });
 
   // Another call to ml_get_buf() may free the line, so make a copy.
-  str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)end_row, false));
+  str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)end_row));
   size_t len_at_end = strlen(str_at_end);
   end_col = end_col < 0 ? (int64_t)len_at_end + end_col + 1 : end_col;
   VALIDATE_RANGE((end_col >= 0 && (size_t)end_col <= len_at_end), "end_col", {
@@ -584,7 +584,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
     for (int64_t i = 1; i < end_row - start_row; i++) {
       int64_t lnum = start_row + i;
 
-      const char *bufline = ml_get_buf(buf, (linenr_T)lnum, false);
+      const char *bufline = ml_get_buf(buf, (linenr_T)lnum);
       old_byte += (bcount_t)(strlen(bufline)) + 1;
     }
     old_byte += (bcount_t)end_col + 1;
@@ -1415,7 +1415,7 @@ bool buf_collect_lines(buf_T *buf, size_t n, linenr_T start, int start_idx, bool
       return false;
     }
 
-    char *bufstr = ml_get_buf(buf, lnum, false);
+    char *bufstr = ml_get_buf(buf, lnum);
     push_linestr(lstate, l, bufstr, strlen(bufstr), start_idx + (int)i, replace_nl);
   }
 
-- 
cgit 


From 008154954791001efcc46c28146e21403f3a698b Mon Sep 17 00:00:00 2001
From: bfredl 
Date: Mon, 21 Aug 2023 14:52:17 +0200
Subject: refactor(change): do API changes to buffer without curbuf switch

Most of the messy things when changing a non-current buffer is
not about the buffer, it is about windows. In particular, it is about
`curwin`.

When editing a non-current buffer which is displayed in some other
window in the current tabpage, one such window will be "borrowed" as the
curwin. But this means if two or more non-current windows displayed the buffers,
one of them will be treated differenty. this is not desirable.

In particular, with nvim_buf_set_text, cursor _column_ position was only
corrected for one single window. Two new tests are added: the test
with just one non-current window passes, but the one with two didn't.

Two corresponding such tests were also added for nvim_buf_set_lines.
This already worked correctly on master, but make sure this is
well-tested for future refactors.

Also, nvim_create_buf no longer invokes autocmds just because you happened
to use `scratch=true`. No option value was changed, therefore OptionSet
must not be fired.
---
 src/nvim/api/buffer.c | 97 ++++++++++++++++++++++++++-------------------------
 1 file changed, 49 insertions(+), 48 deletions(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 4e3468f8d1..775b6e8ea7 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -386,27 +386,29 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
   }
 
   try_start();
-  aco_save_T aco;
-  aucmd_prepbuf(&aco, buf);
 
   if (!MODIFIABLE(buf)) {
     api_set_error(err, kErrorTypeException, "Buffer is not 'modifiable'");
     goto end;
   }
 
-  if (u_save((linenr_T)(start - 1), (linenr_T)end) == FAIL) {
+  if (!buf_ensure_loaded(buf)) {
+    goto end;
+  }
+
+  if (u_save_buf(buf, (linenr_T)(start - 1), (linenr_T)end) == FAIL) {
     api_set_error(err, kErrorTypeException, "Failed to save undo information");
     goto end;
   }
 
-  bcount_t deleted_bytes = get_region_bytecount(curbuf, (linenr_T)start, (linenr_T)end, 0, 0);
+  bcount_t deleted_bytes = get_region_bytecount(buf, (linenr_T)start, (linenr_T)end, 0, 0);
 
   // 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) ? old_len - new_len : 0;
   for (size_t i = 0; i < to_delete; i++) {
-    if (ml_delete((linenr_T)start, false) == FAIL) {
+    if (ml_delete_buf(buf, (linenr_T)start, false) == FAIL) {
       api_set_error(err, kErrorTypeException, "Failed to delete line");
       goto end;
     }
@@ -428,7 +430,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
       goto end;
     });
 
-    if (ml_replace((linenr_T)lnum, lines[i], false) == FAIL) {
+    if (ml_replace_buf(buf, (linenr_T)lnum, lines[i], false) == FAIL) {
       api_set_error(err, kErrorTypeException, "Failed to replace line");
       goto end;
     }
@@ -447,7 +449,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
       goto end;
     });
 
-    if (ml_append((linenr_T)lnum, lines[i], 0, false) == FAIL) {
+    if (ml_append_buf(buf, (linenr_T)lnum, lines[i], 0, false) == FAIL) {
       api_set_error(err, kErrorTypeException, "Failed to insert line");
       goto end;
     }
@@ -462,20 +464,18 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
 
   // Adjust marks. Invalidate any which lie in the
   // changed range, and move any in the remainder of the buffer.
-  // Only adjust marks if we managed to switch to a window that holds
-  // the buffer, otherwise line numbers will be invalid.
-  mark_adjust((linenr_T)start,
-              (linenr_T)(end - 1),
-              MAXLNUM,
-              (linenr_T)extra,
-              kExtmarkNOOP);
-
-  extmark_splice(curbuf, (int)start - 1, 0, (int)(end - start), 0,
+  mark_adjust_buf(buf, (linenr_T)start, (linenr_T)(end - 1), MAXLNUM, (linenr_T)extra,
+                  true, true, kExtmarkNOOP);
+
+  extmark_splice(buf, (int)start - 1, 0, (int)(end - start), 0,
                  deleted_bytes, (int)new_len, 0, inserted_bytes,
                  kExtmarkUndo);
 
-  changed_lines((linenr_T)start, 0, (linenr_T)end, (linenr_T)extra, true);
-  fix_cursor((linenr_T)start, (linenr_T)end, (linenr_T)extra);
+  changed_lines(buf, (linenr_T)start, 0, (linenr_T)end, (linenr_T)extra, true);
+  if (curwin->w_buffer == buf) {
+    // mark_adjust_buf handles non-current windows
+    fix_cursor(curwin, (linenr_T)start, (linenr_T)end, (linenr_T)extra);
+  }
 
 end:
   for (size_t i = 0; i < new_len; i++) {
@@ -483,7 +483,6 @@ end:
   }
 
   xfree(lines);
-  aucmd_restbuf(&aco);
   try_end(err);
 }
 
@@ -630,17 +629,19 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
   }
 
   try_start();
-  aco_save_T aco;
-  aucmd_prepbuf(&aco, buf);
 
   if (!MODIFIABLE(buf)) {
     api_set_error(err, kErrorTypeException, "Buffer is not 'modifiable'");
     goto end;
   }
 
+  if (!buf_ensure_loaded(buf)) {
+    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) {
+  if (u_save_buf(buf, (linenr_T)start_row - 1, (linenr_T)end_row + 1) == FAIL) {
     api_set_error(err, kErrorTypeException, "Failed to save undo information");
     goto end;
   }
@@ -653,7 +654,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
   // repeatedly deleting line "start".
   size_t to_delete = (new_len < old_len) ? old_len - new_len : 0;
   for (size_t i = 0; i < to_delete; i++) {
-    if (ml_delete((linenr_T)start_row, false) == FAIL) {
+    if (ml_delete_buf(buf, (linenr_T)start_row, false) == FAIL) {
       api_set_error(err, kErrorTypeException, "Failed to delete line");
       goto end;
     }
@@ -674,7 +675,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
       goto end;
     });
 
-    if (ml_replace((linenr_T)lnum, lines[i], false) == FAIL) {
+    if (ml_replace_buf(buf, (linenr_T)lnum, lines[i], false) == FAIL) {
       api_set_error(err, kErrorTypeException, "Failed to replace line");
       goto end;
     }
@@ -691,7 +692,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
       goto end;
     });
 
-    if (ml_append((linenr_T)lnum, lines[i], 0, false) == FAIL) {
+    if (ml_append_buf(buf, (linenr_T)lnum, lines[i], 0, false) == FAIL) {
       api_set_error(err, kErrorTypeException, "Failed to insert line");
       goto end;
     }
@@ -702,35 +703,37 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
     extra++;
   }
 
+  colnr_T col_extent = (colnr_T)(end_col
+                                 - ((end_row == start_row) ? start_col : 0));
+
   // 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,
-              (linenr_T)extra,
-              kExtmarkNOOP);
+  // Do not adjust any cursors. need to use column-aware logic (below)
+  mark_adjust_buf(buf, (linenr_T)start_row, (linenr_T)end_row, MAXLNUM, (linenr_T)extra,
+                  true, false, 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 + 1, (linenr_T)extra, true);
+  changed_lines(buf, (linenr_T)start_row, 0, (linenr_T)end_row + 1, (linenr_T)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;
+  FOR_ALL_TAB_WINDOWS(tp, win) {
+    if (win->w_buffer == buf) {
+      // adjust cursor like an extmark ( i e it was inside last_part_len)
+      if (win->w_cursor.lnum == end_row && win->w_cursor.col > end_col) {
+        win->w_cursor.col -= col_extent - (colnr_T)last_item.size;
+      }
+      fix_cursor(win, (linenr_T)start_row, (linenr_T)end_row, (linenr_T)extra);
+    }
   }
-  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);
 
 early_end:
@@ -1317,21 +1320,19 @@ Dictionary nvim__buf_stats(Buffer buffer, Error *err)
 
 // Check if deleting lines made the cursor position invalid.
 // Changed lines from `lo` to `hi`; added `extra` lines (negative if deleted).
-static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra)
+static void fix_cursor(win_T *win, linenr_T lo, linenr_T hi, linenr_T extra)
 {
-  if (curwin->w_cursor.lnum >= lo) {
+  if (win->w_cursor.lnum >= lo) {
     // Adjust cursor position if it's in/after the changed lines.
-    if (curwin->w_cursor.lnum >= hi) {
-      curwin->w_cursor.lnum += extra;
-      check_cursor_col();
+    if (win->w_cursor.lnum >= hi) {
+      win->w_cursor.lnum += extra;
     } else if (extra < 0) {
-      check_cursor();
-    } else {
-      check_cursor_col();
+      check_cursor_lnum(win);
     }
-    changed_cline_bef_curs();
+    check_cursor_col_win(win);
+    changed_cline_bef_curs(win);
   }
-  invalidate_botline();
+  invalidate_botline(win);
 }
 
 /// Initialise a string array either:
-- 
cgit 


From 9b9030ff2ca820d4c4f4b559f86b0f9a3496645b Mon Sep 17 00:00:00 2001
From: bfredl 
Date: Sun, 27 Aug 2023 11:20:59 +0200
Subject: fix(api): fix inconsistent behavior of topline touched in recent
 refactor

The change in #24824 0081549 was not a regression, however it was an
incomplete change. Unfortunately some common plugins come to depend on
this exising self-inconsistent behavior. These plugins are going to need
to update for 0.10

nvim_buf_set_lines used to NOT adjust the topline correctly if a buffer
was displayed in just one window. However, if displayed in multiple
windows, it was correctly adjusted for any window not deemed the
current window for the buffer (which could be an arbitrary choice if the
buffer was not already current, as noted in the last rafactor)

This fixes so that all windows have their topline adjusted. The added
tests show this behavior, which should be the reasonable one.
---
 src/nvim/api/buffer.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 775b6e8ea7..d36f0dd050 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -472,9 +472,11 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
                  kExtmarkUndo);
 
   changed_lines(buf, (linenr_T)start, 0, (linenr_T)end, (linenr_T)extra, true);
-  if (curwin->w_buffer == buf) {
-    // mark_adjust_buf handles non-current windows
-    fix_cursor(curwin, (linenr_T)start, (linenr_T)end, (linenr_T)extra);
+
+  FOR_ALL_TAB_WINDOWS(tp, win) {
+    if (win->w_buffer == buf) {
+      fix_cursor(win, (linenr_T)start, (linenr_T)end, (linenr_T)extra);
+    }
   }
 
 end:
@@ -710,7 +712,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
   // changed range, and move any in the remainder of the buffer.
   // Do not adjust any cursors. need to use column-aware logic (below)
   mark_adjust_buf(buf, (linenr_T)start_row, (linenr_T)end_row, MAXLNUM, (linenr_T)extra,
-                  true, false, kExtmarkNOOP);
+                  true, true, kExtmarkNOOP);
 
   extmark_splice(buf, (int)start_row - 1, (colnr_T)start_col,
                  (int)(end_row - start_row), col_extent, old_byte,
-- 
cgit 


From 0a81ec14a4c006822509b06396871509140b7a79 Mon Sep 17 00:00:00 2001
From: bfredl 
Date: Mon, 28 Aug 2023 11:35:09 +0200
Subject: fix(api): better topline adjustments in nvim_buf_set_lines

Some more reasonable defaults for topline:
  - if topline was replaced with another line, that now becomes topline
  - if line was inserted just before topline, display it. This is more
    similar to the previous API behavior.
---
 src/nvim/api/buffer.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index d36f0dd050..b8cb09ceb3 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -464,7 +464,8 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
 
   // Adjust marks. Invalidate any which lie in the
   // changed range, and move any in the remainder of the buffer.
-  mark_adjust_buf(buf, (linenr_T)start, (linenr_T)(end - 1), MAXLNUM, (linenr_T)extra,
+  linenr_T adjust = end > start ? MAXLNUM : 0;
+  mark_adjust_buf(buf, (linenr_T)start, (linenr_T)(end - 1), adjust, (linenr_T)extra,
                   true, true, kExtmarkNOOP);
 
   extmark_splice(buf, (int)start - 1, 0, (int)(end - start), 0,
@@ -711,7 +712,8 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
   // Adjust marks. Invalidate any which lie in the
   // changed range, and move any in the remainder of the buffer.
   // Do not adjust any cursors. need to use column-aware logic (below)
-  mark_adjust_buf(buf, (linenr_T)start_row, (linenr_T)end_row, MAXLNUM, (linenr_T)extra,
+  linenr_T adjust = end_row >= start_row ? MAXLNUM : 0;
+  mark_adjust_buf(buf, (linenr_T)start_row, (linenr_T)end_row, adjust, (linenr_T)extra,
                   true, true, kExtmarkNOOP);
 
   extmark_splice(buf, (int)start_row - 1, (colnr_T)start_col,
-- 
cgit 


From d22172f36bbe147f3aa6b76a1c43ae445f481c2e Mon Sep 17 00:00:00 2001
From: Sergey Slipchenko 
Date: Mon, 11 Sep 2023 08:16:03 +0400
Subject: fix(api): more intuitive cursor updates in nvim_buf_set_text

Fixes #22526
---
 src/nvim/api/buffer.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 81 insertions(+), 4 deletions(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index b8cb09ceb3..baac694848 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -504,7 +504,10 @@ end:
 ///
 /// Prefer |nvim_buf_set_lines()| if you are only adding or deleting entire lines.
 ///
+/// Prefer |nvim_put()| if you want to insert text at the cursor position.
+///
 /// @see |nvim_buf_set_lines()|
+/// @see |nvim_put()|
 ///
 /// @param channel_id
 /// @param buffer           Buffer handle, or 0 for current buffer
@@ -725,11 +728,12 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
 
   FOR_ALL_TAB_WINDOWS(tp, win) {
     if (win->w_buffer == buf) {
-      // adjust cursor like an extmark ( i e it was inside last_part_len)
-      if (win->w_cursor.lnum == end_row && win->w_cursor.col > end_col) {
-        win->w_cursor.col -= col_extent - (colnr_T)last_item.size;
+      if (win->w_cursor.lnum >= start_row && win->w_cursor.lnum <= end_row) {
+        fix_cursor_cols(win, (linenr_T)start_row, (colnr_T)start_col, (linenr_T)end_row,
+                        (colnr_T)end_col, (linenr_T)new_len, (colnr_T)last_item.size);
+      } else {
+        fix_cursor(win, (linenr_T)start_row, (linenr_T)end_row, (linenr_T)extra);
       }
-      fix_cursor(win, (linenr_T)start_row, (linenr_T)end_row, (linenr_T)extra);
     }
   }
 
@@ -1339,6 +1343,79 @@ static void fix_cursor(win_T *win, linenr_T lo, linenr_T hi, linenr_T extra)
   invalidate_botline(win);
 }
 
+/// Fix cursor position after replacing text
+/// between (start_row, start_col) and (end_row, end_col).
+///
+/// win->w_cursor.lnum is assumed to be >= start_row and <= end_row.
+static void fix_cursor_cols(win_T *win, linenr_T start_row, colnr_T start_col, linenr_T end_row,
+                            colnr_T end_col, linenr_T new_rows, colnr_T new_cols_at_end_row)
+{
+  colnr_T mode_col_adj = win == curwin && (State & MODE_INSERT) ? 0 : 1;
+
+  colnr_T end_row_change_start = new_rows == 1 ? start_col : 0;
+  colnr_T end_row_change_end = end_row_change_start + new_cols_at_end_row;
+
+  // check if cursor is after replaced range or not
+  if (win->w_cursor.lnum == end_row && win->w_cursor.col + mode_col_adj > end_col) {
+    // if cursor is after replaced range, it's shifted
+    // to keep it's position the same, relative to end_col
+
+    linenr_T old_rows = end_row - start_row + 1;
+    win->w_cursor.lnum += new_rows - old_rows;
+    win->w_cursor.col += end_row_change_end - end_col;
+  } else {
+    // if cursor is inside replaced range
+    // and the new range got smaller,
+    // it's shifted to keep it inside the new range
+    //
+    // if cursor is before range or range did not
+    // got smaller, position is not changed
+
+    colnr_T old_coladd = win->w_cursor.coladd;
+
+    // it's easier to work with a single value here.
+    // col and coladd are fixed by a later call
+    // to check_cursor_col_win when necessary
+    win->w_cursor.col += win->w_cursor.coladd;
+    win->w_cursor.coladd = 0;
+
+    linenr_T new_end_row = start_row + new_rows - 1;
+
+    // make sure cursor row is in the new row range
+    if (win->w_cursor.lnum > new_end_row) {
+      win->w_cursor.lnum = new_end_row;
+
+      // don't simply move cursor up, but to the end
+      // of new_end_row, if it's not at or after
+      // it already (in case virtualedit is active)
+      // column might be additionally adjusted below
+      // to keep it inside col range if needed
+      colnr_T len = (colnr_T)strlen(ml_get_buf(win->w_buffer, new_end_row));
+      if (win->w_cursor.col < len) {
+        win->w_cursor.col = len;
+      }
+    }
+
+    // if cursor is at the last row and
+    // it wasn't after eol before, move it exactly
+    // to end_row_change_end
+    if (win->w_cursor.lnum == new_end_row
+        && win->w_cursor.col > end_row_change_end && old_coladd == 0) {
+      win->w_cursor.col = end_row_change_end;
+
+      // make sure cursor is inside range, not after it,
+      // except when doing so would move it before new range
+      if (win->w_cursor.col - mode_col_adj >= end_row_change_start) {
+        win->w_cursor.col -= mode_col_adj;
+      }
+    }
+  }
+
+  check_cursor_col_win(win);
+  changed_cline_bef_curs(win);
+  invalidate_botline(win);
+}
+
 /// Initialise a string array either:
 /// - on the Lua stack (as a table) (if lstate is not NULL)
 /// - as an API array object (if lstate is NULL).
-- 
cgit 


From 2e92065686f62851318150a315591c30b8306a4b Mon Sep 17 00:00:00 2001
From: Gregory Anders <8965202+gpanders@users.noreply.github.com>
Date: Thu, 14 Sep 2023 08:23:01 -0500
Subject: docs: replace 
 with ``` (#25136)

---
 src/nvim/api/buffer.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

(limited to 'src/nvim/api/buffer.c')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index baac694848..e8f9f809f2 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -85,11 +85,15 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err)
 ///
 /// Example (Lua): capture buffer updates in a global `events` variable
 /// (use "vim.print(events)" to see its contents):
-/// 
lua
-///   events = {}
-///   vim.api.nvim_buf_attach(0, false, {
-///     on_lines=function(...) table.insert(events, {...}) end})
-/// 
+/// +/// ```lua +/// events = {} +/// vim.api.nvim_buf_attach(0, false, { +/// on_lines = function(...) +/// table.insert(events, {...}) +/// end, +/// }) +/// ``` /// /// @see |nvim_buf_detach()| /// @see |api-buffer-updates-lua| -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index e8f9f809f2..64dddea5b8 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -4,7 +4,6 @@ // Some of this code was adapted from 'if_py_both.h' from the original // vim source -#include #include #include #include @@ -14,6 +13,7 @@ #include "klib/kvec.h" #include "lua.h" #include "nvim/api/buffer.h" +#include "nvim/api/keysets.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/validate.h" -- cgit From 0da27e9bdec14acf82731c4d5e0ad7d673697af7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 29 Oct 2023 15:44:52 +0800 Subject: fix(api): load buffer first on nvim_buf_set_lines (#25823) Fix #22670 Fix #8659 --- src/nvim/api/buffer.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 64dddea5b8..86298efe08 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -359,6 +359,14 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ return; } + // loaded buffer first if it's not loaded + if (buf->b_ml.ml_mfp == NULL) { + if (!buf_ensure_loaded(buf)) { + api_set_error(err, kErrorTypeException, "Failed to load buffer"); + return; + } + } + bool oob = false; start = normalize_index(buf, start, true, &oob); end = normalize_index(buf, end, true, &oob); @@ -396,10 +404,6 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ goto end; } - if (!buf_ensure_loaded(buf)) { - goto end; - } - if (u_save_buf(buf, (linenr_T)(start - 1), (linenr_T)end) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to save undo information"); goto end; @@ -537,6 +541,14 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In return; } + // loaded buffer first if it's not loaded + if (buf->b_ml.ml_mfp == NULL) { + if (!buf_ensure_loaded(buf)) { + api_set_error(err, kErrorTypeException, "Failed to load buffer"); + return; + } + } + bool oob = false; // check range is ordered and everything! @@ -645,10 +657,6 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In goto end; } - if (!buf_ensure_loaded(buf)) { - 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_buf(buf, (linenr_T)start_row - 1, (linenr_T)end_row + 1) == FAIL) { -- cgit From 2dc9ceb99c018b15dcf0c443cad46efecccaf94e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 29 Oct 2023 09:02:32 +0100 Subject: docs: small fixes (#25585) Co-authored-by: tmummert Co-authored-by: parikshit adhikari --- src/nvim/api/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 86298efe08..2c80f96953 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -359,7 +359,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ return; } - // loaded buffer first if it's not loaded + // load buffer first if it's not loaded if (buf->b_ml.ml_mfp == NULL) { if (!buf_ensure_loaded(buf)) { api_set_error(err, kErrorTypeException, "Failed to load buffer"); @@ -541,7 +541,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In return; } - // loaded buffer first if it's not loaded + // load buffer first if it's not loaded if (buf->b_ml.ml_mfp == NULL) { if (!buf_ensure_loaded(buf)) { api_set_error(err, kErrorTypeException, "Failed to load buffer"); -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/api/buffer.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 2c80f96953..0444deff40 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1,6 +1,3 @@ -// 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 - // Some of this code was adapted from 'if_py_both.h' from the original // vim source -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/api/buffer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 0444deff40..5a9ddaae41 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -24,6 +24,7 @@ #include "nvim/drawscreen.h" #include "nvim/ex_cmds.h" #include "nvim/extmark.h" +#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/lua/executor.h" #include "nvim/mapping.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 5a9ddaae41..6bf0aeb4a7 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -33,7 +33,7 @@ #include "nvim/memory.h" #include "nvim/move.h" #include "nvim/ops.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/types.h" #include "nvim/undo.h" #include "nvim/vim.h" -- cgit From e3f735ef101d670555f44226614a5c3557053b1f Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:13:32 +0100 Subject: refactor: fix includes for api/autocmd.h --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 6bf0aeb4a7..ec667a8953 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -10,7 +10,7 @@ #include "klib/kvec.h" #include "lua.h" #include "nvim/api/buffer.h" -#include "nvim/api/keysets.h" +#include "nvim/api/keysets_defs.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/validate.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index ec667a8953..3f4ab2760d 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -34,7 +34,7 @@ #include "nvim/move.h" #include "nvim/ops.h" #include "nvim/pos_defs.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/undo.h" #include "nvim/vim.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/api/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 3f4ab2760d..96e0e240f2 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -14,7 +14,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/validate.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/buffer_defs.h" @@ -36,7 +36,7 @@ #include "nvim/pos_defs.h" #include "nvim/types_defs.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/buffer.c.generated.h" -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/api/buffer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 96e0e240f2..0df231868d 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -34,6 +34,7 @@ #include "nvim/move.h" #include "nvim/ops.h" #include "nvim/pos_defs.h" +#include "nvim/state_defs.h" #include "nvim/types_defs.h" #include "nvim/undo.h" #include "nvim/vim_defs.h" -- cgit