Skip to content
Merged
Show file tree
Hide file tree
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
70 changes: 63 additions & 7 deletions indent/purescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ if !exists('g:purescript_indent_let')
let g:purescript_indent_let = 4
endif

if !exists('g:purescript_indent_in')
" let x = 0
" >in
let g:purescript_indent_in = 1
endif

if !exists('g:purescript_indent_where')
" where f :: Int -> Int
" >>>>>>f x = x
Expand All @@ -47,16 +53,24 @@ if !exists('g:purescript_indent_do')
let g:purescript_indent_do = 3
endif

if !exists('g:purescript_indent_dot')
" f
" :: forall a
" >. String
" -> String
let g:purescript_indent_dot = 1
endif

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

function! GetPurescriptIndent()
let prevline = getline(v:lnum - 1)
let line = getline(v:lnum)

if line =~ '^\s*\<where\>'
let s = match(prevline, '\S')
return s + 2
return s + &shiftwidth
endif

if line =~ '^\s*\<in\>'
Expand All @@ -68,7 +82,45 @@ function! GetPurescriptIndent()
let s = match(getline(n),'\<let\>')
endwhile

return s + 1
return s + g:purescript_indent_in
endif

let s = match(prevline, '^\s*\zs\(--\|import\>\)')
if s >= 0
return s
endif

if prevline =~ '^\S'
" starting type signature or function body on next line
echom "xxx " . prevline
return &shiftwidth
endif

if line =~ '^\s*::'
return match(prevline, '\S') + &shiftwidth
endif

if prevline =~ '^\s*::\s*forall'
return match(prevline, '\S') + g:purescript_indent_dot
endif

let s = match(prevline, '^\s*\zs\%(::\|=>\|->\)')
let r = match(prevline, '^\s*\zs\.')
if s >= 0 || r >= 0
echom prevline
if s >= 0
if line !~ '^\s*\%(::\|=>\|->\)'
return s - 2
else
return s
endif
elseif r >= 0
if line !~ '^\s\%(::\|=>\|->\)'
return r - g:purescript_indent_dot
else
return r
endif
endif
endif

if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
Expand All @@ -77,11 +129,11 @@ function! GetPurescriptIndent()
return s + 2
endif

let s = match(prevline, ':')
let s = match(prevline, '\<:\>')
if s > 0
return s + 3
return s + &shiftwidth
else
return match(prevline, '\S')
return match(prevline, '\S') + &shiftwidth
endif
endif

Expand All @@ -105,10 +157,14 @@ function! GetPurescriptIndent()
endif
endif

if prevline =~ '\(\<where\>\|\<do\>\|=\|[{([]\)\s*$'
if prevline =~ '\(\<where\>\|\<do\>\|=\)\s*$'
return match(prevline, '\S') + &shiftwidth
endif

if prevline =~ '[{([]\s*$'
return match(prevline, '\S') + (line !~ '^\s*[})]]' ? 0 : &shiftwidth)
endif

if prevline =~ '\<where\>\s\+\S\+.*$'
return match(prevline, '\<where\>') + g:purescript_indent_where
endif
Expand Down
2 changes: 1 addition & 1 deletion syntax/purescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ syn match purescriptForall "∀"
syn keyword purescriptConditional if then else
syn keyword purescriptStatement do case of let in
syn keyword purescriptWhere where
syn match purescriptStructure "\<\(data\|newtype\|type\|class\)\>"
syn match purescriptStructure "\<\(data\|newtype\|type\|class\|kind\)\>"
\ nextgroup=purescriptType skipwhite
syn keyword purescriptStructure derive
syn keyword purescriptStructure instance
Expand Down