changes for a better approach
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user