Option --dump-config-json
lassik opened this issue ยท 3 comments
I thought about what would be needed to implement full Unibeautify support in Emacs, and this kind of option would be needed in the cli program:
unibeautify --language c --dump-config-json source-file.c
The process exit status would be as follows:
- Exit code 0 - settings found and successfully printed to stdout
- Exit code 1 - no settings found
- Exit code 2 and bigger - some other error encountered
This would serve two purposes:
- To configure the indentation and other settings of Emacs (or another editor) to match the beautifier settings in the
.unibeautifyrc
file. - To signal that there is in fact a corresponding
.unibeautifyrc
and hence that Unibeautify should be called automatically on save. (There could be another, faster option only for this purpose that doesn't parse or dump anything, but only uses exit code 0/1/2 as above to tell whether.unibeautifyrc
exists.)
The config dump should only have the beautifier options pertinent to the file given, so that the editor plugin will have an easy job translating them to the editor's native options ๐ The source file is not necessarily in the current directory, it could be anywhere (and the pathname can be an absolute or relative).
The config dump could be in any format, but I guess JSON is a natural choice. And matches the existing --config-json
option.
It would also be awesome if unibeautify
validated the config before dumping it so that the editor plugins don't need to do their own validation (which would amount to a non-trivial amount of duplicate code across editors).
I guess invalid options should have their own exit code. Maybe any valid options should be dumped even if there were some invalid ones, so that the editor can at least use some of them, instead of getting a completely different coding style from its own default settings.
which would amount to a non-trivial amount of duplicate code across editors
Absolutely. Anything we can do to reduce duplicate code ๐.
I've been developing out helper functions in various projects which use Unibeautify. Once I see something happen often enough we migrate the functions into Unibeautify core and de-duplicate it across the other projects.
Great to hear, sounds like exactly the right approach ๐