zyedidia / micro

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

Feature Request: allow c++-style comments in your JSON files #2701

Open ElectricRCAircraftGuy opened 1 year ago

ElectricRCAircraftGuy commented 1 year ago

Description of the problem or steps to reproduce

Please allow comments in the micro settings.json file at ~/.config/micro/settings.json.

JSON doesn't allow for comments. JSON-cpp does. Many settings files using JSON support it, allowing C++-style // comments in JSON files, like this:

{
    // Language-specific settings; see:
    // https://github.com/zyedidia/micro/blob/master/runtime/help/options.md#global-and-local-settings
    "*.md": {
        "softwrap": false
    },
    "colorcolumn": 80,
    "scrollbar": true,
    "scrollspeed": 5
}

Note: to get github to allow the comments above, I set the syntax language to jsonc, like this (see here, and see my answer here):

```jsonc
{
    // Language-specific settings; see:
    // https://github.com/zyedidia/micro/blob/master/runtime/help/options.md#global-and-local-settings
    "*.md": {
        "softwrap": false
    },
    "colorcolumn": 80,
    "scrollbar": true,
    "scrollspeed": 5
}


The current behavior is that if I manually add comments to the config settings file, then open micro, the file gets rewritten and all comments are removed. I'd like the comments to remain.

## Specifications

<!-- You can use `micro -version` to get the commit hash. -->

Commit hash: 225927b
OS: Linux Ubuntu 22.04
Terminal: terminator 2.1.1
ElectricRCAircraftGuy commented 1 year ago

If I am able to add this feature as a PR, would you accept it?

PThorpe92 commented 1 year ago

So json5 supposedly supports comments but from what I've found, there are not many reliable libraries for go that allow for comments (especially block). jsonc

Good call on the jsonc, I found one for Go actually got it to work with all kinds of comments. Not exactly sure what this would mean for performance, especially over ssh. But I wouldn't mind implementing it if it would get accepted.

*Edit: I understand that some json5 libraries may support comments, and the issue is not parsing but that they are not overwritten each runtime. But from what I've seen, comments between lines, block comments, etc were problematic for these other json5 libraries and would often throw errors. This jsonc seems to work much better from what I can tell

JoeKar commented 2 months ago

Hm, from my perspective this was already added with #266, but micro does re-write the settings.json and bindings.json every time a setting is globally done within micro (via set) or by changing a key binding. See the explanation here.