micro icon indicating copy to clipboard operation
micro copied to clipboard

make comment action keybinding user-configurable

Open marlonn opened this issue 4 years ago • 7 comments

Please allow users to rebind the shortcut for comments. When I try to edit the keybinding in bindings.json, the file rewrites itself to the default config.

It seems this is a regression compared to the comment plugin that is now built-in. Apologies if this was already fixed in 2.0.9 or 2.0.10, but I did not find anything referring to this in the release notes.

Specifications

micro version: 2.0.8 OS: Debian 11 Terminal: xfce4-terminal

marlonn avatar Aug 24 '21 19:08 marlonn

what is the default? I am unable to bind "comment" in the bindings.json. Can you share your file. please? thanks

ruvido avatar Apr 16 '24 17:04 ruvido

@marlonn Are you talking about the fact that if you remove any keybinding for Alt-/ in bindings.json, the comment plugin forcefully adds its default binding "Alt-/": "lua:comment.comment" to bindings.json again (and even if you have some other key, e.g. Ctrl-/, bound to "lua:comment.comment", the comment plugin still forcefully adds its default Alt-/ binding, in addition to your Ctrl-/ binding)?

That is an intended behavior (a not exactly intuitive one, yes). If you want to disable any keybinding for Alt-/, you can do it by binding Alt-/ to None.

    "Alt-/": "None",

dmaluka avatar Apr 18 '24 13:04 dmaluka

I'm ok with the plugin forcefully re-adding the default bindings if you can get the same functionality on a custom binding by simply using lua:comment.comment. But the fact that it strips away any comments I've written in the file is a such a pain.

dev-nicolaos avatar Jul 10 '24 23:07 dev-nicolaos

Yes, and this is not a problem of the comment plugin, this is an architectural problem of micro as a whole. I believe it was an unfortunate design decision to make the config files both human-writable and machine-writable (and even recommend both usages in the documentation, e.g. both the bind command and manual editing of bindings.json). And it seems it's too late to change that.

Well, I can think of some rather hacky solutions, for example change TryBindKey() behavior so that plugins' default keybindings are applied every time when micro starts (if they are not already overridden by non-default bindings in bindings.json), but never automatically written to bindings.json. Still, it wouldn't make the user fully sure that micro will not tamper with the user's manual changes in bindings.json or settings.json: if the user runs bind or set command, it will still overwrite those files, so the user would still need to be careful about that, which is not nice...

dmaluka avatar Jul 11 '24 08:07 dmaluka

But the fact that it strips away any comments I've written in the file is a such a pain.

I think JSON doesn't allow comments?

dmaluka avatar Jul 11 '24 08:07 dmaluka

I think JSON doesn't allow comments?

The config file is parsed as JSON5, which does allow for comments.

dev-nicolaos avatar Jul 11 '24 08:07 dev-nicolaos

Well, I can think of some rather hacky solutions, for example change TryBindKey() behavior so that plugins' default keybindings are applied every time when micro starts (if they are not already overridden by non-default bindings in bindings.json), but never automatically written to bindings.json.

Ok, maybe we should actually do that. I've prepared PR #3385.

dmaluka avatar Jul 14 '24 13:07 dmaluka