Skip to content

Commit 6ad5ed9

Browse files
Merge pull request #18 from coot/indentation
Indentation and syntax changes.
2 parents 5688098 + fc0f613 commit 6ad5ed9

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

indent/purescript.vim

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ if !exists('g:purescript_indent_let')
3535
let g:purescript_indent_let = 4
3636
endif
3737

38+
if !exists('g:purescript_indent_in')
39+
" let x = 0
40+
" >in
41+
let g:purescript_indent_in = 1
42+
endif
43+
3844
if !exists('g:purescript_indent_where')
3945
" where f :: Int -> Int
4046
" >>>>>>f x = x
@@ -47,16 +53,24 @@ if !exists('g:purescript_indent_do')
4753
let g:purescript_indent_do = 3
4854
endif
4955

56+
if !exists('g:purescript_indent_dot')
57+
" f
58+
" :: forall a
59+
" >. String
60+
" -> String
61+
let g:purescript_indent_dot = 1
62+
endif
63+
5064
setlocal indentexpr=GetPurescriptIndent()
51-
setlocal indentkeys=!^F,o,O,},=where,=in
65+
setlocal indentkeys=!^F,o,O,},=where,=in,=::,=->,==>
5266

5367
function! GetPurescriptIndent()
5468
let prevline = getline(v:lnum - 1)
5569
let line = getline(v:lnum)
5670

5771
if line =~ '^\s*\<where\>'
5872
let s = match(prevline, '\S')
59-
return s + 2
73+
return s + &shiftwidth
6074
endif
6175

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

71-
return s + 1
85+
return s + g:purescript_indent_in
86+
endif
87+
88+
let s = match(prevline, '^\s*\zs\(--\|import\>\)')
89+
if s >= 0
90+
return s
91+
endif
92+
93+
if prevline =~ '^\S'
94+
" starting type signature or function body on next line
95+
echom "xxx " . prevline
96+
return &shiftwidth
97+
endif
98+
99+
if line =~ '^\s*::'
100+
return match(prevline, '\S') + &shiftwidth
101+
endif
102+
103+
if prevline =~ '^\s*::\s*forall'
104+
return match(prevline, '\S') + g:purescript_indent_dot
105+
endif
106+
107+
let s = match(prevline, '^\s*\zs\%(::\|=>\|->\)')
108+
let r = match(prevline, '^\s*\zs\.')
109+
if s >= 0 || r >= 0
110+
echom prevline
111+
if s >= 0
112+
if line !~ '^\s*\%(::\|=>\|->\)'
113+
return s - 2
114+
else
115+
return s
116+
endif
117+
elseif r >= 0
118+
if line !~ '^\s\%(::\|=>\|->\)'
119+
return r - g:purescript_indent_dot
120+
else
121+
return r
122+
endif
123+
endif
72124
endif
73125

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

80-
let s = match(prevline, ':')
132+
let s = match(prevline, '\<:\>')
81133
if s > 0
82-
return s + 3
134+
return s + &shiftwidth
83135
else
84-
return match(prevline, '\S')
136+
return match(prevline, '\S') + &shiftwidth
85137
endif
86138
endif
87139

@@ -105,10 +157,14 @@ function! GetPurescriptIndent()
105157
endif
106158
endif
107159

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

164+
if prevline =~ '[{([]\s*$'
165+
return match(prevline, '\S') + (line !~ '^\s*[})]]' ? 0 : &shiftwidth)
166+
endif
167+
112168
if prevline =~ '\<where\>\s\+\S\+.*$'
113169
return match(prevline, '\<where\>') + g:purescript_indent_where
114170
endif

syntax/purescript.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ syn match purescriptForall "∀"
7474
syn keyword purescriptConditional if then else
7575
syn keyword purescriptStatement do case of let in
7676
syn keyword purescriptWhere where
77-
syn match purescriptStructure "\<\(data\|newtype\|type\|class\)\>"
77+
syn match purescriptStructure "\<\(data\|newtype\|type\|class\|kind\)\>"
7878
\ nextgroup=purescriptType skipwhite
7979
syn keyword purescriptStructure derive
8080
syn keyword purescriptStructure instance

0 commit comments

Comments
 (0)