zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
25.17k stars 1.18k forks source link

make comment action keybinding user-configurable #2194

Open marlonn opened 3 years ago

marlonn commented 3 years ago

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

ruvido commented 6 months ago

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

dmaluka commented 6 months ago

@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",
dev-nicolaos commented 4 months ago

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.

dmaluka commented 4 months ago

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 commented 4 months ago

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?

dev-nicolaos commented 4 months ago

I think JSON doesn't allow comments?

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

dmaluka commented 3 months ago

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.