@@ -42,8 +42,9 @@ if !exists('g:purescript_indent_in')
4242endif
4343
4444if ! exists (' g:purescript_indent_where' )
45- " where f :: Int -> Int
46- " >>>>>>f x = x
45+ " where
46+ " >>f :: Int -> Int
47+ " >>f x = x
4748 let g: purescript_indent_where = 6
4849endif
4950
@@ -62,7 +63,11 @@ if !exists('g:purescript_indent_dot')
6263endif
6364
6465setlocal indentexpr = GetPurescriptIndent ()
65- setlocal indentkeys = ! ^F,o ,O,},= where,= in ,= ::,= - >,== >
66+ setlocal indentkeys = ! ^F,o ,O,},= where,= in ,= ::,= - >,= →,== >,= ⇒
67+
68+ function ! s: GetSynStack (lnum, col )
69+ return map (synstack (a: lnum , a: col ), { key , val - > synIDattr (val, " name" ) })
70+ endfunction
6671
6772function ! s: GetSynStack (lnum, col )
6873 return map (synstack (a: lnum , a: col ), { key , val - > synIDattr (val, " name" ) })
@@ -74,8 +79,8 @@ function! GetPurescriptIndent()
7479 let line = getline (v: lnum )
7580
7681 if line = ~ ' ^\s*\<where\>'
77- let s = match (prevline, ' \S ' )
78- return s + &l: shiftwidth
82+ let s = indent ( v: lnum - 1 )
83+ return max ([ s , &l: shiftwidth])
7984 endif
8085
8186 if line = ~ ' ^\s*\<in\>'
@@ -100,7 +105,7 @@ function! GetPurescriptIndent()
100105 return s
101106 endif
102107
103- if prevline = ~ ' ^\S.*::' && line !~ ' ^\s*\(\.\|->\|=> \)' && !~ ' ^instance'
108+ if prevline = ~ ' ^\S.*::' && line !~ ' ^\s*\(\.\|->\|→\|=>\|⇒ \)' && !~ ' ^instance'
104109 " f :: String
105110 " -> String
106111 return 0
@@ -113,10 +118,16 @@ function! GetPurescriptIndent()
113118 return s
114119 endif
115120
121+ let s = match (line , ' \%(\\.\{-}\)\@<=->' )
122+ if s >= 0
123+ " inline lambda
124+ return indent (v: lnum )
125+ endif
126+
116127 " indent rules for -> (lambdas and case expressions)
117128 let s = match (line , ' ->' )
118129 " protect that we are not in a type signature
119- if s >= 0 && prevline !~ ' ^\s*\(->\|=>\|::\|\.\) '
130+ if s >= 0 && index ( s: GetSynStack ( s == 0 ? v: lnum - 1 : v: lnum , max ([ 1 , s ])), " purescriptFunctionDecl " ) == -1
120131 let p = match (prevline, ' \\' )
121132 if p >= 0 && index (s: GetSynStack (v: lnum - 1 , p ), " purescriptString" ) == -1
122133 return p
@@ -134,25 +145,25 @@ function! GetPurescriptIndent()
134145 return 0
135146 endif
136147
137- if line = ~ ' ^\s*:: '
148+ if line = ~ ' ^\s*\%(::\|∷\) '
138149 return match (prevline, ' \S' ) + &l: shiftwidth
139150 endif
140151
141- if prevline = ~ ' ^\s*:: \s*forall'
152+ if prevline = ~ ' ^\s*\(::\|∷\) \s*forall'
142153 return match (prevline, ' \S' ) + g: purescript_indent_dot
143154 endif
144155
145- let s = match (prevline, ' ^\s*\zs\%(::\|=>\|-> \)' )
156+ let s = match (prevline, ' ^\s*\zs\%(::\|∷\| =>\|⇒\|->\|→ \)' )
146157 let r = match (prevline, ' ^\s*\zs\.' )
147158 if s >= 0 || r >= 0
148159 if s >= 0
149- if line !~ ' ^\s*\%(::\|=>\|->\) '
160+ if line !~ ' ^\s*\%(::\|∷\| =>\|⇒\| ->\|→\) ' && line !~ ' ^\s*$ '
150161 return s - 2
151162 else
152163 return s
153164 endif
154165 elseif r >= 0
155- if line !~ ' ^\s\%(::\|=>\|-> \)'
166+ if line !~ ' ^\s\%(::\|∷\| =>\|⇒\|->\|→ \)'
156167 return r - g: purescript_indent_dot
157168 else
158169 return r
@@ -207,7 +218,7 @@ function! GetPurescriptIndent()
207218 endif
208219 endif
209220
210- let s = match (prevline, ' \(\<where\>\|\<do\>\|=\) \s*$' )
221+ let s = match (prevline, ' = \s*$' )
211222 if s >= 0 && index (s: GetSynStack (v: lnum - 1 , s ), ' purescriptString' ) == -1
212223 return match (prevline, ' \S' ) + &l: shiftwidth
213224 endif
@@ -217,14 +228,24 @@ function! GetPurescriptIndent()
217228 return match (prevline, ' \S' ) + (line !~ ' ^\s*[})]]' ? 0 : &l: shiftwidth )
218229 endif
219230
220- let s = match (prevline, ' \<where\>\s\+\S\+. *$' )
231+ let s = match (prevline, ' \<where\>\s*$' )
221232 if s >= 0 && index (s: GetSynStack (v: lnum - 1 , s ), ' purescriptString' ) == -1
222- return match (prevline, ' \<where\> ' ) + g: purescript_indent_where
233+ return match (prevline, ' \S ' ) + g: purescript_indent_where
223234 endif
224235
225- let s = match (prevline, ' \<do \>\s\+\S\+.*$' )
236+ let s = match (prevline, ' \<where \>\s\+\zs \S\+.*$' )
226237 if s >= 0 && index (s: GetSynStack (v: lnum - 1 , s ), ' purescriptString' ) == -1
227- return match (prevline, ' \<do\>' ) + g: purescript_indent_do
238+ return s
239+ endif
240+
241+ let s = match (prevline, ' \<do\>\s*$' )
242+ if s >= 0 && index (s: GetSynStack (v: lnum - 1 , s ), ' purescriptString' ) == -1
243+ return s + g: purescript_indent_do
244+ endif
245+
246+ let s = match (prevline, ' \<do\>\s\+\zs\S\+.*$' )
247+ if s >= 0 && index (s: GetSynStack (v: lnum - 1 , s ), ' purescriptString' ) == -1
248+ return s
228249 endif
229250
230251 let s = match (prevline, ' ^\s*\<data\>\s\+[^=]\+\s\+=\s\+\S\+.*$' )
0 commit comments