54 lines
1.6 KiB
Lua
54 lines
1.6 KiB
Lua
local M = {}
|
|
|
|
local configs = require("vern.configs")
|
|
local actions = require("vern.actions")
|
|
M.opts = {}
|
|
|
|
function M.setup(user_opts)
|
|
M.opts = vim.tbl_deep_extend("force", {}, configs, user_opts or {})
|
|
|
|
--- Bind global keybinds
|
|
for key, def in pairs(M.opts.keybinds or {}) do
|
|
if type(def.action) == "function" then
|
|
vim.keymap.set("n", key, function()
|
|
def.action(M.opts)
|
|
end, {
|
|
silent = true,
|
|
desc = def.desc,
|
|
})
|
|
end
|
|
end
|
|
|
|
--- Load project cmdline commands
|
|
vim.api.nvim_create_user_command("VernCreateProject", function(args)
|
|
if actions.create_project then
|
|
actions.create_project(M.opts, args)
|
|
end
|
|
end, { nargs = "*", desc = "Create a new project" })
|
|
|
|
vim.api.nvim_create_user_command("VernCreateFile", function(args)
|
|
if type(actions.create_file) == "function" then
|
|
actions.create_file(M.opts, args)
|
|
end
|
|
end, { nargs = "*", desc = "Creates a new file for project" })
|
|
|
|
--- Create group and attach based on ft
|
|
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
|
|
local ok, attach = pcall(require, "vern.attach." .. ft)
|
|
if ok and type(attach) == "function" then
|
|
attach(args.buf, M.opts)
|
|
end
|
|
end,
|
|
desc = "Attach languages to buffer",
|
|
})
|
|
end
|
|
|
|
return M
|