Skip to content

Add options to configure indentation #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@
## Installation
Install with your favorite plugin manager.

## Options
If you don't like the default indentation you can easily change it by creating the following variables.

Here are some examples:

* `let g:haskell_indent_do = 3`

do
>>>foo

* `let g:haskell_indent_if = 2`

if foo
>>then bar
>>else baz

* `let g:haskell_indent_case = 2`

case foo of
>>bar -> baz

* `let g:haskell_indent_in = 1`

let x = 1
>in x

## Author
itchyny (https://github.com/itchyny)

Expand Down
25 changes: 17 additions & 8 deletions indent/haskell.vim
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ function! GetHaskellIndent() abort

" in
if line =~# '\v^\s*<in>'
return s:indent('\v^\s*<in>', '\v^.*<let>\s*\zs', 0, -1)
return exists('g:haskell_indent_in')
\ ? s:indent('\v^\s*<in>', '\v^.*\zs<let>', 0, -1) + g:haskell_indent_in
\ : s:indent('\v^\s*<in>', '\v^.*<let>\s*\zs', 0, -1)
endif

" =
Expand Down Expand Up @@ -124,7 +126,7 @@ function! GetHaskellIndent() abort
endif

if nonblankline =~# '\v<do>\s*%(--.*)?$'
return match(nonblankline, '\v^\s*%(<where>|.*<let>)?\s*\zs') + &shiftwidth
return match(nonblankline, '\v^\s*%(<where>|.*<let>)?\s*\zs') + get(g:, 'haskell_indent_do', &shiftwidth)
endif

if nonblankline =~# '\v<do>\s*[[:alnum:](]'
Expand All @@ -133,7 +135,9 @@ function! GetHaskellIndent() abort

if line =~# '\v<if>' && line !~# '\v^\s*#'
if line !~# '\v<then>'
return match(line, '\v.*<if>\s*\zs')
return exists('g:haskell_indent_if')
\ ? match(line, '\v.*\zs<if>') + g:haskell_indent_if
\ : match(line, '\v.*<if>\s*\zs')
elseif line !~# '\v<else>'
return match(line, '\v.*\zs<then>')
endif
Expand All @@ -147,9 +151,13 @@ function! GetHaskellIndent() abort
return indent(s:prevnonblank(v:lnum - 1)) + &shiftwidth
endif
else
return line =~# '\v<case>.*<of>\s*([[:alnum:](\"''\[]|-\d)'
\ ? match(line, '\v<case>.*<of>\s*\zs\S')
\ : match(line, '\v.*<case>\s*\zs')
if line =~# '\v<case>.*<of>\s*([[:alnum:](\"''\[]|-\d)'
return match(line, '\v<case>.*<of>\s*\zs')
else
return exists('g:haskell_indent_case')
\ ? match(line, '\v.*\zs<case>') + g:haskell_indent_case
\ : match(line, '\v.*<case>\s*\zs')
endif
endif
endif

Expand Down Expand Up @@ -465,8 +473,9 @@ function! s:indent_then() abort
if lnum == 0 && col == 0
return -1
else
" consider adding option to decide where to indent 'then'
return match(getline(lnum)[col - 1:], '\v<if>\s*\zs') + col - 1
return exists('g:haskell_indent_if')
\ ? g:haskell_indent_if + col - 1
\ : match(getline(lnum)[col - 1:], '\v<if>\s*\zs') + col - 1
endif
endfunction

Expand Down