Skip to content

Zane-XY/haskell-pretty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published