nvim: execute current buffer as lua script by :write and :luafile

This commit is contained in:
Fernando Schauenburg 2024-08-01 22:45:04 +02:00
parent 62dacd2c04
commit f0011b9eb1

View file

@ -40,12 +40,15 @@ M.execute_selection = function()
M.execute_lines(unpack(selection)) M.execute_lines(unpack(selection))
end end
---Execute lua script in a file.
---@param path string|nil Path to the file to execute. If nil, write and source
--- current buffer.
M.execute_file = function(path) M.execute_file = function(path)
if path then if not path then
vim.cmd.luafile(path) path = vim.fn.expand("%")
else vim.cmd.write()
M.execute_lines(1, vim.fn.line("$"))
end end
vim.cmd.luafile(path)
end end
---Edit a lua module. ---Edit a lua module.