@@ -35,6 +35,12 @@ if !exists('g:purescript_indent_let')
3535 let g: purescript_indent_let = 4
3636endif
3737
38+ if ! exists (' g:purescript_indent_in' )
39+ " let x = 0
40+ " >in
41+ let g: purescript_indent_in = 1
42+ endif
43+
3844if ! 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
4854endif
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+
5064setlocal indentexpr = GetPurescriptIndent ()
51- setlocal indentkeys = ! ^F,o ,O,},= where,= in
65+ setlocal indentkeys = ! ^F,o ,O,},= where,= in , = ::, = - >, == >
5266
5367function ! 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
0 commit comments