diff --git a/lua/vern-nvim/attach/c.lua b/lua/vern-nvim/attach/c.lua deleted file mode 100644 index 1395634..0000000 --- a/lua/vern-nvim/attach/c.lua +++ /dev/null @@ -1,22 +0,0 @@ -local config = require("vern-nvim.configs.c") - ----@param bufnr integer Buffer to activate on : defaults to 0 ----@param user_opts? VernCConfig -return function(bufnr, user_opts) - ---@type VernCConfig - local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {}) - for key, def in pairs(opts.c.keybinds or {}) do - if type(def.action) == "function" then - vim.api.nvim_buf_create_user_command(bufnr, def.user_command, function() - def.action(opts) - end, { nargs = "*", desc = def.desc }) - vim.keymap.set("n", key, function() - def.action(opts) - end, { - buffer = bufnr, - silent = true, - desc = def.desc, - }) - end - end -end diff --git a/lua/vern-nvim/attach/cpp.lua b/lua/vern-nvim/attach/cpp.lua deleted file mode 100644 index fa69c78..0000000 --- a/lua/vern-nvim/attach/cpp.lua +++ /dev/null @@ -1,22 +0,0 @@ -local config = require("vern-nvim.configs.cpp") - ----@param bufnr integer Buffer to activate on : defaults to 0 ----@param user_opts? VernCPPConfig -return function(bufnr, user_opts) - ---@type VernCPPConfig - local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {}) - for key, def in pairs(opts.cpp.keybinds or {}) do - if type(def.action) == "function" then - vim.api.nvim_buf_create_user_command(bufnr, def.user_command, function() - def.action(opts) - end, { nargs = "*", desc = def.desc }) - vim.keymap.set("n", key, function() - def.action(opts) - end, { - buffer = bufnr, - silent = true, - desc = def.desc, - }) - end - end -end diff --git a/lua/vern-nvim/attach/lua.lua b/lua/vern-nvim/attach/lua.lua deleted file mode 100644 index 765fa11..0000000 --- a/lua/vern-nvim/attach/lua.lua +++ /dev/null @@ -1,22 +0,0 @@ -local config = require("vern-nvim.configs.lua") - ----@param bufnr integer Buffer to activate on : defaults to 0 ----@param user_opts? VernLuaConfig -return function(bufnr, user_opts) - ---@type VernLuaConfig - local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {}) - for key, def in pairs(opts.lua.keybinds or {}) do - if type(def.action) == "function" then - vim.api.nvim_buf_create_user_command(bufnr, def.user_command, function() - def.action(opts) - end, { nargs = "*", desc = def.desc }) - vim.keymap.set("n", key, function() - def.action(opts) - end, { - buffer = bufnr, - silent = true, - desc = def.desc, - }) - end - end -end diff --git a/lua/vern-nvim/attach/python.lua b/lua/vern-nvim/attach/python.lua deleted file mode 100644 index 994fc42..0000000 --- a/lua/vern-nvim/attach/python.lua +++ /dev/null @@ -1,37 +0,0 @@ -local config = require("vern-nvim.configs.python") - ----@param bufnr integer Buffer to activate on : defaults to 0 ----@param user_opts? VernPythonConfig -return function(bufnr, user_opts) - ---@type VernPythonConfig - local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {}) - for key, def in pairs(opts.python.keybinds or {}) do - if type(def.action) == "function" then - vim.api.nvim_buf_create_user_command(bufnr, def.user_command, function() - def.action(opts) - end, { nargs = "*", desc = def.desc }) - vim.keymap.set("n", key, function() - def.action(opts) - end, { - buffer = bufnr, - silent = true, - desc = def.desc, - }) - end - end - - local root = require("vern-nvim.utils").proj_root() - if not root then - return - end - local venv_dir = nil - if vim.uv.fs_stat(root .. "/venv/bin/python") then - venv_dir = root .. "/venv" - elseif vim.uv.fs_stat(root .. "/.venv/bin/python") then - venv_dir = root .. "/.venv" - end - if venv_dir then - vim.env.VIRTUAL_ENV = venv_dir - vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH - end -end diff --git a/lua/vern-nvim/configs/c.lua b/lua/vern-nvim/configs/c.lua index e53f226..039da33 100644 --- a/lua/vern-nvim/configs/c.lua +++ b/lua/vern-nvim/configs/c.lua @@ -1,5 +1,7 @@ local M = {} +M.attach = function() end + ---@type VernLanguageConfig M.c = { root = "C", diff --git a/lua/vern-nvim/configs/cpp.lua b/lua/vern-nvim/configs/cpp.lua index 77ad8a2..12325e3 100644 --- a/lua/vern-nvim/configs/cpp.lua +++ b/lua/vern-nvim/configs/cpp.lua @@ -1,5 +1,7 @@ local M = {} +M.attach = function() end + ---@type VernLanguageConfig M.cpp = { root = "CPP", diff --git a/lua/vern-nvim/configs/lua.lua b/lua/vern-nvim/configs/lua.lua index 85d8bf2..cb5f570 100644 --- a/lua/vern-nvim/configs/lua.lua +++ b/lua/vern-nvim/configs/lua.lua @@ -1,5 +1,7 @@ local M = {} +M.attach = function() end + ---@type VernLanguageConfig M.lua = { root = "Lua", diff --git a/lua/vern-nvim/configs/python.lua b/lua/vern-nvim/configs/python.lua index 9925258..61bb7e0 100644 --- a/lua/vern-nvim/configs/python.lua +++ b/lua/vern-nvim/configs/python.lua @@ -1,5 +1,22 @@ local M = {} +M.attach = function() + local root = require("vern-nvim.utils").proj_root() + if not root then + return + end + local venv_dir = nil + if vim.uv.fs_stat(root .. "/venv/bin/python") then + venv_dir = root .. "/venv" + elseif vim.uv.fs_stat(root .. "/.venv/bin/python") then + venv_dir = root .. "/.venv" + end + if venv_dir then + vim.env.VIRTUAL_ENV = venv_dir + vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH + end +end + ---@type VernLanguageConfig M.python = { root = "Python", diff --git a/lua/vern-nvim/init.lua b/lua/vern-nvim/init.lua index edf09e2..2603c71 100644 --- a/lua/vern-nvim/init.lua +++ b/lua/vern-nvim/init.lua @@ -35,9 +35,34 @@ function M.setup(user_opts) pattern = "*", callback = function(args) local ft = vim.bo[args.buf].filetype - local ok, attach = pcall(require, "vern-nvim.attach." .. ft) - if ok and type(attach) == "function" then - attach(args.buf, M.opts) + if not ft or ft == "" then + return + end + local has_config, mod = pcall(require, "vern-nvim.configs." .. ft) + if not has_config then + return + end + + local opts = vim.tbl_deep_extend("force", {}, mod, M.opts or {}) + if opts[ft] and opts[ft].keybinds 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 + local ok, attach_mod = pcall(require, "vern-nvim.configs." .. ft) + if ok and type(attach_mod.attach) == "function" then + attach_mod.attach(args.buf, opts) end end, desc = "Attach languages to buffer",