Skip to content

Commit 5a7a305

Browse files
committed
use non-capturing group for all regular expressions
1 parent 3eef84f commit 5a7a305

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

indent/haskell.vim

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Filename: indent/haskell.vim
33
" Author: itchyny
44
" License: MIT License
5-
" Last Change: 2023/11/05 19:52:08.
5+
" Last Change: 2023/11/06 08:17:59.
66
" =============================================================================
77

88
if exists('b:did_indent')
@@ -30,7 +30,7 @@ function! GetHaskellIndent() abort
3030
endif
3131

3232
" #if, #else, #endif, #include
33-
if line =~# '\v^\s*(#$|#\s*\w+)'
33+
if line =~# '\v^\s*%(#$|#\s*\w+)'
3434
return 0
3535
endif
3636

@@ -51,7 +51,7 @@ function! GetHaskellIndent() abort
5151
endif
5252

5353
" class, instance
54-
if line =~# '\v^\s*<(class|instance)>'
54+
if line =~# '\v^\s*<%(class|instance)>'
5555
return 0
5656
endif
5757

@@ -87,7 +87,7 @@ function! GetHaskellIndent() abort
8787
let nonblankline = getline(s:prevnonblank(v:lnum - 1))
8888

8989
" data, type
90-
if line =~# '\v^\s*<(data|type)>' && nonblankline !~# '\v<(class|instance)>.*<where>'
90+
if line =~# '\v^\s*<%(data|type)>' && nonblankline !~# '\v<%(class|instance)>.*<where>'
9191
return 0
9292
endif
9393

@@ -112,11 +112,11 @@ function! GetHaskellIndent() abort
112112

113113
if nonblankline =~# '\v^\s*}?' . noparen . '[([{]' . noparen . '[-+/*\$&<>,]?\s*%(--.*)?$'
114114
if nonblankline =~# '\v[([{]\s*%(--.*)?$'
115-
return match(nonblankline, '\v^\s*(<where>|.*<let>)?\s*\zs') + &shiftwidth
115+
return match(nonblankline, '\v^\s*%(<where>|.*<let>)?\s*\zs') + &shiftwidth
116116
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\|')
117+
return match(nonblankline, '\v^\s*}?' . noparen . '%(\[.*\|\s*\zs|[([{]\s*\zs)')
118+
elseif nonblankline =~# '\v^[^[\]]*\[([^[\]]*|\[[^[\]]*\])*\|%([^[\]]*|\[[^[\]]*\])*\s*%(--.*)?$'
119+
return match(nonblankline, '\v^[^[\]]*\[%([^[\]]*|\[[^[\]]*\])*\zs\|')
120120
else
121121
return match(nonblankline, '\v^\s*}?' . noparen . '\zs[([{]')
122122
endif
@@ -127,10 +127,10 @@ function! GetHaskellIndent() abort
127127
let lnum = s:prevnonblank(v:lnum - 1)
128128
if lnum == 0
129129
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')
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')
134134
elseif nonblankline =~# '\v^\s*<import>'
135135
return indent(lnum) + &shiftwidth
136136
endif
@@ -145,7 +145,7 @@ function! GetHaskellIndent() abort
145145
endif
146146

147147
if nonblankline =~# '\v<do>\s*%(--.*)?$'
148-
return match(nonblankline, '\v^\s*(<where>|.*<let>)?\s*\zs') + &shiftwidth
148+
return match(nonblankline, '\v^\s*%(<where>|.*<let>)?\s*\zs') + &shiftwidth
149149
endif
150150

151151
if nonblankline =~# '\v<deriving>'
@@ -163,7 +163,7 @@ function! GetHaskellIndent() abort
163163
if line =~# '\v<case>.*<of>.*\s*%(--.*)?$' && line !~# '^\s*#'
164164
if get(g:, 'haskell_indent_disable_case', 0)
165165
if line =~# '\v^\s*<where>'
166-
return match(line, '\v^\s*(<where>)?\s*\zs') + &shiftwidth
166+
return match(line, '\v^\s*%(<where>)?\s*\zs') + &shiftwidth
167167
else
168168
return indent(s:prevnonblank(v:lnum - 1)) + &shiftwidth
169169
endif
@@ -175,7 +175,7 @@ function! GetHaskellIndent() abort
175175
endif
176176

177177
if line =~# '\v\\case\s*%(--.*)?$'
178-
return match(line, '\v^\s*(<where>|.*<let>)?\s*\zs') + &shiftwidth
178+
return match(line, '\v^\s*%(<where>|.*<let>)?\s*\zs') + &shiftwidth
179179
endif
180180

