Formatter
Part of m2-ls, and also a standalone m2-fmt.
It fixes spacing, derives indentation from the syntax tree and wraps long lines where the syntax allows. It doesn’t change what your code does: dropping redundant parentheses and such is left to quick fixes.
f=x->(if x>0 then 1 else 2) -- before
f = x -> (if x > 0 then 1 else 2) -- after
In the editor, just use “format document”. On the command line:
m2-fmt file.m2 # in place
m2-fmt --check file.m2 # exit 1 if not formatted, handy in CI
m2-fmt --stdout file.m2 # print instead of writing
Files with syntax errors are left alone.
Knobs
Under m2-ls.formatting (or --config settings.json for m2-fmt):
indent,useTabs: default to your editor’s settings, 4 spaces on the CLIsoftLineWidth/hardLineWidth: preferred and maximum line width, 78 / 90controlFlowLayout:compact,multilineormultilineCompactElse(default)compactFactorOperators:2*xinstead of2 * xbreakAfterSemicolon: new line after every;