The removes the previous restriction that nvim_buf_set_extmark()
could not be used to highlight arbitrary multi-line regions
The problem can be summarized as follows: let's assume an extmark with a
hl_group is placed covering the region (5,0) to (50,0) Now, consider
what happens if nvim needs to redraw a window covering the lines 20-30.
It needs to be able to ask the marktree what extmarks cover this region,
even if they don't begin or end here.
Therefore the marktree needs to be augmented with the information covers
a point, not just what marks begin or end there. To do this, we augment
each node with a field "intersect" which is a set the ids of the
marks which overlap this node, but only if it is not part of the set of
any parent. This ensures the number of nodes that need to be explicitly
marked grows only logarithmically with the total number of explicitly
nodes (and thus the number of of overlapping marks).
Thus we can quickly iterate all marks which overlaps any query position
by looking up what leaf node contains that position. Then we only need
to consider all "start" marks within that leaf node, and the "intersect"
set of that node and all its parents.
Now, and the major source of complexity is that the tree restructuring
operations (to ensure that each node has T-1 <= size <= 2*T-1) also need
to update these sets. If a full inner node is split in two, one of the
new parents might start to completely overlap some ranges and its ids
will need to be moved from its children's sets to its own set.
Similarly, if two undersized nodes gets joined into one, it might no
longer completely overlap some ranges, and now the children which do
needs to have the have the ids in its set instead. And then there are
the pivots! Yes the pivot operations when a child gets moved from one
parent to another.
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.
The change in #248240081549 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.
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.
This aligns its behaviour better with `nvim_win_close`.
Note that `:hide` is actually incapable of closing the cmdwin, unlike `:close`
and `:quit`, so this is a bit of a difference in behaviour.
Disallow closing the previous window from `nvim_win_close`, as this will cause
issues.
Again, no telling how safe this is. It also requires exposing old_curwin. :/
Also note that it's possible for the `&cmdheight` to change if, for example,
there are 2 tabpages and `nvim_win_close` is used to close the last window in
the other tabpage while `&stal` is 1. This is addressed in a later commit.
Problem: As discussed on Matrix, there was some interest in having
`nvim_open_win` again be able to open floats in the cmdwin (e.g: displaying a
hover doc related to what's in the cmdwin). After #23228, this was disallowed.
Solution: Allow `nvim_open_win` in the cmdwin as long as `!enter` and
`buffer != curbuf` (the former can cause all sorts of issues, and the latter
can crash Nvim after closing cmdwin). Also allow `nvim_win_set_buf` in a similar
fashion.
Note that we're not *entirely* sure if this is 100% safe (cmdwin is a
global-state-using-main-loop-calling beast), but this seems to work OK..?
Also:
- Check the buffer argument of `nvim_open_win` earlier, and abort if it's
invalid (it used to still open a window in this case).
- Untranslate `e_cmdwin` errors in the API (other errors in the API are not
translated: although not detailed in the API contract yet, errors are
supposed to be stable).
Problem:
nvim_parse_cmd() in pcall() may show an error message (side-effect):
:lua pcall(vim.api.nvim_parse_cmd, vim.fn.getcmdline(), {})
E16: Invalid range
Solution:
Avoid emsg() in the nvim_parse_cmd() codepath.
- refactor(api): add error message output parameter to get_address()
- fix: null check emsg() parameter
- refactor: remove emsg_off workaround from do_incsearch_highlighting()
- refactor: remove emsg_off workaround from cmdpreview_may_show()
- refactor: remove remaining calls to emsg() from parse_cmd_address() and get_address()
- (refactor): lint set_cmd_dflall_range()
- refactor: addr_error() - move output parameter to return value
Fix#20339
TODO:
These are the functions called by `get_address()`:
```
nvim_parse_cmd() -> parse_cmdline() -> parse_cmd_address() -> get_address()
skipwhite()
addr_error()
qf_get_cur_idx()
qf_get_cur_valid_idx()
qf_get_size()
qf_get_valid_size()
mark_get()
mark_check()
assert()
skip_regexp()
magic_isset()
> do_search()
> searchit()
ascii_isdigit()
getdigits()
getdigits_int32()
compute_buffer_local_count()
hasFolding()
```
From these functions, I found at least two that call emsg directly:
- do_search()
- seems to be simple to refactor
- searchit()
- will be more challenging because it may generate multiple error messages,
which can't be handled by the current `errormsg` out-parameter.
For example, it makes multiple calls to `vim_regexec_multi()` in a loop that
possibly generate error messages, and later `searchit()` itself may generate
another one:
- c194acbfc4/src/nvim/search.c (L631-L647)
- c194acbfc4/src/nvim/search.c (L939-L954)
---------
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Problem:
`:lua vim.cmd.win_getid(30,10)` is interpreted as `:win[size] 30 10`.
User intention was to call `vim.fn.win_getid(30,10)`.
Solution:
Check that the `cmd` actually matches the resolved command.
Problem:
Nvim version string typically has a "build" component
but vim.version() doesn't report it.
Solution:
Add the "build" field to vim.version().
Closes#23863
The options 'path', 'include', and 'define' all use C-specific default
values. This may have made sense a long time ago when Vim was mostly
used just for writing C, but this is no longer the case, and we have
ample support for filetype specific configuration. Make the default
values of these options empty and move the C-specific values into a
filetype plugin where they belong.
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
`nvim_(get|set)_option_value` pick the current buffer / window by default for buffer-local/window-local (but not global-local) options. So specifying `buf = 0` or `win = 0` in opts is unnecessary for those options. This PR removes those to reduce code clutter.
Having the user set `v:lnum` before calling `nvim_eval_statusline()` is
unnecesarily fragile. Redraws inbetween setting `v:lnum` and the
`nvim_eval_statusline()` call will overwrite `v:lnum`.