Closed chrisdone closed 2 years ago
Well, first of all this would effectively introduce a configuration option, which doesn't go well with Ormolu's philosophy. If we imagine that it would be implemented in fourmolu or some other independent fork, then I'd say I'd have go all over the code and do countless manual adjustments (hard and error-prone).
Now that I think about it, perhaps instead I could make a tool that parses with ormolu/ghc-lib-parser, does some AST transformations via syb/generics, and then prints with ormolu. Assuming ormolu never adds or removes optional delimiters or groupings.
Thanks!
I’m wondering, how hard would it be to add a pass in ormolu to do two modes:
Insert explicit parents, braces, semi colons, etc. in various places.
Remove all unnecessary parens, braces, semi colons, etc.
My idea is that for projects already using ormolu, it would be a neat editing mode in various editors to reformat the source of e.g. the current declaration in mode (1), which is very easy to manipulate with editor modes like paredit and it also has a visual aid, and once done editing, it flips it back via (2).
Notably, an editor which edits trees of delimiters, like paredit, can edit a subset of the real AST and can achieve a lot of value on this basis. Most obviously, automatic indentation when you hit new line is easy because it’s all explicit.
So e.g.
becomes
This would be an alternative attack on the problem dealt with by structured-haskell-mode.
Thoughts welcome.