Skip to content

Commit d6c7712

Browse files
committed
use indent function to compute indentation
1 parent 4bd6150 commit d6c7712

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

indent/haskell.vim

+13-12
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,25 @@ endfunction
108108
function! s:indentGuard(pos, prevline)
109109
let l:l = a:prevline
110110
let l:c = v:lnum - 1
111+
let l:s = indent(l:c)
111112

112113
while l:c >= 1
113-
if l:l =~ '^\S'
114+
if l:s == 0 && strlen(l:l) > 0
114115
" top-level start, stop looking
115116
return g:haskell_indent_guard
116117
elseif l:l =~ '^\s\+[|,=]\s\+'
117118
" guard block found
118119
return match(l:l, '[|,=]')
119120
else
120-
let l:m = match(l:l, '\S')
121-
if l:m >= 0 && l:m <= a:pos
121+
if l:s > 0 && l:s <= a:pos
122122
" found less deeper indentation (not starting with `,` or `=`)
123123
" stop looking
124-
return l:m + g:haskell_indent_guard
124+
return l:s + g:haskell_indent_guard
125125
endif
126126
endif
127127
let l:c -= 1
128128
let l:l = getline(l:c)
129+
let l:s = indent(l:c)
129130
endwhile
130131

131132
return -1
@@ -188,7 +189,7 @@ function! GetHaskellIndent()
188189

189190
" operator at end of previous line
190191
if l:prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
191-
return match(l:prevline, '\S') + &shiftwidth
192+
return indent(v:lnum - 1) + &shiftwidth
192193
endif
193194

194195
" let foo =
@@ -242,7 +243,7 @@ function! GetHaskellIndent()
242243
" >>foo
243244
"
244245
if l:prevline =~ '\C\<where\>\s*$'
245-
return match(l:prevline, '\S') + get(g:, 'haskell_indent_after_bare_where', &shiftwidth)
246+
return indent(v:lnum - 1) + get(g:, 'haskell_indent_after_bare_where', &shiftwidth)
246247
endif
247248

248249
" do
@@ -251,7 +252,7 @@ function! GetHaskellIndent()
251252
" foo =
252253
" >>bar
253254
if l:prevline =~ '\C\(\<do\>\|=\)\s*$'
254-
return match(l:prevline, '\S') + &shiftwidth
255+
return indent(v:lnum - 1) + &shiftwidth
255256
endif
256257

257258
" do foo
@@ -267,7 +268,7 @@ function! GetHaskellIndent()
267268
" >>bar -> quux
268269
if l:prevline =~ '\C\<case\>.\+\<of\>\s*$'
269270
if get(g:,'haskell_indent_case_alternative', 0)
270-
return match(l:prevline, '\S') + &shiftwidth
271+
return indent(v:lnum - 1) + &shiftwidth
271272
else
272273
return match(l:prevline, '\C\<case\>') + g:haskell_indent_case
273274
endif
@@ -300,7 +301,7 @@ function! GetHaskellIndent()
300301
" newtype Foo = Foo
301302
" >>deriving
302303
if l:prevline =~ '\C^\s*\<\(newtype\|data\)\>[^{]\+' && l:line =~ '\C^\s*\<deriving\>'
303-
return match(l:prevline, '\S') + &shiftwidth
304+
return indent(v:lnum - 1) + &shiftwidth
304305
endif
305306

306307
" foo :: Int
@@ -405,7 +406,7 @@ function! GetHaskellIndent()
405406
" foo
406407
" >>{
407408
if l:line =~ '^\s*{'
408-
let l:s = match(l:prevline, '\S')
409+
let l:s = indent(v:lnum - 1)
409410
if l:s >= 0
410411
return l:s + &shiftwidth
411412
endif
@@ -423,7 +424,7 @@ function! GetHaskellIndent()
423424
return match(l:prevline, 'in') - g:haskell_indent_in
424425
endif
425426

426-
return match(l:prevline, '\S') + get(g:, 'haskell_indent_before_where', &shiftwidth)
427+
return indent(v:lnum - 1) + get(g:, 'haskell_indent_before_where', &shiftwidth)
427428
endif
428429

429430
" let x = 1
@@ -488,7 +489,7 @@ function! GetHaskellIndent()
488489
" foo
489490
" >>:: Int
490491
if l:line =~ '^\s*::\s'
491-
return match(l:prevline, '\S') + &shiftwidth
492+
return indent(v:lnum - 1) + &shiftwidth
492493
endif
493494

494495
" indent closing brace, paren or bracket

0 commit comments

Comments
 (0)