1
Fork 0
satellite/home/features/neovim/config/ftplugin/lua.lua

45 lines
942 B
Lua
Raw Permalink Normal View History

2023-01-10 02:38:06 +01:00
local opts = function(desc)
return { desc = desc, buffer = true }
end
local function runLocal(functionName)
return function()
local path = vim.api.nvim_buf_get_name(0)
local status, M = pcall(dofile, path)
2023-01-10 02:38:06 +01:00
if status then
if M ~= nil then
if type(M[functionName]) == "function" then
M[functionName]()
print("M." .. functionName .. "() executed succesfully!")
else
print("Module does not return a " .. functionName .. " function")
end
2023-01-10 02:38:06 +01:00
else
print("Module returned nil")
2023-01-10 02:38:06 +01:00
end
else
print("Cannot import current file :(")
2023-01-10 02:38:06 +01:00
end
end
end
2023-01-10 02:38:06 +01:00
2024-02-26 12:56:54 +01:00
vim.keymap.set(
"n",
"<leader>lf",
"<cmd>source %<cr>",
opts("Run [l]ua [f]ile ")
)
vim.keymap.set(
"n",
"<leader>ls",
runLocal("setup"),
opts("Run .[s]etup() in current file")
)
vim.keymap.set(
"n",
"<leader>lc",
runLocal("config"),
opts("Run .[c]onfig() in current file")
)