Update c.lua
This commit is contained in:
+20
-21
@@ -4,9 +4,6 @@ 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_project = nil
|
M.new_c_project = nil
|
||||||
M.build_term_buf = nil
|
|
||||||
M.build_term_win = nil -- Store the window reference for the build terminal
|
|
||||||
|
|
||||||
|
|
||||||
-- Default config
|
-- Default config
|
||||||
M.config = {
|
M.config = {
|
||||||
@@ -122,8 +119,6 @@ function M.open_float_terminal(cmd)
|
|||||||
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 })
|
||||||
M.build_term_buf = buf
|
|
||||||
M.build_term_win = win
|
|
||||||
return buf, win
|
return buf, win
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -238,14 +233,6 @@ public class %s {
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.build()
|
function M.build()
|
||||||
-- Close the build terminal if it's open before running the build
|
|
||||||
if M.build_term_buf and vim.api.nvim_buf_is_valid(M.build_term_buf) then
|
|
||||||
vim.api.nvim_buf_delete(M.build_term_buf, { force = true })
|
|
||||||
vim.api.nvim_win_close(M.build_term_win, true)
|
|
||||||
M.build_term_buf = nil
|
|
||||||
M.build_term_win = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Get the current file's directory
|
-- Get the current file's directory
|
||||||
local current_dir = vim.fn.expand("%:p:h")
|
local current_dir = vim.fn.expand("%:p:h")
|
||||||
-- Try to find the root of the project by matching the path
|
-- Try to find the root of the project by matching the path
|
||||||
@@ -295,15 +282,27 @@ function M.build()
|
|||||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.run()
|
-- function M.build()
|
||||||
-- Close the build terminal if it's open before running the program
|
-- vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
||||||
if M.build_term_buf and vim.api.nvim_buf_is_valid(M.build_term_buf) then
|
-- local build_project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name .. "/build"
|
||||||
vim.api.nvim_buf_delete(M.build_term_buf, { force = true })
|
-- local compile_command = "cd " .. build_project_root .. " && cmake .. && make"
|
||||||
vim.api.nvim_win_close(M.build_term_win, true)
|
-- local term_buf = M.open_float_terminal(compile_command)
|
||||||
M.build_term_buf = nil
|
-- vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||||
M.build_term_win = nil
|
-- local compile_status = vim.fn.system(compile_command)
|
||||||
end
|
--
|
||||||
|
-- if vim.v.shell_error ~= 0 then
|
||||||
|
-- vim.api.nvim_buf_set_lines(term_buf, 0, -1, false, {"Error during compilation:"})
|
||||||
|
-- vim.api.nvim_buf_set_lines(term_buf, 1, -1, false, vim.split(compile_status, "\n"))
|
||||||
|
-- else
|
||||||
|
-- vim.api.nvim_buf_set_lines(term_buf, 0, -1, false, {"Compilation successful!"})
|
||||||
|
-- end
|
||||||
|
--
|
||||||
|
-- vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
|
||||||
|
-- end)
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- Run Java program in floating terminal
|
||||||
|
function M.run()
|
||||||
local current_dir = vim.fn.expand("%:p:h")
|
local current_dir = vim.fn.expand("%:p:h")
|
||||||
local project_root = current_dir:match("(.*)/src")
|
local project_root = current_dir:match("(.*)/src")
|
||||||
if not project_root then
|
if not project_root then
|
||||||
|
|||||||
Reference in New Issue
Block a user