ffmt
A fast, configurable Fortran formatter with support for Fypp, Doxygen, and OpenACC/OpenMP directives. Written in Rust. Installable via pip.
Installation
Or via Cargo:
Usage
|
What it does
- Indentation -- scope-based indentation for all Fortran constructs
- Whitespace -- consistent spacing around operators, commas, colons, parentheses
- Keywords -- case normalization (
IF->if,ENDDO->end do) - Continuation lines -- normalized with proportional re-indentation
- Preprocessor -- Fypp (
#:if,#:for), OpenACC (!$acc), OpenMP (!$omp) handled correctly
Configuration
Create ffmt.toml or add [tool.ffmt] to pyproject.toml:
= 4
= 132
= "lower" # lower, upper, preserve
= true # enddo -> end do
= true # end subroutine -> end subroutine s_foo
= true # align :: in consecutive declarations
= true # Greek/math symbols -> LaTeX in comments
= true # wrap long comments at line-length
= true # wrap long code lines at line-length
= true # !comment -> ! comment
= true # x = y -> x = y
= true # if( -> if (
= true # normalize commas in Fypp '[...]' args
[]
= true # ==, /=, <, <=, >, >=
= true # .and., .or., .not.
= true # binary +, -
= false # *, /
= false # **
= true # =
= true # ::
= true # space after comma
All options have sensible defaults -- most projects need no config file at all.
Preserved as-is
- String literals and inline expressions (
${...}$,@{...}@) - Comment contents and Doxygen alignment (
!<,!>,!!) - Continuation line structure
#ifdef/#endifblocks (no indentation change)
Editor integration
ffmt includes a built-in LSP server for real-time format-on-save:
VS Code
Vim/Neovim
autocmd BufWritePost *.fpp,*.f90 silent !ffmt %
" Or: set formatprg=ffmt\ -
Neovim (LSP)
vim..
CI integration
GitHub Actions
- uses: sbryngelson/ffmt@v0.1.0
with:
args: "--check src/"
pre-commit
repos:
- repo: https://github.com/sbryngelson/ffmt
rev: v0.1.0
hooks:
- id: ffmt
Other Fortran Formatters
| Formatter | Language | Status | Notes |
|---|---|---|---|
| fprettify | Python | Unmaintained (last release 2020) | Free-form only. Fypp support. Requires multiple passes for convergence. |
| findent | C | Active | Indentation and fixed/free conversion. No whitespace normalization. |
| Codee Formatter | Proprietary | Active | Commercial. Tree-sitter based. Fixed and free-form. |
| LFortran fmt | Rust | In development | AST-based. Part of the LFortran compiler project. |
| Fortitude | Rust | Active | Linter with auto-fix, not a full formatter. Tree-sitter based. |
| f90-mode | Emacs Lisp | Active | Emacs built-in. Indentation only. |
License
MIT