-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Change TryBindKey()
behavior to prevent plugins from needlessly rewriting bindings.json
#3385
base: master
Are you sure you want to change the base?
Conversation
Change the (documented) behavior of TryBindKey(): unless the overwrite argument is true, never write to bindings.json, even if the new binding has been successfully applied. TryBindKey() with overwrite=false is mainly used by plugins for adding their own default keybindings. It is not really necessary for them to write those default bindings to bindings.json: even if the binding is not saved in bindings.json, it will be still applied by the plugin calling TryBindKey() every time micro starts. This fixes undesirable behavior: unless there is already a binding for the given key in bindings.json, a plugin forcibly rewrites bindings.json, in particular removing any user's comments from it. With this change, bindings.json will be only rewritten by micro in the case when the user runs `bind` or `unbind` command, not automatically by plugins (unless there is a plugin calling TryBindKey() with overwrite=true, which is unlikely).
Return false if there is already a binding for the given key, different from the requested binding, and we haven't replaced it with the requested binding due to overwrite set to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one.
I normally put comments in my bindings.json
since I rebind a lot of the default keys.
It has always been a chore to find out which plugin is "overwriting" my bindings.json
. Especially when installing multiple plugins at once.
Tested the changes on my machine with both overwrite
as true
and false
. Works as expected.
Currently,
|
In the case of multiple plugins trying to bind the same key, this change would be a breaking change. |
I'm glad this exists. Opened #3391 because it took me a few tries to figure out how to use it. Finding out what a keybinding does (or which plugin is setting it) will require figuring out how to pass it to Could we write the plugin keybindings to somewhere like Alternatively (or do both!), make |
Not a breaking change I think? Right now, |
Yeah, I do agree Alternatively, maybe we can add a flag that shows the action for all binded keys, like
Yeah, this is worth considering I think. In the case of multiple plugins trying to bind the same unbinded key, the change we have right now can cause said key to behave differently each time, since whoever calls While having a dedicated json just for this is not elegant, it would avoid this problem I think. |
Having a dedicated json is just crazy, I think. We have enough crap already. I think the request #3391 is reasonable, we can try to implement an interactive version of Regarding non-deterministic behavior when multiple plugins set conflicting keybindings - yeah, good point, thanks for pointing it out. Thinking how to fix it, the only more or less clean solution I can think of is:
|
Yeah I can understand how you feel, that's why I said it is not "elegant" 😉
Sorry I am not quite following, what is the difference with the changes in this PR for If they are the same, doesn't the non-deterministic behavior behavior still exist? |
|
It returns a boolean and an error right? It can stay as it is if a keybinding already exists in
Sorry 😅 , I am still not following. Isn't this what I am not too sure about having a separate function ( |
So, it would not stay as it is, it would completely change the semantics of its return values, and in a very messy way. Imagine how the documentation for this new behavior would look like?
And as I said, it is not enough. I want a function that will register a default keybinding, not necessarily immediately enabling it (since it may be overridden by the user; that's a normal situation, not an error), but remembering this default keybinding. So that when the user, for example, runs the That would also allow to properly disable a plugin's keybinding when unloading a plugin e.g. in the |
Yeah okay, it makes much more sense now. Should we still merge this? |
I'm inclined to think we shouldn't. |
Change the (documented) behavior of
TryBindKey()
: unless theoverwrite
argument is true, never write tobindings.json
, even if the new binding has been successfully applied.TryBindKey()
with overwrite=false is mainly used by plugins for adding their own default keybindings. It is not really necessary for them to write those default bindings tobindings.json
: even if the binding is not saved inbindings.json
, it will be still applied by the plugin callingTryBindKey()
every time micro starts.This fixes undesirable behavior mentioned in #2194 (comment): unless there is already a binding for the given key in
bindings.json
, a plugin forcibly rewritesbindings.json
, in particular removing any user's comments from it. With this change,bindings.json
will be only rewritten by micro in the case when the user runsbind
orunbind
command, not automatically by plugins (unless there is a plugin callingTryBindKey()
with overwrite=true, which is unlikely).