Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #33: indent if-then-else #42

Merged
merged 1 commit into from
Aug 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions indent/purescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if !exists('g:purescript_indent_dot')
endif

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

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

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

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

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