Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 CLI
  • softLineWidth / hardLineWidth: preferred and maximum line width, 78 / 90
  • controlFlowLayout: compact, multiline or multilineCompactElse (default)
  • compactFactorOperators: 2*x instead of 2 * x
  • breakAfterSemicolon: new line after every ;