removed create new project from specific languages
This commit is contained in:
+4
-9
@@ -4,17 +4,15 @@ M.c_build = nil
|
|||||||
M.c_run = nil
|
M.c_run = nil
|
||||||
M.new_c_file = nil
|
M.new_c_file = nil
|
||||||
M.new_c_header_file = nil
|
M.new_c_header_file = nil
|
||||||
M.new_c_project = nil
|
|
||||||
|
|
||||||
M.config = {
|
M.config = {
|
||||||
project_root = "~/Projects/C",
|
project_root = "~/Projects/C",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<Esc>"] = "CloseTerminal",
|
["<Esc>"] = "CloseTerminal",
|
||||||
["<leader>cb"] = "CBuild",
|
["<leader>pb"] = "CBuild",
|
||||||
["<leader>cr"] = "CRun",
|
["<leader>pr"] = "CRun",
|
||||||
["<leader>cnf"] = "NewCFile",
|
["<leader>nf"] = "NewCFile",
|
||||||
["<leader>cnp"] = "NewCProject",
|
["<leader>nh"] = "NewCHeaderFile",
|
||||||
["<leader>cnh"] = "NewCHeaderFile",
|
|
||||||
},
|
},
|
||||||
terminal = {
|
terminal = {
|
||||||
right_padding = 0,
|
right_padding = 0,
|
||||||
@@ -35,11 +33,9 @@ function M.setup(opts)
|
|||||||
if command == "CBuild" then M.c_build = key end
|
if command == "CBuild" then M.c_build = key end
|
||||||
if command == "CRun" then M.c_run = key end
|
if command == "CRun" then M.c_run = key end
|
||||||
if command == "NewCFile" then M.new_c_file = key end
|
if command == "NewCFile" then M.new_c_file = key end
|
||||||
if command == "NewCProject" then M.new_c_project = key end
|
|
||||||
if command == "NewCHeaderFile" then M.new_c_header_file = key end
|
if command == "NewCHeaderFile" then M.new_c_header_file = key end
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("NewCProject", M.create_project, {})
|
|
||||||
vim.api.nvim_create_user_command("NewCHeaderFile", M.create_new_header_file, {})
|
vim.api.nvim_create_user_command("NewCHeaderFile", M.create_new_header_file, {})
|
||||||
vim.api.nvim_create_user_command("NewCFile", M.create_new_file, {})
|
vim.api.nvim_create_user_command("NewCFile", M.create_new_file, {})
|
||||||
vim.api.nvim_create_user_command("CBuild", M.build, {})
|
vim.api.nvim_create_user_command("CBuild", M.build, {})
|
||||||
@@ -48,7 +44,6 @@ function M.setup(opts)
|
|||||||
vim.keymap.set("n", M.c_build, ":CBuild<CR>", { silent = true })
|
vim.keymap.set("n", M.c_build, ":CBuild<CR>", { silent = true })
|
||||||
vim.keymap.set("n", M.c_run, ":CRun<CR>", { silent = true })
|
vim.keymap.set("n", M.c_run, ":CRun<CR>", { silent = true })
|
||||||
vim.keymap.set("n", M.new_c_file, ":NewCFile<CR>", { silent = true })
|
vim.keymap.set("n", M.new_c_file, ":NewCFile<CR>", { silent = true })
|
||||||
vim.keymap.set("n", M.new_c_project, ":NewCProject<CR>", { silent = true })
|
|
||||||
vim.keymap.set("n", M.new_c_header_file, ":NewCHeaderFile<CR>", { silent = true })
|
vim.keymap.set("n", M.new_c_header_file, ":NewCHeaderFile<CR>", { silent = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+16
-88
@@ -3,17 +3,14 @@ M.close_key = nil
|
|||||||
M.java_build = nil
|
M.java_build = nil
|
||||||
M.java_run = nil
|
M.java_run = nil
|
||||||
M.new_java_file = nil
|
M.new_java_file = nil
|
||||||
M.new_java_project = nil
|
|
||||||
|
|
||||||
-- Default config
|
|
||||||
M.config = {
|
M.config = {
|
||||||
project_root = "~/Projects/Java",
|
project_root = "~/Projects/Java",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<Esc>"] = "CloseTerminal",
|
["<Esc>"] = "CloseTerminal",
|
||||||
["<leader>jb"] = "JavaBuild",
|
["<leader>pb"] = "JavaBuild",
|
||||||
["<leader>jr"] = "JavaRun",
|
["<leader>pr"] = "JavaRun",
|
||||||
["<leader>jnf"] = "NewJavaFile",
|
["<leader>nf"] = "NewJavaFile",
|
||||||
["<leader>jnp"] = "NewJavaProject",
|
|
||||||
},
|
},
|
||||||
terminal = {
|
terminal = {
|
||||||
right_padding = 0,
|
right_padding = 0,
|
||||||
@@ -30,68 +27,31 @@ M.config = {
|
|||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
|
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
|
||||||
|
|
||||||
-- Apply keybindings manually
|
|
||||||
for key, command in pairs(M.config.keybinds) do
|
for key, command in pairs(M.config.keybinds) do
|
||||||
if command == "CloseTerminal" then
|
if command == "CloseTerminal" then M.close_key = key end
|
||||||
M.close_key = key
|
if command == "JavaBuild" then M.java_build = key end
|
||||||
end
|
if command == "JavaRun" then M.java_run = key end
|
||||||
if command == "JavaBuild" then
|
if command == "NewJavaFile" then M.new_java_file = key end
|
||||||
M.java_build = key
|
|
||||||
end
|
|
||||||
if command == "JavaRun" then
|
|
||||||
M.java_run = key
|
|
||||||
end
|
|
||||||
if command == "NewJavaFile" then
|
|
||||||
M.new_java_file = key
|
|
||||||
end
|
|
||||||
if command == "NewJavaProject" then
|
|
||||||
M.new_java_project = key
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register Keybinds
|
|
||||||
vim.keymap.set("n", M.java_build, ":JavaBuild<CR>", { silent = true })
|
vim.keymap.set("n", M.java_build, ":JavaBuild<CR>", { silent = true })
|
||||||
vim.keymap.set("n", M.java_run, ":JavaRun<CR>", { silent = true })
|
vim.keymap.set("n", M.java_run, ":JavaRun<CR>", { silent = true })
|
||||||
vim.keymap.set("n", M.new_java_file, ":NewJavaFile<CR>", { silent = true })
|
vim.keymap.set("n", M.new_java_file, ":NewJavaFile<CR>", { silent = true })
|
||||||
vim.keymap.set("n", M.new_java_project, ":NewJavaProject<CR>", { silent = true })
|
|
||||||
|
|
||||||
-- Register user commands
|
|
||||||
vim.api.nvim_create_user_command("NewJavaProject", M.create_project, {})
|
|
||||||
vim.api.nvim_create_user_command("NewJavaFile", M.create_new_file, {})
|
vim.api.nvim_create_user_command("NewJavaFile", M.create_new_file, {})
|
||||||
vim.api.nvim_create_user_command("JavaBuild", M.build, {})
|
vim.api.nvim_create_user_command("JavaBuild", M.build, {})
|
||||||
vim.api.nvim_create_user_command("JavaRun", M.run, {})
|
vim.api.nvim_create_user_command("JavaRun", M.run, {})
|
||||||
vim.api.nvim_create_user_command("Migrate", M.migrate, {})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Open floating terminal
|
|
||||||
function M.open_float_terminal(cmd)
|
function M.open_float_terminal(cmd)
|
||||||
local ui = vim.api.nvim_list_uis()[1]
|
local ui = vim.api.nvim_list_uis()[1]
|
||||||
local term_cfg = M.config.terminal
|
local term_cfg = M.config.terminal
|
||||||
|
|
||||||
-- Default window size (90% of the editor)
|
local width = math.max(1, math.floor(ui.width * 0.9) - term_cfg.left_padding - term_cfg.right_padding)
|
||||||
local default_width = math.floor(ui.width * 0.9)
|
local height = math.max(1, math.floor(ui.height * 0.9) - term_cfg.top_padding - (term_cfg.bottom_padding + 1))
|
||||||
local default_height = math.floor(ui.height * 0.9)
|
local row = math.max(1, math.floor((ui.height - height) / 2) + term_cfg.top_padding)
|
||||||
|
local col = math.max(1, math.floor((ui.width - width) / 2) + term_cfg.left_padding)
|
||||||
|
|
||||||
-- Default centered position
|
|
||||||
local default_row = math.floor((ui.height - default_height) / 2)
|
|
||||||
local default_col = math.floor((ui.width - default_width) / 2)
|
|
||||||
|
|
||||||
-- Adjust size based on padding
|
|
||||||
local width = default_width - term_cfg.left_padding - term_cfg.right_padding
|
|
||||||
local height = default_height - term_cfg.top_padding - (term_cfg.bottom_padding + 1)
|
|
||||||
|
|
||||||
-- Adjust position based on padding
|
|
||||||
local row = default_row + term_cfg.top_padding
|
|
||||||
local col = default_col + term_cfg.left_padding
|
|
||||||
|
|
||||||
-- Ensure window size doesn't go negative
|
|
||||||
width = math.max(1, width)
|
|
||||||
height = math.max(1, height)
|
|
||||||
-- Ensure position doesn't move off-screen
|
|
||||||
row = math.max(0, row)
|
|
||||||
col = math.max(0, col)
|
|
||||||
|
|
||||||
-- Create buffer and window
|
|
||||||
local buf = vim.api.nvim_create_buf(false, true)
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
local win = vim.api.nvim_open_win(buf, true, {
|
local win = vim.api.nvim_open_win(buf, true, {
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
@@ -103,56 +63,24 @@ function M.open_float_terminal(cmd)
|
|||||||
border = term_cfg.border and "rounded" or "none",
|
border = term_cfg.border and "rounded" or "none",
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Enable scrolling, relative line numbers, and prevent closing on click
|
|
||||||
vim.api.nvim_win_set_option(win, "winblend", vim.o.pumblend)
|
vim.api.nvim_win_set_option(win, "winblend", vim.o.pumblend)
|
||||||
vim.api.nvim_win_set_option(win, "winhighlight", "Normal:Pmenu,FloatBorder:Pmenu")
|
vim.api.nvim_win_set_option(win, "winhighlight", "Normal:Pmenu,FloatBorder:Pmenu")
|
||||||
if(M.config.terminal.number == true) then
|
vim.api.nvim_win_set_option(win, "cursorline", true)
|
||||||
|
if(term_cfg.number == true) then
|
||||||
vim.api.nvim_win_set_option(win, "number", true)
|
vim.api.nvim_win_set_option(win, "number", true)
|
||||||
end
|
if(term_cfg.relativenumber == true) then
|
||||||
if(M.config.terminal.number == true and M.config.terminal.relativenumber == true) then
|
|
||||||
vim.api.nvim_win_set_option(win, "relativenumber", true)
|
vim.api.nvim_win_set_option(win, "relativenumber", true)
|
||||||
end
|
end
|
||||||
if(M.config.terminal.scroll == true) then
|
end
|
||||||
|
if(term_cfg.scroll == true) then
|
||||||
vim.api.nvim_win_set_option(win, "scrolloff", 5)
|
vim.api.nvim_win_set_option(win, "scrolloff", 5)
|
||||||
end
|
end
|
||||||
vim.api.nvim_win_set_option(win, "cursorline", true)
|
|
||||||
|
|
||||||
vim.fn.termopen(cmd)
|
vim.fn.termopen(cmd)
|
||||||
|
|
||||||
vim.api.nvim_buf_set_keymap(buf, "n", M.close_key, "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
vim.api.nvim_buf_set_keymap(buf, "n", M.close_key, "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
||||||
return buf, win
|
return buf, win
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Migrate old folder to new method
|
|
||||||
function M.migrate()
|
|
||||||
vim.ui.input({ prompt = "Enter project name to migrate: "}, function(project_name)
|
|
||||||
if not project_name or project_name == "" then
|
|
||||||
print("Migration failed")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
|
|
||||||
local legacy_src_dir = project_root .. "/root/src"
|
|
||||||
local legacy_out_dir = project_root .. "/root/out"
|
|
||||||
local src_dir = project_root .. "/src"
|
|
||||||
local build_dir = project_root .. "/build"
|
|
||||||
|
|
||||||
vim.fn.mkdir(src_dir, "p")
|
|
||||||
vim.fn.mkdir(build_dir, "p")
|
|
||||||
|
|
||||||
local compile_command = "mv " .. legacy_src_dir .. "/* " .. src_dir ..
|
|
||||||
" && mv " .. legacy_out_dir .. "/* " .. build_dir ..
|
|
||||||
" && rm -rd " .. project_root .. "/" .. "root/"
|
|
||||||
local compile_status = vim.fn.system(compile_command)
|
|
||||||
|
|
||||||
if vim.v.shell_error ~= 0 then
|
|
||||||
print("Error during migration:\n" .. compile_status)
|
|
||||||
else
|
|
||||||
print("Migration successful!")
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Create a new Java project
|
|
||||||
function M.create_project()
|
function M.create_project()
|
||||||
-- Use vim.ui.input for better handling of input
|
-- Use vim.ui.input for better handling of input
|
||||||
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user