181181
if nonblankline =~# '\v^.*[^|]\|[^|].*\='
@@ -194,8 +194,8 @@ function! GetHaskellIndent() abort
194194
if nonblankline =~# '\v^\s*<let>.*,\s*%(--.*)?$'
195195
return match(nonblankline, '\S')
196196
else
197-
return match(nonblankline, '\v^\s*(<where>|.*<let>)?\s*\zs') +
198-
\ (nonblankline =~# '\v(<where>|<let>)|^\s*\k+\s*'. noparen .'\=.*([-+/*\$&<>]|`\k+`)\s*%(--.*)?$|(\=|-\>)\s*%(--.*)?$' ? &shiftwidth : 0)
197+
return match(nonblankline, '\v^\s*%(<where>|.*<let>)?\s*\zs') +
198+
\ (nonblankline =~# '\v%(<where>|<let>)|^\s*\k+\s*'. noparen .'\=.*%([-+/*\$&<>]|`\k+`)\s*%(--.*)?$|%(\=|-\>)\s*%(--.*)?$' ? &shiftwidth : 0)
199199
endif
200200
endif
201201

@@ -227,7 +227,7 @@ function! GetHaskellIndent() abort
227227
while i
228228
let line = getline(i)
229229
if getline(i) =~# '\v<case>'
230-
return match(line, '\v^\s*(where\s+)?\zs')
230+
return match(line, '\v^\s*%(where\s+)?\zs')
231231
endif
232232
let i -= 1
233233
endwhile
@@ -241,7 +241,7 @@ function! GetHaskellIndent() abort
241241
endif
242242

243243
if nonblankline =~# '\v<let>\s+.*\=' && nonblankline !~# '\v<let>\s+.*\=.*<in>'
244-
return s:indent('', getline(v:lnum) =~# '\v^\s*(<in>|\S+\s*\=)' ? '\v<let>\s+\zs\S' : '\v<let>', 0)
244+
return s:indent('', getline(v:lnum) =~# '\v^\s*%(<in>|\S+\s*\=)' ? '\v<let>\s+\zs\S' : '\v<let>', 0)
245245
endif
246246

247247
" in
@@ -274,8 +274,8 @@ function! GetHaskellIndent() abort
274274
if 0 <= indent(i) && indent(i) < indent && line !~# '\v<where>|^\s*\||^$'
275275
return line =~# '\v^\s*[([{]' ? indent : indent(i)
276276
endif
277-
if line =~# '\v^\s*<(class|instance)>' && found_where
278-
return match(line, '\v^\s*<(class|instance)>') + &shiftwidth
277+
if line =~# '\v^\s*<%(class|instance)>' && found_where
278+
return match(line, '\v^\s*<%(class|instance)>') + &shiftwidth
279279
elseif line =~# '^\S'
280280
return 0
281281
endif
@@ -331,7 +331,7 @@ function! s:in_comment() abort
331331
if getline(v:lnum) =~# '^\s*--'
332332
return 1
333333
endif
334-
let start = searchpos('\v(--.*)@<!\{-', 'bcnW')
334+
let start = searchpos('\v%(--.*)@<!\{-', 'bcnW')
335335
let pos = getpos('.')
336336
let end = searchpos('-}', 'bcnW')
337337
return start != [0, 0] && (start[0] < pos[1] || start[0] == pos[1] && start[1] <= pos[2])
@@ -343,20 +343,20 @@ function! s:indent_comment() abort
343343
if getline(s:prevnonblank(v:lnum - 1)) =~# '\v\{-#\s*UNPACK\s*#-}' && getline(v:lnum) =~# '\v^\s*\{-#\s*UNPACK\s*#-}'
344344
return match(getline(s:prevnonblank(v:lnum - 1)), '\v\{-#\s*UNPACK\s*#-}')
345345
elseif getline(v:lnum) =~# '\v^\s*\{-#\s*<RULES>\s*%(--.*)?$'
346-
let name = matchstr(getline(v:lnum + 1), '\v^\s*"\zs\k+\ze(/\k+)*"')
346+
let name = matchstr(getline(v:lnum + 1), '\v^\s*"\zs\k+\ze%(/\k+)*"')
347347
if name !=# ''
348348
let i = v:lnum - 1
349349
while i
350-
if getline(i) =~# '\v^\s*(where\s+)?<' . name . '>.*\='
351-
return match(getline(i), '\v^\s*(<where>)?\s*\zs')
350+
if getline(i) =~# '\v^\s*%(where\s+)?<' . name . '>.*\='
351+
return match(getline(i), '\v^\s*%(<where>)?\s*\zs')
352352
endif
353353
let i -= 1
354354
endwhile
355355
endif
356356
endif
357-
if getline(v:lnum) =~# '\v^\s*\{-#\s*<(INLINE|RULES)>'
357+
if getline(v:lnum) =~# '\v^\s*\{-#\s*<%(INLINE|RULES)>'
358358
return -1
359-
elseif getline(v:lnum) =~# '\v^\s*(\{- \||\{-#.*#-}\s*%(--.*)?$|-- -{10,})'
359+
elseif getline(v:lnum) =~# '\v^\s*%(\{- \||\{-#.*#-}\s*%(--.*)?$|-- -{10,})'
360360
return 0
361361
endif
362362
if getline(v:lnum) =~# '^\s*[-{]-'
@@ -365,7 +365,7 @@ function! s:indent_comment() abort
365365
while i <= line('$') && (getline(i) =~# '^\s*--' || getline(i) ==# '')
366366
let i += 1
367367
endwhile
368-
if getline(i) =~# '\v^\s*<(class|instance|data)>|::.*(-\>|-- *\^)'
368+
if getline(i) =~# '\v^\s*<%(class|instance|data)>|::.*%(-\>|-- *\^)'
369369
return match(getline(i), '^\s*\zs\S')
370370
endif
371371
endif
@@ -376,7 +376,7 @@ function! s:indent_comment() abort
376376
let indent = indent(i)
377377
if line =~# '^\s*[-{]-'
378378
return indent
379-
elseif line =~# '\v^\s*<(class|instance)>|^\s*<where>\s*%(--.*)?$' && line !~# '\v,\s*%(--.*)?$'
379+
elseif line =~# '\v^\s*<%(class|instance)>|^\s*<where>\s*%(--.*)?$' && line !~# '\v,\s*%(--.*)?$'
380380
return indent + &shiftwidth
381381
elseif line =~# '\v\s*\(\s*%(--.*)?$'
382382
return previndent ? previndent : indent + &shiftwidth
@@ -387,7 +387,7 @@ function! s:indent_comment() abort
387387
let i -= 1
388388
endwhile
389389
endif
390-
let listpattern = '\v^\s*(\* \@|[a-z]\)\s+|\>\s+)'
390+
let listpattern = '\v^\s*%(\* \@|[a-z]\)\s+|\>\s+)'
391391
if getline(v:lnum) =~# listpattern
392392
if getline(s:prevnonblank(v:lnum - 1)) =~# listpattern
393393
return indent(s:prevnonblank(v:lnum - 1))
@@ -415,7 +415,7 @@ function! s:indent_comment() abort
415415
return 0
416416
endif
417417
let line = getline(s:prevnonblank(v:lnum - 1))
418-
if line =~# '\v^\s*\{-#\s*(\s+\w+,?)+'
418+
if line =~# '\v^\s*\{-#\s*%(\s+\w+,?)+'
419419
if line =~# '\v,\s*%(--.*)?$'
420420
return match(line, '\v\zs<\w+,')
421421
else
@@ -432,7 +432,7 @@ function! s:indent_comment() abort
432432
return indent(i) - &shiftwidth
433433
endif
434434
endif
435-
if getline(v:lnum) =~# '\v^\s*(#?-}|#$)'
435+
if getline(v:lnum) =~# '\v^\s*%(#?-}|#$)'
436436
let i = v:lnum - 1
437437
while 0 < i
438438
if getline(i) =~# '{-'
@@ -465,10 +465,10 @@ function! s:indent_bar() abort
465465
let indent = indent(i)
466466
while i > 0
467467
let line = getline(i)
468-
if line =~# '\v^[^[\]]*([^[\]]*|\[[^[\]]*\])*\[([^[\]]*|\[[^[\]]*\])*(--.*)?$'
469-
return match(line, '\v^[^[\]]*([^[\]]*|\[[^[\]]*\])*\zs\[([^[\]]*|\[[^[\]]*\])*(--.*)?$') + &shiftwidth
470-
elseif line =~# '\v^\s*(<where>)?.*[^|]\|[^|].*\='
471-
return match(line, '\v^\s*(<where>)?.*[^|]\zs\|[^|].*\=')
468+
if line =~# '\v^[^[\]]*%([^[\]]*|\[[^[\]]*\])*\[%([^[\]]*|\[[^[\]]*\])*%(--.*)?$'
469+
return match(line, '\v^[^[\]]*%([^[\]]*|\[[^[\]]*\])*\zs\[([^[\]]*|\[[^[\]]*\])*%(--.*)?$') + &shiftwidth
470+
elseif line =~# '\v^\s*%(<where>)?.*[^|]\|[^|].*\='
471+
return match(line, '\v^\s*%(<where>)?.*[^|]\zs\|[^|].*\=')
472472
elseif line =~# '\v<data>.*\='
473473
return match(line, '\v^.*<data>.*\zs\=')
474474
elseif line =~# '\v^\s*<where>\s*%(--.*)?$' && indent(i) < indent || line =~# '^\S'
@@ -501,20 +501,20 @@ function! s:after_guard() abort
501501
return 0
502502
endif
503503
if where_clause && line !~# '\v^\s*%(--.*)?$' && line !~# '\v^\s*\|[^|]'
504-
return match(line, '\v^\s*(<where>)?\s*\zs')
504+
return match(line, '\v^\s*%(<where>)?\s*\zs')
505505
endif
506506
if line =~# '\v<where>'
507507
let where_clause = 1
508508
endif
509509
let i -= 1
510510
endwhile
511511
endif
512-
if nonblankline =~# '\v[^|]\|\s*(otherwise|True|0\s*\<\s*1|1\s*\>\s*0)' || getline(v:lnum) =~# '^\s*\S'
512+
if nonblankline =~# '\v[^|]\|\s*%(otherwise|True|0\s*\<\s*1|1\s*\>\s*0)' || getline(v:lnum) =~# '^\s*\S'
513513
let i = s:prevnonblank(v:lnum - 1)
514514
while i
515515
let line = getline(i)
516516
if line !~# '\v^\s*%(--.*)?$' && line !~# '^\s*|'
517-
return match(line, '\v^\s*(<where>)?\s*\zs')
517+
return match(line, '\v^\s*%(<where>)?\s*\zs')
518518
endif
519519
let i -= 1
520520
endwhile
@@ -527,7 +527,7 @@ endfunction
527527

528528
" =
529529
function! s:indent_eq() abort
530-
return match(getline(s:prevnonblank(v:lnum - 1)), '\v^\s*(<where>|<let>)?\s*\zs') + &shiftwidth
530+
return match(getline(s:prevnonblank(v:lnum - 1)), '\v^\s*%(<where>|<let>)?\s*\zs') + &shiftwidth
531531
endfunction
532532

533533
" }, ], )
@@ -543,7 +543,7 @@ function! s:indent_parenthesis() abort
543543
return -1
544544
endif
545545
if indent(end[1] - 1) + 1 < begin[2]
546-
return match(getline(begin[1]), '\v^\s*(<where>|.*<let>)?\s*\zs')
546+
return match(getline(begin[1]), '\v^\s*%(<where>|.*<let>)?\s*\zs')
547547
endif
548548
if getline(end[1]) =~# '^\s*}' && getline(begin[1]) =~# '\v^\s+\w+\s*\{'
549549
return match(getline(begin[1]), '\v^\s+\zs')
@@ -576,13 +576,13 @@ function! s:unindent_after_parenthesis(line, column) abort
576576
let i -= 1
577577
endwhile
578578
elseif getline(begin[1]) =~# '^\s*='
579-
return match(getline(s:prevnonblank(begin[1] - 1)), '\v^\s*(<where>|<let>)?\s*\zs')
579+
return match(getline(s:prevnonblank(begin[1] - 1)), '\v^\s*%(<where>|<let>)?\s*\zs')
580580
elseif getline(s:prevnonblank(begin[1] - 1)) =~# '\v\=\s*%(--.*)?$'
581-
return match(getline(s:prevnonblank(begin[1] - 1)), '\v^\s*(<where>|<let>)?\s*\zs')
581+
return match(getline(s:prevnonblank(begin[1] - 1)), '\v^\s*%(<where>|<let>)?\s*\zs')
582582
elseif getline(s:prevnonblank(begin[1] - 1)) =~# '\v<import>'
583583
return 0
584584
endif
585-
return match(getline(begin[1]), '\v^\s*(<where>)?\s*\zs')
585+
return match(getline(begin[1]), '\v^\s*%(<where>)?\s*\zs')
586586
endfunction
587587

588588
" where
@@ -591,8 +591,8 @@ function! s:indent_where() abort
591591
let i = s:prevnonblank(v:lnum - 1)
592592
while i > 0
593593
let line = getline(i)
594-
if line =~# '\v^\s*(<where>)?\s*\zs\h.*\=|^\s*[^| ]'
595-
return match(line, '\v^\s*(<where>)?\s*\zs\h.*\=|^\s*[^| ]') + &shiftwidth
594+
if line =~# '\v^\s*%(<where>)?\s*\zs\h.*\=|^\s*[^| ]'
595+
return match(line, '\v^\s*%(<where>)?\s*\zs\h.*\=|^\s*[^| ]') + &shiftwidth
596596
elseif line =~# '^\S'
597597
return -1
598598
endif
@@ -605,20 +605,20 @@ function! s:indent_where() abort
605605
let begin = getpos('.')
606606
call setpos('.', pos)
607607
call winrestview(view)
608-
if getline(begin[1]) =~# '\v(<module>|<class>|<instance>)'
608+
if getline(begin[1]) =~# '\v<%(module|class|instance)>'
609609
return indent(begin[1]) + &shiftwidth
610-
elseif getline(s:prevnonblank(begin[1] - 1)) =~# '\v(<module>|<class>|<instance>)'
610+
elseif getline(s:prevnonblank(begin[1] - 1)) =~# '\v<%(module|class|instance)>'
611611
return indent(s:prevnonblank(begin[1] - 1)) + &shiftwidth
612-
elseif getline(begin[1]) =~# '\v^\s*\((--.*)?'
612+
elseif getline(begin[1]) =~# '\v^\s*\(%(--.*)?'
613613
return indent(begin[1])
614614
endif
615-
elseif getline(v:lnum) =~# '\v^\s*(<module>|<class>|<instance>)'
615+
elseif getline(v:lnum) =~# '\v^\s*<%(module|class|instance)>'
616616
return 0
617-
elseif getline(v:lnum) =~# '\v<where>\s*(--.*)?'
617+
elseif getline(v:lnum) =~# '\v<where>\s*%(--.*)?'
618618
let i = s:prevnonblank(v:lnum - 1)
619619
if i > 0
620620
let line = getline(i)
621-
if line =~# '\v^\s*(<module>|<class>|<instance>)'
621+
if line =~# '\v^\s*<%(module|class|instance)>'
622622
return indent(i) + &shiftwidth
623623
endif
624624
endif
@@ -637,7 +637,7 @@ function! s:after_where() abort
637637
call setpos('.', pos)
638638
call winrestview(view)
639639
let i = getline(begin[1]) =~# '^\s*(' ? s:prevnonblank(begin[1] - 1) : begin[1]
640-
if i > 0 && getline(i) =~# '\v(<module>|<class>|<instance>)'
640+
if i > 0 && getline(i) =~# '\v<%(module|class|instance)>'
641641
return 0
642642
endif
643643
endif
@@ -647,12 +647,12 @@ function! s:after_where() abort
647647
let line = getline(i)
648648
if line =~# '\v^\s*<module>'
649649
return 0
650-
elseif line =~# '\v^\s*(<class>|<instance>|<data>|<type> +<family>)'
650+
elseif line =~# '\v^\s*%(<class>|<instance>|<data>|<type> +<family>)'
651651
if line =~# '\v<where>\s*%(--.*)?$' && i != s:prevnonblank(v:lnum - 1)
652652
break
653653
endif
654-
return match(line, '\v(<class>|<instance>|<data>|<type> +<family>)') + &shiftwidth
655-
elseif line =~# '\v^(\S|\s*\k+\s*\=)' && line !~# '^--'
654+
return match(line, '\v%(<class>|<instance>|<data>|<type> +<family>)') + &shiftwidth
655+
elseif line =~# '\v^%(\S|\s*\k+\s*\=)' && line !~# '^--'
656656
return match(getline(s:prevnonblank(v:lnum - 1)), '\v<where>') + &shiftwidth
657657
endif
658658
let i -= 1
@@ -669,7 +669,7 @@ function! s:after_where() abort
669669
if line =~# '^\S'
670670
return 0
671671
elseif indent(i) < indent
672-
return match(line, '\v^\s*(<where>)?\s*\zs')
672+
return match(line, '\v^\s*%(<where>)?\s*\zs')
673673
endif
674674
let i -= 1
675675
endwhile

0 commit comments

Comments
 (0)