HOCON config txt editor


#1

With sponge going with HOCON for its config I decided to try it out my self to get use to it. I like it alot over json or ymal however there is one thing I am wondering about.

What txt editor is good to edit its syntax. Notepad ++ supported .yml in a way that it provided buttons on the side that allowed you to collapse blocks of config to hide away what you don't need to see at the time. However .json and the file extension .conf HOCON shows to use in examples doesn't appear to have the same utility in notepad++. Visual studio has utility for .json but shows warnings whenever I use the less strict syntax of HOCON using the .json extension, and none when I use the .conf extension.

Is there a text editor that provides utility for HOCON?


#2

For json I use http://sourceforge.net/projects/nppjsonviewer/
for HOCON IDK, never seen it before.
but for editing configs on server I must use VI over SSH, no choice.


#3

Let's spam the Notepad++ devs about HOCON


#4

There you go, I looked it up and no one has even written the rules out as a language format for it, so someone here could do that. Under languages press "Define your language" then copy the language definition file and post it here.


#5

To clarify what @tebbenjo means, Notepad++ comes with built-in 'definitions' which can tell N++ that something is part of a language's syntax. N++ then allows you to color those terms and syntax details.

As I believe that HOCON was create for Forge, it's not too surprising it doesn't have a definition yet. You can define your own language by going to the Language menu in the N++ toolbar and clicking the next to last option "Define your language...", if anyone is interested in doing so. Some info about HOCON (Not sure how reliable it is, but it looks like a good document)

The HOCON language is derived from JSON, so I've read, so maybe starting by importing the JSON definitions would be a good start. N++ may also provide some partial coloring or recognition for HOCON if you set the language to JSON (also done via the Language menu)


#6

What?!
Don't tell me what to do! I'm lazy.


#7

HOCON was not created for Forge. It was created by (or is at least maintained by) the company that created the Scala programming language.


#8

Ah, thanks for clarifying that. I thought I read elsewhere on the forums it was designed for Forge. Guess it could've said something along the lines of Forge using it's own config file type and nothing about HOCON, but I've no idea anymore.


#9

HOCON is a subset of JSON so for syntax highlighting the JSON support should be sufficient in most cases. I cannot speak for Notepad++, but most of the well known texteditors such as GitHub's Atom, SublimeText and Textmate support JSON natively. Additionally all of this editors can be easily extended with custom packages so writing a dedicated HOCON support - if that is really needed - is quit simple.

As for terminal editors, for nano users this repository provides a starting point.


#10

The documentation I linked a few posts up specifically note that HOCON isn't a subset of JSON, but is only derived from it (I'm not sure how that particularly works or why, just something I noticed), and I would think N++ has JSON support at least. Since the language definitions are generally just lists of keywords or regex patterns (I think), I was thinking it'd also highlight some stuff decently if set to JSON.


#11

Right, my bad. JSON is a subset of HOCON, not the other way around (all JSON is valid HOCON but not all HOCON is valid JSON). That means that also my initial assumption was wrong and a dedicated parser is need. Luckily this can be done quit easily for the editors I mentioned.


#12

If you select Javascript from the Languages menu (in N++) it pretty much works as expected, the only thing it doesn't do is '#' comments.


#13

Ah your right, that works out nicely. Still would be nice for a dedicated one for HOCON due to javascript keywords highlighting and the lack of HOCON keywords such as its "include" keyword, but it works


#14

So copy the definition for Javascript and add the # to the comment field and save it as HOCON.

These could be added too.


#15

Kind of off topic to my original post but I think it would be silly to make a new topic for this question.

I can't seem to find any way to write a HOCON Config object to a file in the typesafe api http://typesafehub.github.io/config/latest/api/.

Am I missing it or is is their api just a config read only thing with sponge implementing the ability to write to file?


#16

You are able to write the ConfigObject back to a file using
config.root().render().


#17

I noticed that and considered it a possible option, but it states in its documentation that't the render() methods intended purpose is for debugging.

It also spams every value with comments such as "# test.conf: 1-17"

Attempts at using render options did not remove them. It does not feel like a viable option for writing to file.


#18

So for an editor I have a 2 options (that I know of):

Option 1: Go for paid but shareware program: Sublime Text 2 (version 3 coming soon) is a very VERY good editor. Fact is its not Open Source but the shareware version is totally usable (just says you can pay when you save a file from time to time). The fact is there is a module for HOCON and if it is not good we can definitely build one.

Option 2: Go for the Open Source alternative: Atom is amazing! The fact is its 100% hackable but I have not found a plugin/module for HOCON so I would be glad to make one for the community. wink

(I personally dislike Notepad++ do_not_litter)


#19

I gota say Atom looks nice


#20

Just try a VSCode extension written by myself? https://forums.spongepowered.org/t/hocon-colorizer-a-vscode-extension-for-hocon/23618