changes for a better approach

This commit is contained in:
2024-12-12 18:57:35 +01:00
parent 7db810c04f
commit 78b0172772
7 changed files with 285 additions and 148 deletions

View File

@@ -1,29 +1,25 @@
-- lua/chatgpt_nvim/handler.lua
-- No major changes needed, just ensure it can be reused for the new command.
-- Ensuring we have get_clipboard_content and write_file as is.
local M = {}
-- Retrieves clipboard content and trims trailing whitespace/newlines
function M.get_clipboard_content()
local content = vim.fn.getreg('+')
content = content:gsub("%s+$", "")
return content
return vim.fn.getreg('+')
end
function M.write_file(filepath, content)
local dir = filepath:match("(.*/)")
if dir and dir ~= "" then
vim.fn.mkdir(dir, "p")
end
local f = io.open(filepath, "w")
if f then
f:write(content)
f:close()
else
vim.api.nvim_err_writeln("Failed to write file: " .. filepath)
local fd = vim.loop.fs_open(filepath, "w", 438)
if not fd then
vim.api.nvim_err_writeln("Could not open file: " .. filepath)
return
end
vim.loop.fs_write(fd, content, -1)
vim.loop.fs_close(fd)
end
function M.finish()
print("All files processed. You can now continue working.")
print("Finished processing files.")
end
return M