2
2
" Filename: indent/haskell.vim
3
3
" Author: itchyny
4
4
" License: MIT License
5
- " Last Change: 2024/08/04 15:46:49 .
5
+ " Last Change: 2024/11/01 20:51:18 .
6
6
" =============================================================================
7
7
8
8
if exists (' b:did_indent' )
@@ -110,32 +110,6 @@ function! GetHaskellIndent() abort
110
110
return match (nonblankline, ' ^\s*\zs--' )
111
111
endif
112
112
113
- if nonblankline = ~# ' \v^\s*}?' . noparen . ' [([{]' . noparen . ' [-+/*\$&<>,]?\s*%(--.*)?$'
114
- if nonblankline = ~# ' \v[([{]\s*%(--.*)?$'
115
- return match (nonblankline, ' \v^\s*%(<where>|.*<let>)?\s*\zs' ) + &shiftwidth
116
- elseif nonblankline = ~# ' \v[-+/*\$&<>,]\s*%(--.*)?$'
117
- return match (nonblankline, ' \v^\s*}?' . noparen . ' %(\[.*\|\s*\zs|[([{]\s*\zs)' )
118
- elseif nonblankline = ~# ' \v^[^[\]]*\[([^[\]]*|\[[^[\]]*\])*\|%([^[\]]*|\[[^[\]]*\])*\s*%(--.*)?$'
119
- return match (nonblankline, ' \v^[^[\]]*\[%([^[\]]*|\[[^[\]]*\])*\zs\|' )
120
- else
121
- return match (nonblankline, ' \v^\s*}?' . noparen . ' \zs[([{]' )
122
- endif
123
- endif
124
-
125
- " (
126
- if getline (v: lnum ) = ~# ' \v^\s*\('
127
- let lnum = s: prevnonblank (v: lnum - 1 )
128
- if lnum == 0
129
- return -1
130
- elseif nonblankline = ~# ' \v^\s*%(<where>|.*<let>).*%([-+/*\$&<>=,]+|`\k+`)\s*%(--.*)?$'
131
- return match (nonblankline, ' \v^\s*<%(where|let)>\s*\zs' ) + &shiftwidth
132
- elseif nonblankline = ~# ' \v^\s*<%(where|let)>'
133
- return match (nonblankline, ' \v^\s*%(<where>|<let>)?\s*\zs' )
134
- elseif nonblankline = ~# ' \v^\s*<import>'
135
- return indent (lnum) + &shiftwidth
136
- endif
137
- endif
138
-
139
113
if nonblankline = ~# ' \v^\s*<infix[rl]?>'
140
114
return match (nonblankline, ' \S' )
141
115
endif
@@ -152,10 +126,6 @@ function! GetHaskellIndent() abort
152
126
return match (nonblankline, ' \v<do>\s*\zs\S' )
153
127
endif
154
128
155
- if nonblankline = ~# ' \v<deriving>'
156
- return s: indent (' ' , ' \v^\s*\zs<data>' , 0 )
157
- endif
158
-
159
129
if line = ~# ' \v<if>' && line !~# ' \v^\s*#'
160
130
if line !~# ' \v<then>'
161
131
return match (line , ' \v.*<if>\s*\zs' )
@@ -172,7 +142,7 @@ function! GetHaskellIndent() abort
172
142
return indent (s: prevnonblank (v: lnum - 1 )) + &shiftwidth
173
143
endif
174
144
else
175
- return line = ~# ' \v<case>.*<of>\s*[[:alnum:](] '
145
+ return line = ~# ' \v<case>.*<of>\s*( [[:alnum:](\" '' \[]|-\d) '
176
146
\ ? match (line , ' \v<case>.*<of>\s*\zs\S' )
177
147
\ : match (line , ' \v.*<case>\s*\zs' )
178
148
endif
@@ -186,6 +156,36 @@ function! GetHaskellIndent() abort
186
156
return match (line , ' \v\\\s*<case>\s*\zs\S' )
187
157
endif
188
158
159
+ if nonblankline = ~# ' \v^\s*}?' . noparen . ' [([{]' . noparen . ' [-+/*\$&<>,]?\s*%(--.*)?$'
160
+ if nonblankline = ~# ' \v[([{]\s*%(--.*)?$'
161
+ return match (nonblankline, ' \v^\s*%(<where>|.*<let>)?\s*\zs' ) + &shiftwidth
162
+ elseif nonblankline = ~# ' \v[-+/*\$&<>,]\s*%(--.*)?$'
163
+ return match (nonblankline, ' \v^\s*}?' . noparen . ' %(\[.*\|\s*\zs|[([{]\s*\zs)' )
164
+ elseif nonblankline = ~# ' \v^[^[\]]*\[([^[\]]*|\[[^[\]]*\])*\|%([^[\]]*|\[[^[\]]*\])*\s*%(--.*)?$'
165
+ return match (nonblankline, ' \v^[^[\]]*\[%([^[\]]*|\[[^[\]]*\])*\zs\|' )
166
+ else
167
+ return match (nonblankline, ' \v^\s*}?' . noparen . ' \zs[([{]' )
168
+ endif
169
+ endif
170
+
171
+ " (
172
+ if getline (v: lnum ) = ~# ' \v^\s*\('
173
+ let lnum = s: prevnonblank (v: lnum - 1 )
174
+ if lnum == 0
175
+ return -1
176
+ elseif nonblankline = ~# ' \v^\s*%(<where>|.*<let>).*%([-+/*\$&<>=,]+|`\k+`)\s*%(--.*)?$'
177
+ return match (nonblankline, ' \v^\s*<%(where|let)>\s*\zs' ) + &shiftwidth
178
+ elseif nonblankline = ~# ' \v^\s*<%(where|let)>'
179
+ return match (nonblankline, ' \v^\s*%(<where>|<let>)?\s*\zs' )
180
+ elseif nonblankline = ~# ' \v^\s*<import>'
181
+ return indent (lnum) + &shiftwidth
182
+ endif
183
+ endif
184
+
185
+ if nonblankline = ~# ' \v<deriving>'
186
+ return s: indent (' ' , ' \v^\s*\zs<data>' , 0 )
187
+ endif
188
+
189
189
if nonblankline = ~# ' \v^.*[^|]\|[^|].*\='
190
190
return s: after_guard ()
191
191
endif
0 commit comments