75 lines
2.5 KiB
Lua
75 lines
2.5 KiB
Lua
local M = {}
|
|
|
|
local settings = require("vern-nvim.settings")
|
|
|
|
---@type VernCoreConfig
|
|
M.opts = vim.deepcopy(settings)
|
|
|
|
---@class VernUserConfig
|
|
---@field workspace_root? string
|
|
---@field keybinds? table<string, VernKeybindItem>
|
|
---@field terminal? VernTerminalConfig | table
|
|
|
|
---@param user_opts? VernUserConfig
|
|
function M.setup(user_opts)
|
|
---@type VernCoreConfig
|
|
M.opts = vim.tbl_deep_extend("force", {}, settings, user_opts or {})
|
|
|
|
for key, def in pairs(M.opts.keybinds or {}) do
|
|
if type(def.action) == "function" then
|
|
vim.api.nvim_create_user_command(
|
|
def.user_command,
|
|
function() def.action(M.opts) end,
|
|
{ nargs = "*", desc = def.desc }
|
|
)
|
|
vim.keymap.set("n", key, function() def.action(M.opts) end, {
|
|
silent = true,
|
|
desc = def.desc,
|
|
})
|
|
end
|
|
end
|
|
|
|
local group =
|
|
vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
|
|
vim.api.nvim_create_autocmd("FileType", {
|
|
group = group,
|
|
pattern = "*",
|
|
callback = function(args)
|
|
local ft = vim.bo[args.buf].filetype
|
|
if not ft or ft == "" then return end
|
|
local ok, mod = pcall(require, "vern-nvim.langs." .. ft)
|
|
if not ok then return end
|
|
|
|
local opts = vim.tbl_deep_extend("force", {}, mod, M.opts or {})
|
|
if opts[ft] and opts[ft].keybinds ~= nil then
|
|
for key, def in pairs(opts[ft].keybinds or {}) do
|
|
if type(def.action) == "function" then
|
|
vim.api.nvim_buf_create_user_command(
|
|
args.buf,
|
|
def.user_command,
|
|
function() def.action(opts) end,
|
|
{ nargs = "*", desc = def.desc }
|
|
)
|
|
vim.keymap.set(
|
|
"n",
|
|
key,
|
|
function() def.action(opts) end,
|
|
{
|
|
buffer = args.buf,
|
|
silent = true,
|
|
desc = def.desc,
|
|
}
|
|
)
|
|
end
|
|
end
|
|
end
|
|
if ok and type(mod.attach) == "function" then
|
|
mod.attach(args.buf, opts)
|
|
end
|
|
end,
|
|
desc = "Attach languages to buffer",
|
|
})
|
|
end
|
|
|
|
return M
|