Skip to content

Commit f8f584e

Browse files
author
Coot
authored
Merge pull request #42 from coot/indent-if-then-else
issue #33: indent if-then-else
2 parents e637c49 + 26c5968 commit f8f584e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

indent/purescript.vim

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ if !exists('g:purescript_indent_dot')
6363
endif
6464

6565
setlocal indentexpr=GetPurescriptIndent()
66-
setlocal indentkeys=!^F,o,O,},=where,=in,=::,=->,=→,==>,=
66+
setlocal indentkeys=!^F,o,O,},=where,=in,=::,=->,=→,==>,=,=else
6767

6868
function! s:GetSynStack(lnum, col)
6969
return map(synstack(a:lnum, a:col), { key, val -> synIDattr(val, "name") })
@@ -199,17 +199,18 @@ function! GetPurescriptIndent()
199199
return match(prevline, '\<let\>') + g:purescript_indent_let
200200
endif
201201

202-
let s = match(prevline, '\<else\>')
203-
if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1
204-
let s = match(prevline, '\<if\>.*\&.*\zs\<then\>')
205-
if s > 0
206-
return s
202+
let s = searchpairpos('\%(--.\{-}\)\@<!\<if\>', '\<then\>', '\<else\>.*\zs$', 'bnrc')[0]
203+
if s > 0
204+
" this rule ensures that using `=` in visual mode will correctly indent
205+
" `if then else`, but it does not handle lines after `then` and `else`
206+
if line =~ '\<\%(then\|else\)\>'
207+
return match(getline(s), '\<if\>') + &l:shiftwidth
207208
endif
209+
endif
208210

209-
let s = match(prevline, '\<if\>')
210-
if s > 0
211-
return s + g:purescript_indent_if
212-
endif
211+
let p = match(prevline, '\<if\>\%(.\{-}\<then\>.\{-}\<else\>\)\@!')
212+
if p > 0
213+
return p + &l:shiftwidth
213214
endif
214215

215216
let s = match(prevline, '=\s*$')

0 commit comments

Comments
 (0)