Skip to content

Commit

Permalink
factor out matching character indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
raichoo committed Mar 5, 2016
1 parent cfdadd6 commit 54a3f53
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions indent/haskell.vim
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ function! s:getHLStack()
return map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunction

" indent matching character
function! s:indentMatching(char)
norm 0
call search(a:char, 'c')
norm %
return col('.') - 1
endfunction

" backtrack to find guard clause
function! s:indentGuard(pos, prevline)
let l:l = a:prevline
Expand Down Expand Up @@ -382,18 +390,15 @@ function! GetHaskellIndent()

" indent closing brace, paren or bracket
if l:line =~ '^\s*}'
norm 0f}%
return col('.') - 1
return s:indentMatching('}')
endif

if l:line =~ '^\s*)'
norm 0f)%
return col('.') - 1
return s:indentMatching(')')
endif

if l:line =~ '^\s*]'
norm 0f]%
return col('.') - 1
return s:indentMatching(']')
endif

return match(l:prevline, '\S')
Expand Down

0 comments on commit 54a3f53

Please sign in to comment.