Manpage logo

fnlfmt - a code formatter for Fennel

NAME  SYNOPSIS  DESCRIPTION  OPTIONS  DOCUMENTATION  KNOWN ISSUES  SEE ALSO  COMMUNITY  LICENSE 

NAME

fnlfmt − a code formatter for Fennel

SYNOPSIS

fnlfmt [--check] | [--fix] | [--no-comments] FILENAME...

DESCRIPTION

This manual page documents briefly the fnlfmt command.

fnlfmt is a code formatter for Fennel code.

OPTIONS

When no command is given, formats the given file and prints the result to standard out.

−−fix

Format the given file and write the result back to the original file.

−−check

Fail (exit code 1) if the given file is not currently formatted.

−−no−comments

Strip comments from the file.

DOCUMENTATION

Formatting is essentially an aesthetic process; any automated attempt at doing it will necessarily encounter situations where it produces output that doesn’t look as good as it would if a human were making the decisions. That said, the goal is to at worst emit output which, if less than ideal, is at least not objectionable. Currently the indentation decisions it makes are great, but it occasionally puts newlines in places that a human would not.

For the most part, fnlfmt follows established lisp conventions when determining how to format a given piece of code. Key/value tables are shown with each key/value pair on its own line, unless they are small enough to all fit on one line. Sequential tables similarly have each element on their own line unless they fit all on a single line. Tables with string keys and symbol values will use {: foo : bar} shorthand notation where possible.

Calls are formatted differently depending on whether they are calling a regular function/macro or whether they’re calling a special macro which is known to have a body; in the latter case every element is given its own line, usually indented 2 spaces in.

Forms calling match and if are treated differently; if possible it will attempt to pair off their pattern/condition clauses with the body on the same line. If that can’t fit, it falls back to one-form-per-line.

Certain forms which have a body are sometimes allowed to keep their body on the same line as the call, if the original code has it that way, provided the body doesn’t nest more than two levels and fits in the line length limit.

Strings are formatted using :colon-notation where possible, unless they consist entirely of punctuation.

Top level forms may or may not have blank lines between them depending on whether the input code spaces them out. Functions defined inside a body form get empty lines spacing them out as well.

Similarly if forms and arrow forms will occasionally be allowed to be one line if the original code had them as one-liners.

By design there is no way to configure it; the indentation should be considered canonical other than bugs or when new features are added to Fennel itself.

KNOWN ISSUES

Comments will not be wrapped.

When using fnlfmt as a library, it may modify the AST argument.

Function argument lists will be displayed one-per-line if they can’t all fit on one line.

Some of the issues are inherent to this approach, or at least cannot be fixed without major changes:

Numbers are always emitted as decimal; hex notation is not preserved.

Page breaks and other whitespace will not be preserved.

Macros that take a body argument but aren’t built-in will only be indented correctly if their name starts with ‘with-‘ or ‘def‘. Functions which use this naming convention will be indented as if they were macros.

SEE ALSO

fennel(1)

COMMUNITY

Report bugs to the main Fennel mailing list at https://lists.sr.ht/˜technomancy/fennel

LICENSE

Copyright © 2019-2024, Released under the MIT/X11 license


Updated 2026-06-01 - jenkler.se | uex.se