Skip to content

Commit 5181edc

Browse files
committed
fix priority of parenthesis and case expression (close #33)
1 parent bf6a265 commit 5181edc

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

indent/haskell.vim

Lines changed: 32 additions & 32 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: 2024/08/04 15:46:49.
5+
" Last Change: 2024/11/01 20:51:18.
66
" =============================================================================
77

88
if exists('b:did_indent')
@@ -110,32 +110,6 @@ function! GetHaskellIndent() abort
110110
return match(nonblankline, '^\s*\zs--')
111111
endif
112112

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-
139113
if nonblankline =~# '\v^\s*<infix[rl]?>'
140114
return match(nonblankline, '\S')
141115
endif
@@ -152,10 +126,6 @@ function! GetHaskellIndent() abort
152126
return match(nonblankline, '\v<do>\s*\zs\S')
153127
endif
154128

155-
if nonblankline =~# '\v<deriving>'
156-
return s:indent('', '\v^\s*\zs<data>', 0)
157-
endif
158-
159129
if line =~# '\v<if>' && line !~# '\v^\s*#'
160130
if line !~# '\v<then>'
161131
return match(line, '\v.*<if>\s*\zs')
@@ -172,7 +142,7 @@ function! GetHaskellIndent() abort
172142
return indent(s:prevnonblank(v:lnum - 1)) + &shiftwidth
173143
endif
174144
else
175-
return line =~# '\v<case>.*<of>\s*[[:alnum:](]'
145+
return line =~# '\v<case>.*<of>\s*([[:alnum:](\"''\[]|-\d)'
176146
\ ? match(line, '\v<case>.*<of>\s*\zs\S')
177147
\ : match(line, '\v.*<case>\s*\zs')
178148
endif
@@ -186,6 +156,36 @@ function! GetHaskellIndent() abort
186156
return match(line, '\v\\\s*<case>\s*\zs\S')
187157
endif
188158

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+
189189
if nonblankline =~# '\v^.*[^|]\|[^|].*\='
190190
return s:after_guard()
191191
endif
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
f x = F (case x of -1 -> 0
2+
2 -> 1
3+
_ -> (-x))
4+
g x = x
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
f x = F (case x of -1 -> 0
2+
2 -> 1
3+
_ -> (-x))
4+
g x = x

0 commit comments

Comments
 (0)