• Stars
    star
    559
  • Rank 79,673 (Top 2 %)
  • Language
    Haskell
  • License
    Other
  • Created about 10 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Haskell pretty printer

hindent Hackage Haskell Cabal Haskell Stack OpenSSF Scorecard

Haskell pretty printer

Examples

Install

$ stack install hindent

Usage

$ hindent --help
hindent - Reformat Haskell source code

Usage: hindent [--version | [--line-length ARG]
                 [--indent-size ARG | --tab-size ARG] [--no-force-newline]
                 [--sort-imports | --no-sort-imports] [--style STYLE]
                 [-X GHCEXT] [--validate] [FILENAMES]]

Available options:
  --version                Print the version
  --line-length ARG        Desired length of lines (default: 80)
  --indent-size ARG        Indentation size in spaces (default: 2)
  --tab-size ARG           Same as --indent-size, for compatibility
  --no-force-newline       Don't force a trailing newline
  --sort-imports           Sort imports in groups
  --no-sort-imports        Don't sort imports
  --style STYLE            Style to print with (historical, now ignored)
  -X GHCEXT                Language extension
  --validate               Check if files are formatted without changing them
  -h,--help                Show this help text

hindent is used in a pipeline style

$ cat path/to/sourcefile.hs | hindent

The default indentation size is 2 spaces. Configure indentation size with --indent-size:

$ echo 'example = case x of Just p -> foo bar' | hindent --indent-size 2; echo
example =
  case x of
    Just p -> foo bar
$ echo 'example = case x of Just p -> foo bar' | hindent --indent-size 4; echo
example =
    case x of
        Just p -> foo bar

Customization

Create a .hindent.yaml file in your project directory or in your ~/ home directory. The following fields are accepted and are the default:

indent-size: 2
line-length: 80
force-trailing-newline: true
sort-imports: true
line-breaks: []
extensions: []

By default, hindent preserves the newline or lack of newline in your input. With force-trailing-newline, it will make sure there is always a trailing newline.

hindent can be forced to insert a newline before specific operators and tokens with line-breaks. This is especially useful when utilizing libraries like servant which use long type aliases.

Using extensions, hindent can be made aware of valid syntactic compiler extensions that would normally be considered invalid syntax.

It is also possible to specify which extensions HIndent runs with in your .hindent.yaml:

extensions:
  - MagicHash
  - RecursiveDo

Emacs

In elisp/hindent.el there is hindent-mode, which provides keybindings to reindent parts of the buffer:

  • M-q reformats the current declaration. When inside a comment, it fills the current paragraph instead, like the standard M-q.
  • C-M-\ reformats the current region.

To enable it, add the following to your init file:

(add-to-list 'load-path "/path/to/hindent/elisp")
(require 'hindent)
(add-hook 'haskell-mode-hook #'hindent-mode)

Vim

The 'formatprg' option lets you use an external program (like hindent) to format your text. Put the following line into ~/.vim/ftplugin/haskell.vim to set this option for Haskell files:

setlocal formatprg=hindent

Then you can format with hindent using gq. Read :help gq and help 'formatprg' for more details.

Note that unlike in emacs you have to take care of selecting a sensible buffer region as input to hindent yourself. If that is too much trouble you can try vim-textobj-haskell which provides a text object for top level bindings.

In order to format an entire source file execute:

:%!hindent

Alternatively you could use the vim-hindent plugin which runs hindent automatically when a Haskell file is saved.

IntelliJ / other JetBrains IDEs

  1. Install the "HaskForce" Haskell plugin (this is so we get the language type recognized in the file watcher)
  2. Install the "File Watchers" plugin under "Browse Repositories"
  3. Add a File Watcher with
    1. File type: Haskell Language
    2. Program: /path/to/hindent
    3. Arguments: $FilePath$
    4. Immediate file synchronization: off
    5. Show console: Error

Now whenever you save a file, hindent should autoformat it.

More Repositories

1

JADE-ARIA

JADE extensions developed at first ARIA Hackathon (http://www.aria-romania.org/en/community/63-aria-hackaton-1)
Java
8
star
2

HsMaze

A robot trying to escape from a maze using GA
Haskell
7
star
3

io-manager

Haskell IO manager for hiding the IO monad and related advanced concepts. Useful for beginners.
Haskell
7
star
4

q-learning

Q-learning implementation for Machine Learning Course
Python
6
star
5

dphcar

Differentially Private High Confidence Association Rules
C
4
star
6

HaCoTeB

This project is dead. It started disorganized and ended prematurely as it was expected due to a busy schedule and because I forgot some of the ideas from the start. Sorry. Transforms a textfile containing code and text into a HTML file, useful for blogging.
Haskell
4
star
7

ssl

SSL - Solving CAPTCHAs. Homework project.
Java
3
star
8

id3

Small id3 classifier written for the Automatic Learning Course
C
3
star
9

blog-demos

Demos from my old blog, collected, changed and moved to the new one when active.
Haskell
3
star
10

ixcode

Utility for code spelunking
Python
3
star
11

book-of-marks

Bookmark manager written in Haskell. Non-browser. Either GUI or cmdline. Linux/GTK only.
Haskell
3
star
12

blog-engine

The engine behind the blog at https://mihai.page
Haskell
2
star
13

petulant-octo-avenger

Small project for holding helpers for one MMORPG I play
Haskell
2
star
14

naaya-nose-selenium

Integrating nynose (nose for Naaya) with Selenium
Python
1
star
15

real-slacking-service

A RSS feed reader for Linux Desktops (mainly Gnome3, used privately)
Haskell
1
star
16

mithlond

Old attempt to create my personal blog
Haskell
1
star
17

TSM

Repository for the TSM (Today Software Magazine) articles.
Haskell
1
star
18

Backpropagation

Backpropagation implementation in Python for forecasting/regression
Python
1
star
19

secret-octo

Some experiments with crypto and bits.
C
1
star
20

HsMinesweeper

A short multiagent game of Minesweeper. Homework for the Artificial Intelligence Course.
Haskell
1
star
21

KamikazeRace

A clone for Android of the popular and addictive KamikazeRace game on Facebook (not for profit)
Java
1
star
22

hirst-v00

Haskell IRC statistics - v.0.0
Haskell
1
star
23

cs680

CS680. A lot of Java :(
Java
1
star
24

esotd

Exponential sum of the day
Haskell
1
star
25

robotik

Robotik language - entry for http://www.pltgames.com/competition/2012/12
Haskell
1
star
26

nlp

NLP - Meta-cognition evaluation. Homework project.
Python
1
star
27

cdte

A Cooperative MAS for Distributed Task Execution (Multi Agent Systems Homework)
Haskell
1
star
28

test-stack-templates

Testing the new mm stack template.
Haskell
1
star
29

SchemePlanner

A simple planner in Scheme. Homework for the Artificial Intelligence course
Scheme
1
star
30

stack-test-coverage-sublibs

Demo project for a bug in Stack when asking for code coverage of a project with internal libraries
Haskell
1
star
31

pvz-tdd-hs

Plants vs Zombies in Haskell, via Test Driven Design
Haskell
1
star
32

dpsn

Differentially private sensor networks
C
1
star
33

FSFrame

A Frame System
Haskell
1
star
34

softbinator-dp

Presenation on Differential Privacy at Talks by Softbinator
TeX
1
star