This commit is contained in:
Adam Stankiewicz
2017-03-23 11:28:19 +01:00
parent 9f735b1fe7
commit 0801eac01a
45 changed files with 2015 additions and 1258 deletions

View File

@@ -13,12 +13,16 @@ if exists('b:did_indent')
finish
endif
let b:did_indent = 1
if !exists('g:haskell_indent_disable')
let g:haskell_indent_disable = 0
endif
if g:haskell_indent_disable != 0
finish
endif
let b:did_indent = 1
if !exists('g:haskell_indent_if')
" if x
" >>>then ...
@@ -63,22 +67,16 @@ if !exists('g:haskell_indent_guard')
let g:haskell_indent_guard = 2
endif
if exists("g:haskell_indent_disable") && g:haskell_indent_disable == 0
setlocal indentexpr=GetHaskellIndent()
setlocal indentkeys=0{,0},0(,0),0[,0],!^F,o,O,0\=,0=where,0=let,0=deriving,<space>
else
setlocal nocindent
setlocal nosmartindent
setlocal autoindent
endif
setlocal indentexpr=GetHaskellIndent()
setlocal indentkeys=0},0),0],!^F,o,O,0\=,0=where,0=let,0=deriving,<space>
function! s:isInBlock(hlstack)
return 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
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
endfunction
function! s:stripTrailingComment(line)
if a:line =~ '^\s*--\(-\+\|\s\+\)' || a:line =~ '^\s*{-'
return a:line
function! s:stripComment(line)
if a:line =~ '^\s*--\(-*\s\+\|$\)'
return ''
else
let l:stripped = split(a:line, '-- ')
if len(l:stripped) > 1
@@ -144,7 +142,7 @@ function! GetHaskellIndent()
return -1
endif
let l:prevline = s:stripTrailingComment(getline(v:lnum - 1))
let l:prevline = s:stripComment(getline(v:lnum - 1))
let l:line = getline(v:lnum)
" indent multiline strings
@@ -161,13 +159,14 @@ function! GetHaskellIndent()
return 0
endif
" comment indentation
if l:line =~ '^\s*--'
return match(l:prevline, '-- ')
endif
if l:prevline =~ '^\s*--'
return match(l:prevline, '\S')
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
" >>,
@@ -176,7 +175,7 @@ function! GetHaskellIndent()
" ...
" >>,
if l:line =~ '^\s*,'
if s:isInBlock(l:hlstack)
if s:isInBlock(s:getHLStack(line('.'), col('.')))
normal! 0
call search(',', 'cW')
let l:n = s:getNesting(s:getHLStack(line('.'), col('.')))
@@ -395,7 +394,7 @@ function! GetHaskellIndent()
" foo
" >>{
if l:line =~ '^\s*{' && l:prevline !~ '^{'
if l:line =~ '^\s*{ '
let l:s = match(l:prevline, '\S')
if l:s >= 0
return l:s + &shiftwidth
@@ -477,16 +476,7 @@ function! GetHaskellIndent()
return s:indentMatching(']')
endif
" do not reindent indented lines
if match(l:prevline, '\S') < match(l:line, '\S')
return -1
endif
if l:line !~ '^\s*[=-]>\s' && l:line =~ '^\s*[!#$%&*+./<>?@\\^|~-]\+'
return -1
endif
return match(l:prevline, '\S')
return -1
endfunction
endif