From 94e8b411e0cf501f8e2b119ea92e5d08dfacb351 Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:29:30 -0400 Subject: [PATCH] Update c.lua --- lua/Polydev/c.lua | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/lua/Polydev/c.lua b/lua/Polydev/c.lua index 3194fb0..768ae85 100644 --- a/lua/Polydev/c.lua +++ b/lua/Polydev/c.lua @@ -136,24 +136,13 @@ end function M.create_new_file() vim.ui.input({ prompt = "Enter file name: " }, function(class_name) - if not class_name or class_name == "" then - return print("File creation canceled.") - end - - local root_dir = M.get_project_root() -- Use a function to reliably find the project root - if not root_dir then - return print("Error: Project root not found.") - end - + if not class_name or class_name == "" then return print("File creation canceled.") end + local root_dir = M.get_project_root() + if not root_dir then return print("Error: Project root not found.") end local file_path = root_dir .. "/src/" .. class_name .. ".c" - local file = io.open(file_path, "w") - if file then - file:close() - vim.cmd("edit " .. file_path) - print(class_name .. ".c created successfully!") - else - print("Error creating " .. class_name .. ".c") - end + assert(io.open(file_path, "w")):close() + vim.cmd("edit " .. file_path) + print(class_name .. ".c created successfully!") end) end