flatten.nvim icon indicating copy to clipboard operation
flatten.nvim copied to clipboard

Option to set `window.open` for each individual file being opened, not once globally

Open dk949 opened this issue 8 months ago • 4 comments

Is your feature request related to a problem? Please describe.

When using the terminal to open files normally, I like having them open in the alternate window, but for git commit, I would like to be able to do something like:

[open floating window]
vim.cmd.term("git commit")

Such that the editor opens in that floating window.

Describe the solution you'd like

Perhaps a global variable to make it possible to do something like GIT_EDITOR="nvim --cmd 'let g:flatten_window_open=\"current\"'"

Another option could be to let the pre_open hook return a new configuration (or subset of the configuration) which would be applied to just the current window being opened. This is a bit more complicated to work with, but it would solve this question for other config options too, not just window.open.

Describe alternatives you've considered

My current solution seems to work, but it's pretty ugly

-- config:
{
    hooks = {
        post_open = function ()
            require("flatten").config.window.open = "alternate"
        end
    },
}

-- git commit function:

require("flatten").config.window.open = "current"
[open floating window]
vim.cmd.term("git commit")

dk949 avatar May 26 '25 01:05 dk949

Yeah, I would definitely like to support this - I've had the need for it as well. I'm pretty busy with work right now but I'll try to get to this soon :)

willothy avatar May 30 '25 06:05 willothy

I've got a weekend spare if you accept PRs

I would personally be in favour of the second solution where pre_open returns the new config to be merged, but it technically could be a breaking change.

dk949 avatar May 30 '25 23:05 dk949

I'd love a PR! In this solution would pre_open return the config for each window? I might be misunderstanding. I think it should still be possible to set a global default, but having the ability to define custom handlers / determine what to do for individual files would be great too :)

willothy avatar May 31 '25 02:05 willothy

PR opened. The config returned by pre_open is merged with the global one only for the current file, so users can use guest_data to determine if/how config needs to be updated. returning nil just keeps the old config, so old behaviour is not changed.

dk949 avatar Jun 01 '25 14:06 dk949