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

Allowing plugin to add cursor in custom Loc #3441

Merged
merged 1 commit into from
Aug 31, 2024

Conversation

Neko-Box-Coder
Copy link
Contributor

@Neko-Box-Coder Neko-Box-Coder commented Aug 24, 2024

It is very difficult to add new cursor from a plugin standpoint since NewCursor() is not exposed.
While this can be worked around by manipulating the cursor after calling SpawnMultiCursorDown(), it is pretty much impossible to retain selections from previous cursors.

This PR allows the plugin to add new cursor without any limitations

@niten94
Copy link
Contributor

niten94 commented Aug 25, 2024

There is another pull request where NewCursor is exposed but it is not merged. I do not usually use multiple cursors so I do not know what resolution would be good, but there is a comment where other things that may be done are written: #2941 (comment)

@Neko-Box-Coder
Copy link
Contributor Author

Neko-Box-Coder commented Aug 25, 2024

@niten94
Yeah, I just noticed it, thanks.

@dmaluka

Still, what about my question #2920 (comment)?

I.e. isn't NewCursor() too low-level a detail to be exposed to plugins? Perhaps the needed functionality can be already achieved from Lua with existing BufPane methods like SpawnMultiCursor()?

SpawnMultiCursor() hardcodes multi cursor to be the selected word and there's no way to customize it. I don't see how it can be used by plugin to insert cursors in custom places (or other use cases). And other multi-cursor functions deselect existing selections.

Or if those methods are not quite suitable since they do "too much", perhaps we should just add a new simple method to BufPane or to Buffer, which would, roughly speaking, just do NewCursor() + AddCursor() + MergeCursors() and nothing else?

I personally think it doesn't hurt to expose a function that creates a Cursor struct, which can be used in many other places, other scenarios that we might not foresee. And the plugin developer can already look at how NewCursor() is used in the source code which is pretty clear on how it is "meant" to used I think.

That being said, I don't mind having a dedicated function just to allow plugins to add a cursor to the buffer if you want it.

@dmaluka
Copy link
Collaborator

dmaluka commented Aug 25, 2024

I personally think it doesn't hurt to expose a function that creates a Cursor struct, which can be used in many other places, other scenarios that we might not foresee. And the plugin developer can already look at how NewCursor() is used in the source code which is pretty clear on how it is "meant" to used I think.

So if later for some reason we want to change the way how it is done in the source code, we cannot just do that, since there are already plugins that already do the same, so we would need to update those plugins as well.

Things are already quite messy due to the fact that micro's plugin system doesn't clearly define which APIs are supposed to be used by plugins (and thus are expected to preserve backward compatibility, etc) and which are only supposed to be used internally by micro. So let's not make it even messier.

@Neko-Box-Coder
Copy link
Contributor Author

@dmaluka
Yeah fair enough, I get what you mean.
I added a function that adds a cursor to a buffer and reverted the previous changes.

@Neko-Box-Coder Neko-Box-Coder changed the title Exposing NewCursor to allow plugin to add multiple cursor in custom Loc Allowing plugin to add cursor in custom Loc Aug 25, 2024
@JoeKar JoeKar merged commit e6b20b2 into zyedidia:master Aug 31, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants