Skip to content

Elixir code formatted with intelligent line wrapping

Notifications You must be signed in to change notification settings

Steams/Elixirfmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elixirfmt (Work in progress)

Elixir Code formatter with automatic line wrapping based on Phillip Wadler's "A Prettier Printer"

Current working Example
    max_width = 40

    str = "def nested(one,two,three,four) do
      sum4 = fn(x,y,z,a) -> x + y + z + a end

      somethingElse = fn(name,surname) -> name ++ surname end
      somethingElse = fn(name,surname) -> name ++ surname end
    end"

    ast = Code.string_to_quoted!(str)

    parsed = parse_ast(ast)

    doc = show_ast(parsed)

    IO.puts("|" <> String.duplicate("-",w-2) <> "|")
    IO.puts(pretty(max_width,doc))

Output with max line width 40

|--------------------------------------|
def nested( one, two, three, four, ) do 
  sum4 = fn( x, y, z, a, ) -> 
    x + y + z + a
  end
  
  somethingElse = fn(
    name, surname,
  ) ->  name ++ surname end
  
  somethingElse = fn(
    name, surname,
  ) ->  name ++ surname end
  
end

with Max line width 80

|------------------------------------------------------------------------------|
def nested( one, two, three, four, ) do 
  sum4 = fn( x, y, z, a, ) ->  x + y + z + a end
  
  somethingElse = fn( name, surname, ) ->  name ++ surname end
  
  somethingElse = fn( name, surname, ) ->  name ++ surname end
  
end

About

Elixir code formatted with intelligent line wrapping

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages