summaryrefslogtreecommitdiffstats
path: root/indent/haskell.vim
diff options
context:
space:
mode:
Diffstat (limited to 'indent/haskell.vim')
-rw-r--r--indent/haskell.vim90
1 files changed, 49 insertions, 41 deletions
diff --git a/indent/haskell.vim b/indent/haskell.vim
index 43dc97a6..e63515ce 100644
--- a/indent/haskell.vim
+++ b/indent/haskell.vim
@@ -13,11 +13,7 @@ if exists('b:did_indent')
finish
endif
-if !exists('g:haskell_indent_disable')
- let g:haskell_indent_disable = 0
-endif
-
-if g:haskell_indent_disable != 0
+if get(g:, 'haskell_indent_disable', 0)
finish
endif
@@ -68,7 +64,7 @@ if !exists('g:haskell_indent_guard')
endif
setlocal indentexpr=GetHaskellIndent()
-setlocal indentkeys=0},0),0],!^F,o,O,0\=,0=where,0=let,0=deriving,<space>
+setlocal indentkeys=0},0),0],!^F,o,O,0=where,0=let,0=deriving,<space>
function! s:isInBlock(hlstack)
return index(a:hlstack, 'haskellDelimiter') > -1 || index(a:hlstack, 'haskellParens') > -1 || index(a:hlstack, 'haskellBrackets') > -1 || index(a:hlstack, 'haskellBlock') > -1 || index(a:hlstack, 'haskellBlockComment') > -1 || index(a:hlstack, 'haskellPragma') > -1
@@ -159,15 +155,6 @@ function! GetHaskellIndent()
return 0
endif
- " " comment indentation
- " if l:line =~ '^\s*--'
- " let l:s = match(l:prevline, '-- ')
- " if l:s > -1
- " endif
- " " if l:prevline =~ '^\s*--'
- " " return match(l:prevline, '\S')
- " " endif
-
" { foo :: Int
" >>,
"
@@ -258,12 +245,16 @@ function! GetHaskellIndent()
" where
" >>foo
"
+ if l:prevline =~ '\C\<where\>\s*$'
+ return match(l:prevline, '\S') + get(g:, 'haskell_indent_after_bare_where', &shiftwidth)
+ endif
+
" do
" >>foo
"
" foo =
" >>bar
- if l:prevline =~ '\C\(\<where\>\|\<do\>\|=\)\s*$'
+ if l:prevline =~ '\C\(\<do\>\|=\)\s*$'
return match(l:prevline, '\S') + &shiftwidth
endif
@@ -279,7 +270,7 @@ function! GetHaskellIndent()
" case foo of
" >>bar -> quux
if l:prevline =~ '\C\<case\>.\+\<of\>\s*$'
- if exists('g:haskell_indent_case_alternative') && g:haskell_indent_case_alternative
+ if get(g:,'haskell_indent_case_alternative', 0)
return match(l:prevline, '\S') + &shiftwidth
else
return match(l:prevline, '\C\<case\>') + g:haskell_indent_case
@@ -321,38 +312,50 @@ function! GetHaskellIndent()
" foo :: Int
" -> Int
+ " >>>>-> Int
+ "
+ " foo :: Monad m
+ " => Functor f
+ " >>>>=> Int
+ "
+ " foo :: Int
+ " -> Int
" foo x
"
" foo
" :: Int
" -> Int
" foo x
- if l:prevline =~ '^\s*[-=]>' && l:line !~ '^\s*[-=]>'
- if s:isInBlock(l:hlstack)
- return match(l:prevline, '[^\s-=>]')
+ if l:prevline =~ '^\s*[-=]>'
+ if l:line =~ '^\s*[-=]>'
+ return match(l:prevline, '[-=]')
else
- let l:m = matchstr(l:line, '^\s*\zs\<\S\+\>\ze')
- let l:l = l:prevline
- let l:c = 1
-
- while v:lnum != l:c
- " fun decl
- if l:l =~ ('^\s*' . l:m . '\(\s*::\|\n\s\+::\)')
- let l:s = match(l:l, l:m)
- if match(l:l, '\C^\s*\<default\>') > -1
- return l:s - 8
- else
- return l:s
+ if s:isInBlock(l:hlstack)
+ return match(l:prevline, '[^-=]')
+ else
+ let l:m = matchstr(l:line, '^\s*\zs\<\S\+\>\ze')
+ let l:l = l:prevline
+ let l:c = 1
+
+ while v:lnum != l:c
+ " fun decl
+ if l:l =~ ('^\s*' . l:m . '\(\s*::\|\n\s\+::\)')
+ let l:s = match(l:l, l:m)
+ if match(l:l, '\C^\s*\<default\>') > -1
+ return l:s - 8
+ else
+ return l:s
+ endif
+ " empty line, stop looking
+ elseif l:l =~ '^$'
+ return 0
endif
- " empty line, stop looking
- elseif l:l =~ '^$'
- return 0
- endif
- let l:c += 1
- let l:l = getline(v:lnum - l:c)
- endwhile
+ let l:c += 1
+ let l:l = getline(v:lnum - l:c)
+ endwhile
- return 0
+ return 0
+ endif
endif
endif
@@ -403,12 +406,17 @@ function! GetHaskellIndent()
" in foo
" where bar
+ "
+ " or
+ "
+ " foo
+ " >>where
if l:line =~ '\C^\s*\<where\>'
if match(l:prevline, '\C^\s\+in\s\+') == 0
return match(l:prevline, 'in') - g:haskell_indent_in
endif
- return match(l:prevline, '\S') + &shiftwidth
+ return match(l:prevline, '\S') + get(g:, 'haskell_indent_before_where', &shiftwidth)
endif
" let x = 1