Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
IndianBoy42 opened this issue Apr 17, 2023 · 2 comments · Fixed by #87
Closed
1 task done

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

IndianBoy42 opened this issue Apr 17, 2023 · 2 comments · Fixed by #87
Assignees
Labels
enhancement New feature or request

Comments

@IndianBoy42
Copy link

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)

@IndianBoy42 IndianBoy42 added the enhancement New feature or request label Apr 17, 2023
@mrjones2014
Copy link
Owner

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.

@IndianBoy42
Copy link
Author

That sounds perfectly usable too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants