Analogous to nodejs's `on('data', …)` interface, here on_key is the "add
listener" interface.
ref 3ccdbc570d#12536
BREAKING_CHANGE: vim.register_keystroke_callback() is now an error.
Resolve an issue with deferred clearing of highlight failing if the
buffer is deleted before the timeout by checking whether the
buffer is valid first.
* feat(api): add lua C bindings for xdiff
* chore: opt.hunk_lines -> opt.result_type
opt.on_hunk now takes precedence over opt.result_type
* chore: fix indents
Fix indents
* chore: change how priv is managed
Assign priv NULL and unconditionally apply XFREE_CLEAR to it when
finished.
v:lua expressions are represented using vvlua_partial. As v:lua isn't
intended to be called directly, it's given an empty pt_name.
Because of this, calling v:lua directly like "v:lua()" will cause "E117:
Unknown function: ", with an empty name.
Instead, have call_func() show the name "v:lua" in the emsg.
An empty table was previously always treated as a list, which means that
while merging tables, whenever an empty table was encountered it would
always truncate any table on the left.
`vim.tbl_deep_extend("force", { b = { a = 1 } }, { b = {} })`
Before: `{ b = {} }`
After: `{ b = { a = 1 } }`
Options formatted as a list of comma-separated key-value pairs may have
values that contain leading and trailing whitespace characters. For
example, the `listchars` option has a default value of
`"tab:> ,trail:-,nbsp:+"`. When converting this value to a lua table,
leading and trailing whitespace should not be trimmed.
Co-authored-by: Robert Hrusecky <robert.hrusecky@utexas.edu>
This closes#14677, but I also am a little unsure if there are times
where this may not be correct. However, this just changes the behavior
that even if `was_set` was false, we still get for
`nvim_win_get_option`.
New versions of neovim will not read undofiles written by nvim before this merge (there will be an error message about incopmatible version). Nvim 0.4 (or an master up to bda12927be ) can be used to recover older undofiles, so if you worried about unsaved changes lurking around in undofiles it would make sense to keep such version around somewhere to recover them.
This is a necessary change to keep tree-sitter and plugins dependent on byte-level buffer change events fully working with undo states from a undofile. If there is a clear demand we might implement reading of the old format. Such recovered buffers will not be be fully functional with plugins relying on buffer updates or tree-sitter, however.
Implement the LanguageTree structure to enable language injection.
This is done be removing the old Parser metatable and replacing by the
new structure, with the same API (almost).
Some noticeable differences :
- `parser:parse()` now returns a table of trees
- There is no incremental parsing for child (injected) languages
Co-authored-by: Thomas Vigouroux <tomvig38@gmail.com>
Also allow to get parser ranges.
This will be useful for language injection, allowing us to tweak the
parser's ranges on the fly.
Update runtime/lua/vim/treesitter.lua
Co-authored-by: Paul Burlumi <paul@burlumi.com>
Runtime queries just work like ftplugins, that is:
- Queries in the `after` directory are sourced _after_ the "base" query
- Otherwise, the last define query takes precedence.
Queries can be found in the `queries` directory.
Update runtime/lua/vim/treesitter/query.lua
Co-authored-by: Paul Burlumi <paul@burlumi.com>
- The previous commit lost information in the tests. Instead, add some
more "normalization" substitutions in pcall_err(), so that the general
shape of the stacktrace is included in the asserted text.
- Eliminate contains(), it is redundant with matches()
On empty buffers, when editing the first line, the line is buffered, causing offset to be < 0. While the buffer is not actually empty, the buffered line has not been flushed (and should not be) yet, so the call is valid but an edge case.
This caused segfaults when calling win_findbuf in an `on_detach`
callback, when the callback was triggered when closing the last window
containing the buffer.
Can be reproduced with a script like this:
-- in some lua file
vim.fn.timer_start(10, function() error("uh....") end)
-- will cause neovim to crash with the following error.
PANIC: unprotected error in call to Lua API
(nlua_CFunction_func_call failed.)
After this, it will instead print the error message
from the top of the stack, like so.
tmp/error_nvim.lua:10: uh...
Also added an example test. Previously this test
caused the embedded nvim to panic.
vim-patch:8.2.1054: not so easy to pass a lua function to Vim
vim-patch:8.2.1084: Lua: registering function has useless code
I think I have also opened up the possibility for people to use these
callbacks elsewhere, since I've added a new struct that we should be
able to use.
Also, this should allow us to determine what the state of a list is in
Lua or a dictionary in Lua, since we now can track the luaref as we go.
* Change uri_to_fname to not convert non-file URIs
A URI with a scheme other than file doesn't have a local file path.
* fixup! Change uri_to_fname to not convert non-file URIs
* fixup! fixup! Change uri_to_fname to not convert non-file URIs
* add lua function to highlight yanked region
* extract namespace, better naming, default values
* add default for event argument
* free timer
* factor out mark to position calculation
* d'oh
* make sure timer stops before callback (cf. luv example)
* factor out timer, more documentation
* fixup
* validate function argument for schedule
* fix block selection past eol
* correct handling of multibyte characters
* move arguments around, some cleanup
* move utility functions to vim.lua
* use anonymous namespaces, avoid local api
* rename function
* add test for schedule_fn
* fix indent
* turn hl-yank into proper (hightlight) module
* factor out position-to-region function
mark extraction now part of highlight.on_yank
* rename schedule_fn to defer_fn
* add test for vim.region
* todo: handle double-width characters
* remove debug printout
* do not shadow arguments
* defer also callable table
* whitespace change
* move highlight to vim/highlight.lua
* add documentation
* add @return documentation
* test: add check before vim.defer fires
* doc: fixup