Ok. figured it out by looking into haskell.vim, I found ad slight modification of indentexpr
would work.
check it out.
first,
$ cd ~/.vim/bundle/haskell-vim/
$ vi indent/haskell.vim
then find the definition of GetHaskellIndent
function.
I add following lines right after the handling of --
comment, therefore the function becomes:
function! GetHaskellIndent()
let l:prevline = getline(v:lnum - 1)
if l:prevline =~ '^\s*--'
return match(l:prevline, '\S')
endif
if synIDattr(synID(line("."), col("."), 1), "name") == 'hsBlockComment'
for l:c in range(v:lnum - 1, 0, -1)
let l:bline = getline(l:c)
if l:bline =~ '{-'
return 1 + match(l:bline, '{-')
endfor
return 1
endif
starting from if synIDattr(synID(line("."), ...
is my code.
basically what it means is check whether the current position is in block comment syntax, if so, get in the for loop and find the first occurrence of {-
, then return the indent as deep as the -
in {-
.
notice that, my haskell environment is heavily customized. you should config according to yours. though my indent is setup to use haskell.vim
, my syntax highlight is setup to use vim2hs
. so it's better to look into the syntax highlight file first to find out what syntax element you should look at(in vim2hs
's case, it should be 'hsBlockComment'
, in haskell.vim
it should be 'haskellBlockComment'
).
after having this code, I have following effect:
{-
-
-
- -}
for comments in deep indent:
{-
-
-
-
-
- -}
works like a charm.