Racket fixw

March 24, 2026 ยท View on GitHub

A Racket formatter that adjusts whitespace but respects newlines.

:battery: Status

It should work as expected, except some builtin rules for macros and special forms are missing.

:printer: Example

before

#lang racket

(define(fib n )
(if (<= n 1)
1
(+ (fib  (- n 1))
(fib (- n 2)) )))

after

#lang racket

(define (fib n)
  (if (<= n 1)
      1
      (+ (fib (- n 1))
         (fib (- n 2)))))

:airplane: Performance

  • format a 5k lines file in 100ms on a 6 years old laptop

The biggest Racket file class-internal.rkt in racket/racket repo has almost 5k lines, so I think it's fast enough.

:sparkles: Features

  • Fixes indentation
  • Respects existing newlines
  • Works on incorrect code
  • Enforces a trailing empty line at the end of file with -n or --newline
  • Ensures at least one trailing newline at end of file with --ensure-newline-eof
  • Enforces single spaces between tokens (with several exceptions)
  • Raco integration
  • Reads scmindent-compatible configuration files
  • Skips code surrounded by special comments
  • Supports range formatting

Planned Features:

  • Customizable formatting system (macro-like)
    • Sorting require clauses
    • Keyword arguments and default arguments support

:bookmark_tabs: Todo

:rocket: Run

# install
raco pkg install fixw
# show help
raco fixw -h
# read from stdin and print formatted text to stdout
raco fixw
# ensure the file ends with at least one newline
raco fixw --ensure-newline-eof some-file.rkt
# format all Racket files in current directory recursively
raco fixw .

:thinking: Documentation

See the online documentation.

:paperclips: See also

  • fmt - A Racket formatter that calculates optimal layout.
  • scmindent - A general Lisp indenter.