SMLFormat is an autoformatter for the Standard ML programing language. It indents, keeps lines under 80 characters, and applies a set of heuristics to prettify code.
The source code of SMLFormat is formatted with SMLFormat.
git clone https://github.com/jluningp/smlformat.git SMLFORMAT_DIR
.$ echo "PATH=\"\$PATH:SMLFORMAT_DIR\"; export PATH" >> ~/.bashrc
$ source ~/.bashrc
SMLFormat can read from stdin and write to stdout, or it can take files as arguments.
Usage: smlformat [-i inputfile] [-o outputfile]
-i infile read code from file instead of stdin
-o outfile write formatted code to file instead of stdout
-h print this help message
Read from file:
$ echo "fun foo x = 10" > test.sml
$ smlformat -i test.sml
fun foo x = 10
Write to file:
$ echo "fun foo x = 10" | smlformat -o test_output.sml
$ cat test_output.sml
fun foo x = 10
Read and write files:
$ echo "fun foo x = 10" > test.sml
$ smlformat -i test.sml -o test_output.sml
$ cat test_output.sml
fun foo x = 10
Read from stdin and write to stdout:
$ echo "fun foo x = 10" | smlformat
fun foo x = 10
Format a file "in-place":
$ echo "fun foo x = 10" > test.sml
$ smlformat -i test.sml -o test.sml
$ cat test.sml
fun foo x = 10
If an input fails to parse, SMLFormat cannot format it and will return the original input.
$ echo "val x" | smlformat
val x
You can also manually run SMLFormat in the SML/NJ REPL by running
sml -m SMLFORMAT_DIR/sources.cm
- SmlFormat.format "input.sml";
val () = ()
-
editors/emacs/smlformat.el
. .emacs
, with SMLFORMAT_DIR
replaced by your SMLFormat directory:
(load "SMLFORMAT_DIR/editors/emacs/smlformat.el")
M-x smlformat
editors/vim
into Neoformat's formatters directory1.
cp editors/vim/* ~/.vim/plugged/neoformat/autoload/neoformat/formatters/
autocmd BufWritePre *.sml,*.sig Neoformat
1 Why is there sml.vim
and lprolog.vim
? Vim thinks .sig
files have filetype lprolog
: Neoformat