fixw
1 Examples
2 raco fixw
3 API
fixw
fixw/  lines
4 Features
5 Indent rules
6 Config file
7 Enable/  Disable in code
8.12

fixw🔗ℹ

6cdh

 (require fixw) package: fixw

A Racket formatter that only fixes whitespaces and keep newlines.

It provides a command line tool and a library.

1 Examples🔗ℹ

before

#lang racket
 
(Range #:start (Position #:line 0
#:character 0)
#:end(Position #:line 10
#:character 0))

after

#lang racket
 
(Range #:start (Position #:line 0
                         #:character 0)
       #:end (Position #:line 10
                       #:character 0))

2 raco fixw🔗ℹ

raco fixw reads text from stdin, and output formatted code to stdout.

raco fixw files or dirs ... format files or dirs recursively. For files, fixw will format it whatever its extension. For dirs, fixw will format all "*.rkt" files recursively.

It accepts these flags:

3 API🔗ℹ

procedure

(fixw in rules [#:interactive? interactive?])  string?

  in : input-port?
  rules : (or/c (hash/c string? integer?) #f)
  interactive? : boolean? = #f
Read from in, and user defined rules rules, return formatted string.

If interactive? is #t, every empty line will be indented with appropriate amount of whitespace as if there are visible atom at that line. It is designed to be used when editing.

fixw also remove extra trailing empty lines to keep only one trailing empty line.

The builtin rules are always used.

procedure

(fixw/lines in    
  rules    
  [start    
  end    
  #:interactive? interactive?])  (listof string?)
  in : input-port?
  rules : (or/c (hash/c string? integer?) #f)
  start : exact-nonnegative-integer? = 0
  end : exact-nonnegative-integer? = (length (port->lines in))
  interactive? : boolean? = #f
Like fixw, but return a list of string contains the formatted lines from start to end(exclusive).

fixw/lines don’t remove extra trailing empty lines.

The builtin rules are always used.

4 Features🔗ℹ

You might want to know what fixw exactly do with your code:

Any other behavior should be considered a bug.

5 Indent rules🔗ℹ

fixw indenter has a basic assumption: user defined procedure is more common than macros. So it will perform procedure indent by default.

The procedure indent look like this:

(fn arg1
    arg2
    ...)

Macros as special cases. They are assumed to be like this:

(macro parg_1
       parg_2
       ...
       parg_n
  body ...)

The number of parg of a macro is specified by a rule.

For example, A rule ("func" 2) specifies a form whose first element is func, then 2 argument aligned, then body. So fixw will format func as this:

(func (function-name args ...)
      (types ...)
  body ...)

Except these two strategy, fixw also use some heuristics strategies. Here are the full details:

6 Config file🔗ℹ

fixw support read user defined rules from config file ".lispwords" that compatible with scmindent’s config. Here are some examples, they are equivalent.

(lambda 1)
(define 1)
;; or
(1 define lambda)
;; or
((define lambda) 1)

For a file that need to be formatted, fixw will try to read the ".lispwords" file at the same directory. If not found, then its parent directory, ..., until the root directory.

The builtin rules are always used. User defined rules can override them.

7 Enable/Disable in code🔗ℹ

Use (fixw off) in comment to disable fixw temporarily. And (fixw on) to enable it.

For example,

;; (fixw off)
 
;; your code
 
;; (fixw on)