Skip to content

Can FeMaco add a mechanism for clean temp file #29

Description

@AbaoFromCUG

Thanks for this plugin.

I have a slight issue with Femaco, when I use FeMaco to edit inline code block in a floating window, the formatter tool don't be affected by config (e.g., .stylua.tomal for stylua). I realized that FeMaco create temp file use os.tmpname() default, which return /temp/lua_xxxx, it is out of source folder.

So I add customize post_open_float and create_tmp_filepath for the purpose of creating tempfile in source folder

local function femaco()
    local cache_filename
    require("femaco").setup({
        post_open_float = function(winnr)
            print(string.format("post_open_float: %s", winnr))
            vim.api.nvim_create_autocmd("WinClosed", {
                pattern = "*",
                callback = function()
                    local closed_win = vim.fn.expand("<amatch>")
                    if tonumber(closed_win)== winnr then
                        print(string.format("remove temp file %s", cache_filename))
                        vim.loop.fs_unlink(cache_filename)
                    end
                end,
            })
        end,
        create_tmp_filepath = function(filetype)
            cache_filename = string.format("%s/.femaco_%d_%s", vim.fn.getcwd(), math.random(100, 999), filetype)
            return cache_filename
        end,
    })
end

everything works perfect until I open multiple FeMaco floating windows to edit different code blocks. the cache_filename will be override, so some tempfile will not be clean right.

could FeMaco add ability to cleanup temp file?

Refer to null-ls.nvim, which need tempfile to format file sameily

https://github.com/jose-elias-alvarez/null-ls.nvim/blob/db09b6c691def0038c456551e4e2772186449f35/lua/null-ls/helpers/generator_factory.lua#L300-L311

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions