@@ -3,7 +3,7 @@
33" Based on haskell indentation by motemen <motemen@gmail.com>
44"
55" author: raichoo (raichoo@googlemail.com)
6−" date: Sep 21 2012
6+" date: Oct 19 2012
77"
88" Modify g:idris_indent_if and g:idris_indent_case to
99" change indentation for `if'(default 3) and `case'(default 5).
@@ -11,92 +11,109 @@
1111" > let g:idris_indent_if = 2
1212
1313if exists('b:did_indent')
14− finish
14+ finish
1515endif
1616
1717let b:did_indent = 1
1818
1919if !exists('g:idris_indent_if')
20− " if bool
21− " >>>then ...
22− " >>>else ...
23− let g:idris_indent_if = 3
20+ " if bool
21+ " >>>then ...
22+ " >>>else ...
23+ let g:idris_indent_if = 3
2424endif
2525
2626if !exists('g:idris_indent_case')
27− " case xs of
28− " >>>>>[] -> ...
29− " >>>>>(y:ys) -> ...
30− let g:idris_indent_case = 5
27+ " case xs of
28+ " >>>>>[] -> ...
29+ " >>>>>(y::ys) -> ...
30+ let g:idris_indent_case = 5
31+endif
32+
33+if !exists('g:idris_indent_let')
34+ " let x : Nat = O in
35+ " >>>>x
36+ let g:idris_indent_let = 4
37+endif
38+
39+if !exists('g:idris_indent_where')
40+ " where f : Nat -> Nat
41+ " >>>>>>f x = x
42+ let g:idris_indent_where = 6
43+endif
44+
45+if !exists('g:idris_indent_do')
46+ " do x <- a
47+ " >>>y <- b
48+ let g:idris_indent_do = 3
3149endif
3250
3351setlocal indentexpr=GetIdrisIndent()
3452setlocal indentkeys=!^F,o,O
3553
3654function! GetIdrisIndent()
37− let line = substitute(getline(getpos('.')[1] - 1), '\t', repeat(' ', &tabstop), 'g')
55+ let prevline = getline(v:lnum - 1)
3856
39− if line =~ '[!#$%&*+./<=>?@\\^|~-]$\|\<do$'
40− return match(line, '\s*where \zs\|\S') + &shiftwidth
57+ if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
58+ let s = match(prevline, '[:=]')
59+ if s > 0
60+ return s + 2
61+ else
62+ return match(prevline, '\S')
4163 endif
64+ endif
4265
43− if line =~ '{$'
44− return match(line, '\s*where \zs\|\S') + &shiftwidth
45− endif
66+ if prevline =~ '[{([]\s*$'
67+ return match(prevline, '[{([]')
68+ endif
4669
47− if line =~ '^\s*\(data\|instance\|class\).*\&.*where$'
48− return match(line, '\(data\|instance\|class\)') + &shiftwidth
49− endif
70+ if prevline =~ 'let\s\+.\+in\s*$'
71+ return match(prevline, 'let') + g:idris_indent_let
72+ endif
5073
51− if line =~ '^\s*using\s*(.\+)$'
52− return match(line, 'using') + &shiftwidth
74+ if prevline !~ '\<else\>'
75+ let s = match(prevline, '\<if\>.*\&.*\zs\<then\>')
76+ if s > 0
77+ return s
5378 endif
5479
55− if line =~ '\<with\>'
56− return &shiftwidth
80+ let s = match(prevline, '\<if\>')
81+ if s > 0
82+ return s + g:idris_indent_if
5783 endif
84+ endif
5885
59− if line =~ '^\s*data\s\+\S*\s\+=\s\+\S\+$'
60− return match(line, '=')
61− endif
86+ if prevline =~ '\(where\|do\|=\)\s*$'
87+ return match(prevline, '\S') + &shiftwidth
88+ endif
6289
63− if line =~ '^\s*namespace\s\+\S\+$'
64− return match(line, 'namespace') + &shiftwidth
65− endif
90+ if prevline =~ 'where\s\+\S\+.*$'
91+ return match(prevline, 'where') + g:idris_indent_where
92+ endif
6693
67− if line =~ ')$'
68− let pos = getpos('.')
69− normal k$
70− let paren_end = getpos('.')
71− normal %
72− let paren_begin = getpos('.')
73− call setpos('.', pos)
74− if paren_begin[1] != paren_end[1]
75− return paren_begin[2] - 1
76− endif
77− endif
94+ if prevline =~ 'do\s\+\S\+.*$'
95+ return match(prevline, 'do') + g:idris_indent_do
96+ endif
7897
79− if line !~ '\<else\>'
80− let s = match(line, '\<if\>.*\&.*\zs\<then\>')
81− if s > 0
82− return s
83− endif
98+ if prevline =~ '^\s*data\s\+[^=]\+\s\+=\s\+\S\+.*$'
99+ return match(prevline, '=')
100+ endif
84101
85− let s = match(line, '\<if\>')
86− if s > 0
87− return s + g:idris_indent_if
88− endif
89− endif
102+ if prevline =~ 'with\s\+([^)]*)\s*$'
103+ return match(prevline, '\S') + &shiftwidth
104+ endif
90105
91− let s = match(line, '\<do\s\+\zs[^{]\|\<where\s\+\zs\w\|\<let\s\+\zs\S\|^\s*\zs|\s')
92− if s > 0
93− return s
94− endif
106+ if prevline =~ 'case\s\+.\+of\s*$'
107+ return match(prevline, 'case') + g:idris_indent_case
108+ endif
95109
96− let s = match(line, '\<case\>')
97− if s > 0
98− return s + g:idris_indent_case
99− endif
110+ if prevline =~ '^\s*\(namespace\|data\)\s\+\S\+\s*$'
111+ return match(prevline, '\(namespace\|data\)') + &shiftwidth
112+ endif
113+
114+ if prevline =~ '^\s*using\s\+([^(]*)\s*$'
115+ return match(prevline, 'using') + &shiftwidth
116+ endif
100117
101− return match(line, '\S')
118+ return match(prevline, '\S')
102119endfunction