nvim_buf_set_text does not handle negative row numbers correctly: for
example,
nvim_buf_set_text(0, -2, 0, -1, 20, {"Hello", "world"})
should replace the 2nd to last line in the buffer with "Hello" and the
first 20 characters of the last line with "world". Instead, it reports
"start_row out of bounds". This happens because when negative line
numbers are used, they are incremented by one additional number to make
the non-negative line numbers end-exclusive. However, the line numbers
for nvim_buf_set_text should be end-inclusive.
In #15181 we handled this for nvim_buf_get_text by adding a new
parameter to `normalize_index`. We can solve the problem with
nvim_buf_set_text by simply availing ourselves of this new argument.
This is a breaking change, but makes the semantics of negative line
numbers much clearer and more obvious (as well as matching
nvim_buf_get_text).
BREAKING CHANGE: Existing usages of nvim_buf_set_text that use negative
line numbers will be off-by-one.
nvim_buf_get_text is the mirror of nvim_buf_set_text. It differs from
nvim_buf_get_lines in that it allows retrieving only portions of lines.
While this can typically be done easily enough by API clients,
implementing this function provides symmetry between the get/set
text/lines APIs, and also provides a nice convenience that saves API
clients the work of having to slice the result of nvim_buf_get_lines
themselves.
Adds the following API functions.
- nvim_buf_set_mark(buf, name, line, col)
* Set marks in a buffer.
- nvim_buf_del_mark(buf, name)
* Delete a mark that belongs to buffer.
- nvim_del_mark(name)
* Delete a global mark.
- nvim_get_mark(name)
* Get a global mark.
Tests:
- Adds test to all the new api functions, and adds more for the existing
nvim_buf_get_mark.
* Tests include failure cases.
Documentation:
- Adds documentation for all the new functions, and improves the
existing fucntion docs.
removing pending virtcol tests
Allow passing in empty array as a shorthand for array with empty string; add more documentation
add check for start_row as well
fix double free because intermediary lines weren't xmemdup'd.
NL-for-NUL dance.
Normalize row indices and perform more validation.
Adjust the cursor position if it's on the right side of the replacement.
Tests and documentation.
- Rename `meth_pcall`.
- Make `pcall_err` raise an error if the function does not fail.
- Add `vim.pesc()` to treat a string as literal where a Lua pattern is
expected.
bisected to f5d5da3917
Other test steps:
nvim -u NORC
:terminal tree / " Produces lots of output
:edit somefile.txt
:vsplit
:vsplit
<c-w>l
<c-w>l
<c-w>h
<c-w>p
msgpack_rpc_to_object (called by handle_request .. msgpack_rpc_to_array)
always NUL-terminates API Strings.
But handle_request .. msgpack_rpc_get_handler_for operates on a raw
msgpack_object, before preparation.
Also re-word some error messages:
- "Key does not exist: %s"
- "Invalid channel: %<PRIu64>"
- "Request array size must be 4 (request) or 3 (notification)"
- "String cannot contain newlines"
References #6150
Hope this will make people using feed_command less likely: this hides bugs.
Already found at least two:
1. msgpackparse() will show internal error: hash_add() in case of duplicate
keys, though it will still work correctly. Currently silenced.
2. ttimeoutlen was spelled incorrectly, resulting in option not being set when
expected. Test was still functioning somehow though. Currently fixed.
When the buffer that nvim_buf_set_lines() is changing is not in any vim
window, fix_cursor() leads to calling ml_get_buf() with an invalid line
number. The condition that fix_cursor() was called on was (buf ==
curbuf), but this is always true because of the call to
switch_to_win_for_buf() earlier in the function.
Instead this should be predicated on (save_curbuf.br_buf == NULL)
It is otherwise impossible to determine which test failed sanitizer/valgrind
check. test/functional/helpers.lua module return was changed so that tests which
do not provide after_each function to get new check will automatically fail.
-1 is index past the end, and -2 is the index of the last element.
This eliminates the need for include_start/include_end.
Allow the handling of out-of-bounds to be configurable.
Sanity API checks made by the python-client in the api-python travis target were
converted to lua and will now live in this repository. This will simplify
performing breaking changes to the API as it won't be necessary to send parallel
PRs the python-client.