Skip to content

Commit 517d9de

Browse files
author
Coot
authored
Indent (#44)
* indent class and remove '|' from operator characters If '|' was included then there is extra indent in ``` class RowLacking (entry :: Type) (key :: Symbol) (typ :: Type) (row :: # Type) | >> entry typ -> key row ``` * indent pattern guards * guard against class * if the previous line contains `| otherwise` find the first line that does not start with `|` (actually find the first line that starts with `\k`, '^\%(\s*|\)\@!' did not work inside indent function for some reason.
1 parent 26ffc81 commit 517d9de

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

indent/purescript.vim

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ function! GetPurescriptIndent()
108108
endif
109109

110110
let s = match(prevline, '[[:alnum:][:blank:]]\@<=|[[:alnum:][:blank:]$]')
111-
if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), "purescriptFunctionDecl") == -1
112-
" ident pattern quards but not if we are in a type declaration
111+
if s >= 0 && prevline !~ '^class\>' && index(s:GetSynStack(v:lnum - 1, s), "purescriptFunctionDecl") == -1
112+
" ident pattern guards but not if we are in a type declaration
113113
" what we detect using syntax groups
114-
return s
114+
if prevline =~ '|\s*otherwise\>'
115+
return indent(search('^\s*\k', 'bnW'))
116+
" somehow this pattern does not work :/
117+
" return indent(search('^\(\s*|\)\@!', 'bnW'))
118+
else
119+
return s
120+
endif
115121
endif
116122

117123
let s = match(line, '\%(\\.\{-}\)\@<=->')
@@ -165,10 +171,10 @@ function! GetPurescriptIndent()
165171
endif
166172
endif
167173

168-
if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
174+
if prevline =~ '[!#$%&*+./<>?@\\^~-]\s*$'
169175
let s = match(prevline, '=')
170176
if s > 0
171-
return s + 2
177+
return s + &l:shiftwidth
172178
endif
173179

174180
let s = match(prevline, '\<:\>')
@@ -223,6 +229,10 @@ function! GetPurescriptIndent()
223229
return match(prevline, '\S') + (line !~ '^\s*[})]]' ? 0 : &l:shiftwidth)
224230
endif
225231

232+
if prevline =~ '^class'
233+
return &l:shiftwidth
234+
endif
235+
226236
let s = match(prevline, '\<where\>\s*$')
227237
if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1
228238
return match(prevline, '\S') + g:purescript_indent_where

0 commit comments

Comments
 (0)