Zane-XY / haskell-pretty

Haskell source code pretty print

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pretty-hs

very basic haskell source code pretty printer using Language.Haskell.Exts.Pretty

Installation

clone and run

cabal install

this should install the pretty-hs exebutable into your ~/.cabal/bin/ or cabal binary directory, make sure it's in your path.

Usage

The prettyPrint function is called with stdin input and format it to stdout. If your text editor supports external formmater, you can use it to format code fragments.

Vim Integration

add this into your .vimrc

au BufEnter *.hs setl formatprg=pretty-hs\ --stdin\ --stdout

and use gq to format a block of selected codes, if the source can't be parsed, it'll return the original source.

##Formatter demo

visual select the following code

prettyHS ::             String     ->          String
prettyHS src = case parseFileContentsWithComments defaultParseMode src of
        ParseOk (ast, _)          -> prettyPrint ast
        _ ->       src

format with gq, you'll get:

prettyHS :: String -> String
prettyHS src
  = case parseFileContentsWithComments defaultParseMode src of
        ParseOk (ast, _) -> prettyPrint ast
        _ -> src

Limitation

the Language.Haskell.Exts doesn't provide parameterized formatter, so it's not configurable. And the comments is discarded in the prettyPrint function, so this formatter is just used for formatting code fragments.

About

Haskell source code pretty print

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Haskell 84.0%Language:Ruby 16.0%