Skip to content
Haskell source code pretty print
Haskell Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src
test
.gitignore
Guardfile
LICENSE
README.md
Setup.hs
pretty-hs.cabal

README.md

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.

Something went wrong with that request. Please try again.