From 89f831a3b0a8f569985364142a1ef2f745017c74 Mon Sep 17 00:00:00 2001 From: Abao Date: Wed, 9 Aug 2023 11:20:46 +0800 Subject: [PATCH 1/2] feat(tempfile): clean tempfile when winclosed --- lua/femaco/edit.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/femaco/edit.lua b/lua/femaco/edit.lua index c050b4f..d94573e 100644 --- a/lua/femaco/edit.lua +++ b/lua/femaco/edit.lua @@ -168,7 +168,8 @@ M.edit_code_block = function() })) local filetype = settings.ft_from_lang(match_data.lang) - vim.cmd('file ' .. settings.create_tmp_filepath(filetype)) + local tempfile = settings.create_tmp_filepath(filetype) + vim.cmd('file ' .. tempfile) vim.bo.filetype = filetype vim.api.nvim_buf_set_lines(vim.fn.bufnr(), 0, -1, true, match_lines) -- use nvim_exec to do this silently @@ -181,7 +182,7 @@ M.edit_code_block = function() buffer = 0, callback = function() local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, true) - + vim.loop.fs_unlink(tempfile) if tbl_equal(match_lines, lines) then return end if lines[#lines] ~= '' and settings.ensure_newline(base_filetype) then From 4c3c1982e5a0bae5e5915bfe9ac9688781bcbc8a Mon Sep 17 00:00:00 2001 From: Abao Date: Tue, 22 Aug 2023 19:49:10 +0800 Subject: [PATCH 2/2] docs(): add desc for create_tmp_filepath --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 564043f..ac2bd0a 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ require('femaco').setup({ post_open_float = function(winnr) vim.wo.signcolumn = 'no' end - -- create the path to a temporary file + -- create the path to a temporary file, which will clear automatically create_tmp_filepath = function(filetype) return os.tmpname() end,