Skip to content

Commit bf6a265

Browse files
committed
fix after closing parenthesis of case expression (ref #27)
1 parent 6e645ed commit bf6a265

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

indent/haskell.vim

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ function! GetHaskellIndent() abort
191191
endif
192192

193193
if nonblankline =~# '\v[)}\]]\s*%(--.*)?$'
194-
return s:unindent_after_parenthesis(s:prevnonblank(v:lnum - 1), match(nonblankline, '\v[)}\]]\s*%(--.*)?$'))
194+
let i = s:unindent_after_parenthesis(s:prevnonblank(v:lnum - 1), match(nonblankline, '\v[)}\]]\s*%(--.*)?$'))
195+
if i >= 0
196+
return i
197+
endif
195198
endif
196199

197200
if nonblankline =~# '\v^\s*\|\s*.*\<-\s*.*,\s*%(--.*)?$'
@@ -245,7 +248,6 @@ function! GetHaskellIndent() abort
245248
if nonblankline =~# '\v\{-#\s*UNPACK\s*#-}' && getline(v:lnum) =~# '\v^\s*\{-#\s*UNPACK\s*#-}'
246249
return match(nonblankline, '\v\{-#\s*UNPACK\s*#-}')
247250
endif
248-
return s:indent('', '\v^.*<data>.*\zs\=', 0)
249251
endif
250252

251253
if nonblankline =~# '\v<let>\s+.*\=' && nonblankline !~# '\v<let>\s+.*\=.*<in>'
@@ -563,7 +565,7 @@ endfunction
563565
function! s:unindent_after_parenthesis(line, column) abort
564566
let i = s:prevnonblank(v:lnum - 1)
565567
if i < v:lnum - 2
566-
return 0
568+
return -1
567569
endif
568570
let pos = getpos('.')
569571
let view = winsaveview()
@@ -572,14 +574,17 @@ function! s:unindent_after_parenthesis(line, column) abort
572574
let begin = getpos('.')
573575
call setpos('.', pos)
574576
call winrestview(view)
577+
if v:lnum - 1 == begin[1]
578+
return -1
579+
endif
575580
if getline(begin[1]) =~# '\v<deriving>'
576581
let i = begin[1]
577582
while i
578583
let line = getline(i)
579584
if getline(i) =~# '\v<data>'
580585
return match(line, '\v<data>')
581586
elseif line =~# '^\S'
582-
return -1
587+
return 0
583588
endif
584589
let i -= 1
585590
endwhile

test/case/case_same_line.in.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
f x = case x of 1 -> 0
22
2 -> 1
3-
_ -> x
3+
_ -> (-x)
4+
g x = x

test/case/case_same_line.out.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
f x = case x of 1 -> 0
22
2 -> 1
3-
_ -> x
3+
_ -> (-x)
4+
g x = x

test/pragma/unpack.in.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
data T = T {-# UNPACK #-} !X
2-
{-# UNPACK #-} !X
2+
{-# UNPACK #-} !X

0 commit comments

Comments
 (0)