mrjones2014 / smart-splits.nvim

šŸ§  Smart, seamless, directional navigation and resizing of Neovim + terminal multiplexer splits. Supports tmux, Wezterm, and Kitty. Think about splits in terms of "up/down/left/right".

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature]: Custom `at_edge` behaviour (user-defined function)

IndianBoy42 opened this issue Ā· comments

Similar Issues

  • Before filing, I have searched for similar issues.

Description

I just had a (weird?) idea to open nvim-tree automatically when I try to move left from the leftmost window, similar for the other edges. It might be cool to allow the user to pass a function as the at_edge parameter and call it with some information like which edge we hit. The function should return wrap, split or any other future behaviour, or 'none'/nil for which smart-splits wouldn't do anything (but from inside at_edge I would call NvimTreeOpen and focus it)

commented

Hmm, that's a neat idea. Though I'm not sure how I feel about the API returning a string to indicate the at_edge behavior, as that opens a big can of worms of undefined behavior -- what if the function has done something weird to mess up internal state before returning the value?

Instead, I think we could pass some utilities into the function that you can use, but if you use a function, all bets are off, and you must define the edge behavior yourself.

What if we did an API like:

{
  at_edge = function(ctx)
    -- you can do any of these
    ctx.next_window() -- direction handled automatically
    ctx.split() -- direction handled automatically
    ctx.direction -- value of 'left'|'right'|'up'|'down'
    ctx.edge -- value of 'left'|'right'|'up'|'down'|nil (nil if not at an edge)
  end,
}

And then you can do whatever you want at the edge, without this plugin needing to worry about the tons of edge cases that will come up from people's tons of custom behavior.

That sounds perfectly usable too