diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-08-18 22:55:54 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-08-27 21:19:10 +0200 |
commit | 6d277f43a287d62c10fb1ed8d93247ddf4a437d9 (patch) | |
tree | 0e874c787ec25b86814d9902e04a31a516a09490 | |
parent | 7df566060c6ca4acbd7b42c1b40adf6058e49982 (diff) | |
download | rneovim-6d277f43a287d62c10fb1ed8d93247ddf4a437d9.tar.gz rneovim-6d277f43a287d62c10fb1ed8d93247ddf4a437d9.tar.bz2 rneovim-6d277f43a287d62c10fb1ed8d93247ddf4a437d9.zip |
TUI/paste: define paste function as Lua builtin
- Define in Lua so that it is compiled-in (available with `-u NONE`).
TODO: Eventually we will want a 'pastefunc' option or some other way to
override the default paste handler.
-rw-r--r-- | src/nvim/lua/vim.lua | 18 | ||||
-rw-r--r-- | src/nvim/tui/input.c | 5 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index 9854496415..922878d6ce 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -93,6 +93,23 @@ local function _os_proc_children(ppid) return children end +-- Default paste function. +local function _paste(data) + -- local eof = (data == {''}) + local curline = vim.api.nvim_call_function('line', {'.'}) + vim.api.nvim_buf_set_lines( + 0, + curline, + curline, + false, + data) + vim.api.nvim_call_function('cursor', {curline + #data, 1}) + -- if eof then + -- vim.api.nvim_command('redraw') + -- end + return 0 +end + -- TODO(ZyX-I): Create compatibility layer. --{{{1 package.path updater function -- Last inserted paths. Used to clear out items from package.[c]path when they @@ -186,6 +203,7 @@ local module = { _update_package_paths = _update_package_paths, _os_proc_children = _os_proc_children, _os_proc_info = _os_proc_info, + _paste = _paste, _system = _system, schedule_wrap = schedule_wrap, } diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 54332128f2..dc79a22862 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -132,8 +132,9 @@ static void tinput_wait_enqueue(void **argv) Object keys_array = ARRAY_OBJ(string_to_array(keys)); Array args = { .capacity = 1, .size = 1, .items = &keys_array }; Error err = ERROR_INIT; - Object fret = nvim_call_function(STATIC_CSTR_AS_STRING("PasteCallback"), - args, &err); + Object fret + = nvim_execute_lua(STATIC_CSTR_AS_STRING("return vim._paste(...)"), + args, &err); if ((fret.type == kObjectTypeInteger && fret.data.integer) || (fret.type == kObjectTypeBoolean && fret.data.boolean) || (fret.type == kObjectTypeString && fret.data.string.size)) { |