vim: add feedback for lua executor

This is useful when executing lines that produce no output, so I have
some confidence that something actually happened when pressing the key
bindings.

I am printing the message before executing the command because otherwise
this feedback would shadow the output of the command being executed
(which I am presumably interested in and would serve itself as
feedback).
This commit is contained in:
Fernando Schauenburg 2022-09-28 23:01:12 +02:00
parent 8cb0e94698
commit 38476f668c

View file

@ -3,13 +3,16 @@ vim.bo.tabstop = 2
local buffer = { buffer = true } local buffer = { buffer = true }
local exec_current_lua_line = function() local exec_current_lua_line = function()
vim.fn.luaeval(vim.fn.getline('.')) local lineno = vim.fn.line('.')
print('Executing line ' .. lineno)
vim.fn.luaeval(vim.fn.getline(lineno))
end end
local exec_current_lua_selection = function() local exec_current_lua_selection = function()
local selection = { vim.fn.line('v'), vim.fn.line('.') } local selection = { vim.fn.line('v'), vim.fn.line('.') }
local first, last = vim.fn.min(selection), vim.fn.max(selection) local first, last = vim.fn.min(selection), vim.fn.max(selection)
local code = vim.fn.join(vim.fn.getline(first, last), '\n') local code = vim.fn.join(vim.fn.getline(first, last), '\n')
print('Executing lines ' .. first .. ' to ' .. last)
loadstring(code)() loadstring(code)()
end end