2 Commits
Author SHA1 Message Date
DarthMooMancer 3046a3ce36 refactor: continuation of compressing languages to be agnostic 2026-10-26 21:11:55 -04:00
DarthMooMancer 5eaa7d10a7 refactor: realized I was heavily unoptimized.
Each language had the same boilerplate code to create new projects and
new files with minor differences between each language making them
difficult to edit and navigate.
2026-10-26 14:13:33 -04:00
18 changed files with 139 additions and 289 deletions
+24 -51
View File
@@ -1,71 +1,44 @@
local M = {} local M = {}
local utils = require("vern-nvim.utils") local utils = require("vern-nvim.utils")
local templates = require("vern-nvim.templates")
local action_utils = require("vern-nvim.actions.utils")
local join = vim.fs.joinpath
---@param opts VernCConfig
function M.create_project(opts)
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
pname = pname and vim.trim(pname)
if not pname or pname == "" then
return
end
local configs = require("vern-nvim.configs.c")
---@type VernCConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {})
local root = join(vim.fn.expand(cfg.workspace_root), cfg.c.root, pname)
local bin = action_utils.create(cfg.c, pname, root)
---@param root string
M.create_project = function(root)
local build_cmd = "cd " .. root .. " && cmake -S . -B build && cmake --build build" local build_cmd = "cd " .. root .. " && cmake -S . -B build && cmake --build build"
local _ = vim.system({ "sh", "-c", build_cmd }):wait() local _ = vim.system({ "sh", "-c", build_cmd }):wait()
utils.init_git(root, "c")
vim.cmd.edit(vim.fn.fnameescape(bin))
end)
end end
function M.create_file(opts) ---@param opts VernCConfig
M.create_file = function(opts)
opts = opts or {}
vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft) vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft)
ft = ft and vim.trim(ft) ft = ft and vim.trim(ft)
if not ft or ft == "" then if not ft or ft == "" then
return return
end end
local configs = require("vern-nvim.configs.c") local mod = {}
---@type VernCConfig if ft == "c" then
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {}) mod = opts.c.templates.file.source or {}
end
if ft == "h" then
mod = opts.c.templates.file.header or {}
end
vim.ui.input({ prompt = "Enter file name: " }, function(fname) vim.ui.input({ prompt = "Enter file name: " }, function(fname)
local root = join(vim.fn.expand(cfg.workspace_root), cfg.c.root, utils.proj_name()) fname = fname and vim.trim(fname)
local input_txt = fname if not fname or fname == "" then
ft = ft and vim.trim(ft)
if not ft or ft == "" then
return return
end end
local mod
if ft == "c" then local raw_path = vim.fs.joinpath(mod.path, mod.name)
mod = cfg.c.templates.file.source or {}
end
if ft == "h" then
mod = cfg.c.templates.file.header or {}
input_txt = fname:upper()
end
local raw_path = join(mod.path, mod.name)
local context = { project_name = utils.proj_name(), name = fname } local context = { project_name = utils.proj_name(), name = fname }
local path = utils.resolve_path(raw_path, cfg.c.dirs or {}, context) local path = utils.resolve_path(raw_path, opts.c.dirs or {}, context)
local abs_file_path = vim.fs.normalize(join(root, path)) local root = utils.proj_root()
if ft == "h" then utils.dump(
local abs_dir_path = vim.fs.dirname(abs_file_path) vim.fs.joinpath(root, path),
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then require("vern-nvim.templates").fetch(mod.kind_path, mod.kind, fname)
vim.fn.mkdir(abs_dir_path, "p") )
end vim.cmd.edit(vim.fn.expand(path))
end vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
utils.dump(abs_file_path, templates.fetch(mod.kind_path, mod.kind, input_txt))
vim.cmd.edit(vim.fn.expand(abs_file_path))
end) end)
end) end)
end end
+23 -51
View File
@@ -1,72 +1,44 @@
local M = {} local M = {}
local utils = require("vern-nvim.utils") local utils = require("vern-nvim.utils")
local templates = require("vern-nvim.templates")
local action_utils = require("vern-nvim.actions.utils")
local join = vim.fs.joinpath
---@param opts VernCPPConfig
function M.create_project(opts)
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
pname = pname and vim.trim(pname)
if not pname or pname == "" then
return
end
local configs = require("vern-nvim.configs.cpp")
---@type VernCPPConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {})
local root = join(vim.fn.expand(cfg.workspace_root), cfg.cpp.root, pname)
local bin = action_utils.create(cfg.cpp, pname, root)
---@param root string
M.create_project = function(root)
local build_cmd = "cd " .. root .. " && cmake -S . -B build && cmake --build build" local build_cmd = "cd " .. root .. " && cmake -S . -B build && cmake --build build"
local _ = vim.system({ "sh", "-c", build_cmd }):wait() local _ = vim.system({ "sh", "-c", build_cmd }):wait()
utils.init_git(root, "cpp")
vim.cmd.edit(vim.fn.fnameescape(bin))
end)
end end
---@param opts VernCPPConfig ---@param opts VernCPPConfig
function M.create_file(opts) M.create_file = function(opts)
opts = opts or {}
vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft) vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft)
ft = ft and vim.trim(ft) ft = ft and vim.trim(ft)
if not ft or ft == "" then if not ft or ft == "" then
return return
end end
local configs = require("vern-nvim.configs.cpp") local mod = {}
---@type VernCPPConfig if ft == "c" then
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {}) mod = opts.cpp.templates.file.source or {}
end
if ft == "h" then
mod = opts.cpp.templates.file.header or {}
end
vim.ui.input({ prompt = "Enter file name: " }, function(fname) vim.ui.input({ prompt = "Enter file name: " }, function(fname)
local root = join(vim.fn.expand(cfg.workspace_root), cfg.cpp.root, utils.proj_name()) fname = fname and vim.trim(fname)
local input_txt = fname if not fname or fname == "" then
ft = ft and vim.trim(ft)
if not ft or ft == "" then
return return
end end
local mod
if ft == "c" then local raw_path = vim.fs.joinpath(mod.path, mod.name)
mod = cfg.cpp.templates.file.source or {}
end
if ft == "h" then
mod = cfg.cpp.templates.file.header or {}
input_txt = fname:upper()
end
local raw_path = join(mod.path, mod.name)
local context = { project_name = utils.proj_name(), name = fname } local context = { project_name = utils.proj_name(), name = fname }
local path = utils.resolve_path(raw_path, cfg.cpp.dirs or {}, context) local path = utils.resolve_path(raw_path, opts.cpp.dirs or {}, context)
local abs_file_path = vim.fs.normalize(join(root, path)) local root = utils.proj_root()
if ft == "h" then utils.dump(
local abs_dir_path = vim.fs.dirname(abs_file_path) vim.fs.joinpath(root, path),
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then require("vern-nvim.templates").fetch(mod.kind_path, mod.kind, fname)
vim.fn.mkdir(abs_dir_path, "p") )
end vim.cmd.edit(vim.fn.expand(path))
end vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
utils.dump(abs_file_path, templates.fetch(mod.kind_path, mod.kind, input_txt))
vim.cmd.edit(vim.fn.expand(abs_file_path))
end) end)
end) end)
end end
+49 -14
View File
@@ -1,5 +1,9 @@
local M = {} local M = {}
local action_utils = require("vern-nvim.actions.utils")
local utils = require("vern-nvim.utils")
local templates = require("vern-nvim.templates")
M.create_project = function(opts) M.create_project = function(opts)
opts = opts or {} opts = opts or {}
vim.ui.input( vim.ui.input(
@@ -7,18 +11,34 @@ M.create_project = function(opts)
function(ft) function(ft)
ft = ft and vim.trim(ft) ft = ft and vim.trim(ft)
if not ft or vim.trim(ft) == "" then if not ft or vim.trim(ft) == "" then
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
title = "Vern Project",
})
return return
end end
local ok, actions = pcall(require, "vern-nvim.actions." .. ft) local ok, actions = pcall(require, "vern-nvim.actions." .. ft)
local configs = require("vern-nvim.configs." .. ft) local configs = require("vern-nvim.configs." .. ft)
local args = vim.tbl_deep_extend("force", {}, configs, opts or {}) local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
if ok and actions and type(actions.create_project) == "function" then vim.ui.input({ prompt = "Enter project name: " }, function(pname)
actions.create_project(args) pname = pname and vim.trim(pname)
else if not pname or pname == "" then
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, { return
title = "Vern Project",
})
end end
local root =
vim.fs.joinpath(vim.fn.expand(args.workspace_root), args[ft].root, pname)
local bin = action_utils.create(args[ft], pname, root)
utils.init_git(root, ft)
utils.init_readme(root)
if ok and actions and type(actions.create_project) == "function" then
actions.create_project(root)
end
vim.cmd.edit(vim.fn.fnameescape(bin))
vim.notify(
"Project: " .. pname .. " has been created!",
vim.log.levels.INFO,
{ title = "Vern Project" }
)
end)
end end
) )
end end
@@ -34,18 +54,33 @@ M.create_file = function(opts)
return return
end end
local ok, actions = pcall(require, "vern-nvim.actions." .. ft) local ok, actions = pcall(require, "vern-nvim.actions." .. ft)
local configs = require("vern-nvim.configs." .. ft) if not ok then
local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
if ok and actions and type(actions.create_file) == "function" then
actions.create_file(args)
else
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, { vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
title = "Vern File", title = "Vern File",
}) })
vim.notify("Error: " .. actions, vim.log.levels.ERROR, { return
title = "Vern File",
})
end end
local configs = require("vern-nvim.configs." .. ft)
local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
fname = fname and vim.trim(fname)
if not fname or fname == "" then
return
end
local mod
if ok and actions and type(actions.create_file) == "function" then
mod = actions.create_file(args[ft]) or args[ft].templates.file.source or {}
end
local raw_path = vim.fs.joinpath(mod.path, mod.name)
local context = { project_name = utils.proj_name(), name = fname }
local path = utils.resolve_path(raw_path, args[ft].dirs or {}, context)
local root = utils.proj_root()
utils.dump(vim.fs.joinpath(root, path), templates.fetch(mod.kind_path, mod.kind, fname))
vim.cmd.edit(vim.fn.expand(path))
vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
end)
end) end)
end end
+3 -47
View File
@@ -1,54 +1,10 @@
local M = {} local M = {}
local utils = require("vern-nvim.utils") local utils = require("vern-nvim.utils")
local templates = require("vern-nvim.templates")
local action_utils = require("vern-nvim.actions.utils")
local join = vim.fs.joinpath M.create_project = function() end
---@param opts VernLuaConfig M.create_file = function() end
function M.create_project(opts)
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
pname = pname and vim.trim(pname)
if not pname or pname == "" then
return
end
local configs = require("vern-nvim.configs.lua")
---@type VernLuaConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {})
local root = join(vim.fn.expand(cfg.workspace_root), cfg.lua.root, pname)
local bin = action_utils.create(cfg.lua, pname, root)
utils.init_git(root, "lua")
vim.cmd.edit(vim.fn.fnameescape(bin))
end)
end
---@param opts VernLuaConfig
function M.create_file(opts)
opts = opts or {}
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
fname = fname and vim.trim(fname)
if not fname or fname == "" then
return
end
local configs = require("vern-nvim.configs.lua")
---@type VernLuaConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
local mod = cfg.lua.templates.file.source or {}
local raw_path = join(mod.path, mod.name)
local context = { project_name = utils.proj_name(), name = fname }
local path = utils.resolve_path(raw_path, cfg.lua.dirs or {}, context)
utils.dump(path, templates.fetch(mod.kind_path, mod.kind, fname))
vim.notify("File: " .. fname .. " has been created!")
vim.cmd.edit(vim.fn.expand(path))
end)
end
---@param opts VernCPPConfig Takes a table for the runtime ---@param opts VernCPPConfig Takes a table for the runtime
function M.run(opts) function M.run(opts)
@@ -56,7 +12,7 @@ function M.run(opts)
local root = utils.proj_root() or "." local root = utils.proj_root() or "."
local pname = vim.fs.basename(root) local pname = vim.fs.basename(root)
local full_path = join(root, pname, "lua", pname) local full_path = vim.fs.joinpath(root, "lua", pname)
print(full_path .. "/init.lua") print(full_path .. "/init.lua")
utils.term({ "lua " .. full_path .. "/init.lua" }, opts.terminal or {}, false) utils.term({ "lua " .. full_path .. "/init.lua" }, opts.terminal or {}, false)
+6 -51
View File
@@ -1,58 +1,13 @@
local M = {} local M = {}
local utils = require("vern-nvim.utils") local utils = require("vern-nvim.utils")
local templates = require("vern-nvim.templates")
local action_utils = require("vern-nvim.actions.utils")
local join = vim.fs.joinpath ---@param root string
M.create_project = function(root)
---@param opts VernPythonConfig vim.fn.system("python3 -m venv " .. root .. "/venv")
function M.create_project(opts)
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
pname = pname and vim.trim(pname)
if not pname or pname == "" then
return
end
local configs = require("vern-nvim.configs.python")
---@type VernPythonConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
local root = join(vim.fn.expand(cfg.workspace_root), cfg.python.root, pname)
local bin = action_utils.create(cfg.python, pname, root)
utils.init_git(root, "python")
local venv_path = root .. "/venv"
vim.fn.system("python3 -m venv " .. venv_path)
vim.notify("Project: " .. pname .. " has been created!")
vim.cmd.edit(vim.fn.fnameescape(bin))
end)
end end
---@param opts VernPythonConfig M.create_file = function() end
function M.create_file(opts)
opts = opts or {}
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
fname = fname and vim.trim(fname)
if not fname or fname == "" then
return
end
local configs = require("vern-nvim.configs.python")
---@type VernPythonConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
local mod = cfg.python.templates.file.source or {}
local raw_path = join(mod.path, mod.name)
local context = { project_name = utils.proj_name(), name = fname }
local path = utils.resolve_path(raw_path, cfg.python.dirs or {}, context)
utils.dump(path, templates.fetch(mod.kind_path, mod.kind, fname))
vim.notify("File: " .. fname .. " has been created!")
vim.cmd.edit(vim.fn.expand(path))
end)
end
---@param opts VernPythonConfig Takes a table for the runtime ---@param opts VernPythonConfig Takes a table for the runtime
function M.run(opts) function M.run(opts)
@@ -61,9 +16,9 @@ function M.run(opts)
local pname = vim.fs.basename(root) local pname = vim.fs.basename(root)
local bin = opts.python.templates.project.primary local bin = opts.python.templates.project.primary
local exe = join(bin.path, bin.name) or "src/{project_name}/main.py" local exe = vim.fs.joinpath(bin.path, bin.name) or "src/{project_name}/main.py"
local exe_path = utils.resolve_path(exe, opts.python.dirs, { project_name = pname }) local exe_path = utils.resolve_path(exe, opts.python.dirs, { project_name = pname })
local full_path = join(vim.fn.expand(root), exe_path) local full_path = vim.fs.joinpath(vim.fn.expand(root), exe_path)
utils.term({ "python3 " .. full_path }, opts.terminal or {}, false) utils.term({ "python3 " .. full_path }, opts.terminal or {}, false)
end end
+3 -7
View File
@@ -1,4 +1,3 @@
local actions = require("vern-nvim.actions.c")
local config = require("vern-nvim.configs.c") local config = require("vern-nvim.configs.c")
---@param bufnr integer Buffer to activate on : defaults to 0 ---@param bufnr integer Buffer to activate on : defaults to 0
@@ -6,14 +5,11 @@ local config = require("vern-nvim.configs.c")
return function(bufnr, user_opts) return function(bufnr, user_opts)
---@type VernCConfig ---@type VernCConfig
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {}) local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
vim.api.nvim_buf_create_user_command(bufnr, "CRun", function()
if type(actions.run) == "function" then
actions.run(opts)
end
end, { desc = "Run c project" })
for key, def in pairs(opts.c.keybinds or {}) do for key, def in pairs(opts.c.keybinds or {}) do
if type(def.action) == "function" then 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() vim.keymap.set("n", key, function()
def.action(opts) def.action(opts)
end, { end, {
+3 -7
View File
@@ -1,4 +1,3 @@
local actions = require("vern-nvim.actions.cpp")
local config = require("vern-nvim.configs.cpp") local config = require("vern-nvim.configs.cpp")
---@param bufnr integer Buffer to activate on : defaults to 0 ---@param bufnr integer Buffer to activate on : defaults to 0
@@ -6,14 +5,11 @@ local config = require("vern-nvim.configs.cpp")
return function(bufnr, user_opts) return function(bufnr, user_opts)
---@type VernCPPConfig ---@type VernCPPConfig
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {}) local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
vim.api.nvim_buf_create_user_command(bufnr, "CPPRun", function()
if type(actions.run) == "function" then
actions.run(opts)
end
end, { desc = "Run cpp project" })
for key, def in pairs(opts.cpp.keybinds or {}) do for key, def in pairs(opts.cpp.keybinds or {}) do
if type(def.action) == "function" then 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() vim.keymap.set("n", key, function()
def.action(opts) def.action(opts)
end, { end, {
+3 -7
View File
@@ -1,4 +1,3 @@
local actions = require("vern-nvim.actions.lua")
local config = require("vern-nvim.configs.lua") local config = require("vern-nvim.configs.lua")
---@param bufnr integer Buffer to activate on : defaults to 0 ---@param bufnr integer Buffer to activate on : defaults to 0
@@ -6,14 +5,11 @@ local config = require("vern-nvim.configs.lua")
return function(bufnr, user_opts) return function(bufnr, user_opts)
---@type VernLuaConfig ---@type VernLuaConfig
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {}) local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
vim.api.nvim_buf_create_user_command(bufnr, "LuaRun", function()
if type(actions.run) == "function" then
actions.run(opts)
end
end, { desc = "Run lua project" })
for key, def in pairs(opts.lua.keybinds or {}) do for key, def in pairs(opts.lua.keybinds or {}) do
if type(def.action) == "function" then 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() vim.keymap.set("n", key, function()
def.action(opts) def.action(opts)
end, { end, {
+3 -13
View File
@@ -1,4 +1,3 @@
local actions = require("vern-nvim.actions.python")
local config = require("vern-nvim.configs.python") local config = require("vern-nvim.configs.python")
---@param bufnr integer Buffer to activate on : defaults to 0 ---@param bufnr integer Buffer to activate on : defaults to 0
@@ -6,20 +5,11 @@ local config = require("vern-nvim.configs.python")
return function(bufnr, user_opts) return function(bufnr, user_opts)
---@type VernPythonConfig ---@type VernPythonConfig
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {}) local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
vim.api.nvim_buf_create_user_command(bufnr, "Pythonrun", function()
if type(actions.run) == "function" then
actions.run(opts)
end
end, { desc = "Run python project" })
vim.api.nvim_buf_create_user_command(bufnr, "Pythonpip", function()
if actions.pip_install then
actions.pip_install()
end
end, { nargs = "*", desc = "Install python packages" })
for key, def in pairs(opts.python.keybinds or {}) do for key, def in pairs(opts.python.keybinds or {}) do
if type(def.action) == "function" then 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() vim.keymap.set("n", key, function()
def.action(opts) def.action(opts)
end, { end, {
+2
View File
@@ -9,10 +9,12 @@ M.c = {
}, },
keybinds = { keybinds = {
["<leader>pr"] = { ["<leader>pr"] = {
user_command = "CRun",
desc = "Executes c code", desc = "Executes c code",
action = require("vern-nvim.actions.c").run, action = require("vern-nvim.actions.c").run,
}, },
["<leader>pf"] = { ["<leader>pf"] = {
user_command = "CCreateFile",
desc = "Creates source/header files", desc = "Creates source/header files",
action = require("vern-nvim.actions.c").create_file, action = require("vern-nvim.actions.c").create_file,
}, },
+4 -2
View File
@@ -9,10 +9,12 @@ M.cpp = {
}, },
keybinds = { keybinds = {
["<leader>pr"] = { ["<leader>pr"] = {
user_command = "CPPRun",
desc = "Executes cpp code", desc = "Executes cpp code",
action = require("vern-nvim.actions.cpp").run, action = require("vern-nvim.actions.cpp").run,
}, },
["<leader>pf"] = { ["<leader>pf"] = {
user_command = "CPPCreateFile",
desc = "Creates source/header files", desc = "Creates source/header files",
action = require("vern-nvim.actions.cpp").create_file, action = require("vern-nvim.actions.cpp").create_file,
}, },
@@ -47,7 +49,7 @@ M.cpp = {
}, },
source = { source = {
path = "{dirs.src}", path = "{dirs.src}",
name = "{name}.c", name = "{name}.cpp",
kind = "source", kind = "source",
kind_path = "vern-nvim.templates.cpp", kind_path = "vern-nvim.templates.cpp",
}, },
@@ -57,7 +59,7 @@ M.cpp = {
path = ".", path = ".",
name = ".clang-tidy", name = ".clang-tidy",
kind = "linter", kind = "linter",
kind_path = "vern-nvim.templates.c", kind_path = "vern-nvim.templates.cpp",
enabled = false, enabled = false,
}, },
}, },
+2
View File
@@ -5,10 +5,12 @@ return {
workspace_root = "~/personal/Projects", workspace_root = "~/personal/Projects",
keybinds = { keybinds = {
["<leader>pc"] = { ["<leader>pc"] = {
user_command = "VernCreateProject",
desc = "Creates a new project", desc = "Creates a new project",
action = actions.create_project, action = actions.create_project,
}, },
["<leader>pf"] = { ["<leader>pf"] = {
user_command = "VernCreateFile",
desc = "Creates a new project file", desc = "Creates a new project file",
action = actions.create_file, action = actions.create_file,
}, },
+1
View File
@@ -8,6 +8,7 @@ M.lua = {
}, },
keybinds = { keybinds = {
["<leader>pr"] = { ["<leader>pr"] = {
user_command = "LuaRun",
desc = "Executes lua code", desc = "Executes lua code",
action = require("vern-nvim.actions.lua").run, action = require("vern-nvim.actions.lua").run,
}, },
+3 -1
View File
@@ -8,11 +8,13 @@ M.python = {
}, },
keybinds = { keybinds = {
["<leader>pr"] = { ["<leader>pr"] = {
user_command = "Pythonrun",
desc = "Executes python code", desc = "Executes python code",
action = require("vern-nvim.actions.python").run, action = require("vern-nvim.actions.python").run,
}, },
["<leader>pi"] = { ["<leader>pi"] = {
desc = "Asks for what python package to install", user_command = "Pythonpip",
desc = "Install python packages for environment",
action = require("vern-nvim.actions.python").pip_install, action = require("vern-nvim.actions.python").pip_install,
}, },
}, },
+3 -13
View File
@@ -1,7 +1,6 @@
local M = {} local M = {}
local configs = require("vern-nvim.configs") local configs = require("vern-nvim.configs")
local actions = require("vern-nvim.actions")
---@type VernCoreConfig ---@type VernCoreConfig
M.opts = vim.deepcopy(configs) M.opts = vim.deepcopy(configs)
@@ -18,6 +17,9 @@ function M.setup(user_opts)
for key, def in pairs(M.opts.keybinds or {}) do for key, def in pairs(M.opts.keybinds or {}) do
if type(def.action) == "function" then 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() vim.keymap.set("n", key, function()
def.action(M.opts) def.action(M.opts)
end, { end, {
@@ -27,18 +29,6 @@ function M.setup(user_opts)
end end
end end
vim.api.nvim_create_user_command("VernCreateProject", function()
if actions.create_project then
actions.create_project(M.opts)
end
end, { nargs = "*", desc = "Create a new project" })
vim.api.nvim_create_user_command("VernCreateFile", function()
if type(actions.create_file) == "function" then
actions.create_file(M.opts)
end
end, { nargs = "*", desc = "Creates a new file for project" })
local group = vim.api.nvim_create_augroup("VernAutocommands", { clear = true }) local group = vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
vim.api.nvim_create_autocmd("FileType", { vim.api.nvim_create_autocmd("FileType", {
group = group, group = group,
-20
View File
@@ -117,26 +117,6 @@ M.languages = {
end end
end, end,
}, },
lua = {
setup = function(self, user_opts)
local opts = vim.tbl_deep_extend("force", {}, configs.get("lua"), user_opts or {})
vim.api.nvim_create_user_command("LuaRun", function()
self:run()
end, {})
for key, _ in pairs(opts.keybinds) do
vim.keymap.set("n", key, ":LuaRun<CR>", { silent = true })
end
end,
run = function()
local init_lua_path = utils.get_project_root()
.. "/lua/"
.. utils.get_project_name()
.. "/init.lua"
if vim.fn.filereadable(init_lua_path) == 1 then
utils.terminal({ "lua " .. init_lua_path })
end
end,
},
} }
return M return M
@@ -0,0 +1 @@
return "# Hello from your fellow README.md"
+1
View File
@@ -3,6 +3,7 @@
---@alias SplitAnchorType "right" | "bottom" ---@alias SplitAnchorType "right" | "bottom"
---@class VernKeybindItem ---@class VernKeybindItem
---@field user_command string
---@field desc string ---@field desc string
---@field action function ---@field action function