@@ -3,7 +3,7 @@
3" Based on haskell indentation by motemen <motemen@gmail.com>
3" Based on haskell indentation by motemen <motemen@gmail.com>
5" author: raichoo (raichoo@googlemail.com)
5" author: raichoo (raichoo@googlemail.com)
6−" date: Sep 21 2012
6+" date: Oct 19 2012
8" Modify g:idris_indent_if and g:idris_indent_case to
8" Modify g:idris_indent_if and g:idris_indent_case to
9" change indentation for `if'(default 3) and `case'(default 5).
9" change indentation for `if'(default 3) and `case'(default 5).
@@ -11,92 +11,109 @@
11" > let g:idris_indent_if = 2
11" > let g:idris_indent_if = 2
13if exists('b:did_indent')
13if exists('b:did_indent')
17let b:did_indent = 1
17let b:did_indent = 1
19if !exists('g:idris_indent_if')
19if !exists('g:idris_indent_if')
20− " if bool
20+ " if bool
21− " >>>then ...
21+ " >>>then ...
22− " >>>else ...
22+ " >>>else ...
23− let g:idris_indent_if = 3
23+ let g:idris_indent_if = 3
26if !exists('g:idris_indent_case')
26if !exists('g:idris_indent_case')
27− " case xs of
27+ " case xs of
28− " >>>>>[] -> ...
28+ " >>>>>[] -> ...
29− " >>>>>(y:ys) -> ...
29+ " >>>>>(y::ys) -> ...
30− let g:idris_indent_case = 5
30+ let g:idris_indent_case = 5
33+if !exists('g:idris_indent_let')
36+ let g:idris_indent_let = 4
39+if !exists('g:idris_indent_where')
40+ " where f : Nat -> Nat
42+ let g:idris_indent_where = 6
45+if !exists('g:idris_indent_do')
48+ let g:idris_indent_do = 3
33setlocal indentexpr=GetIdrisIndent()
51setlocal indentexpr=GetIdrisIndent()
34setlocal indentkeys=!^F,o,O
52setlocal indentkeys=!^F,o,O
36function! GetIdrisIndent()
54function! GetIdrisIndent()
37− let line = substitute(getline(getpos('.')[1] - 1), '\t', repeat(' ', &tabstop), 'g')
55+ let prevline = getline(v:lnum - 1)
39− if line =~ '[!#$%&*+./<=>?@\\^|~-]$\|\<do$'
57+ if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
40− return match(line, '\s*where \zs\|\S') + &shiftwidth
58+ let s = match(prevline, '[:=]')
62+ return match(prevline, '\S')
43− if line =~ '{$'
66+ if prevline =~ '[{([]\s*$'
44− return match(line, '\s*where \zs\|\S') + &shiftwidth
67+ return match(prevline, '[{([]')
47− if line =~ '^\s*\(data\|instance\|class\).*\&.*where$'
70+ if prevline =~ 'let\s\+.\+in\s*$'
48− return match(line, '\(data\|instance\|class\)') + &shiftwidth
71+ return match(prevline, 'let') + g:idris_indent_let
51− if line =~ '^\s*using\s*(.\+)$'
74+ if prevline !~ '\<else\>'
52− return match(line, 'using') + &shiftwidth
75+ let s = match(prevline, '\<if\>.*\&.*\zs\<then\>')
55− if line =~ '\<with\>'
80+ let s = match(prevline, '\<if\>')
56− return &shiftwidth
81+ if s > 0
82+ return s + g:idris_indent_if
59− if line =~ '^\s*data\s\+\S*\s\+=\s\+\S\+$'
86+ if prevline =~ '\(where\|do\|=\)\s*$'
60− return match(line, '=')
87+ return match(prevline, '\S') + &shiftwidth
63− if line =~ '^\s*namespace\s\+\S\+$'
90+ if prevline =~ 'where\s\+\S\+.*$'
64− return match(line, 'namespace') + &shiftwidth
91+ return match(prevline, 'where') + g:idris_indent_where
67− if line =~ ')$'
94+ if prevline =~ 'do\s\+\S\+.*$'
68− let pos = getpos('.')
95+ return match(prevline, 'do') + g:idris_indent_do
70− let paren_end = getpos('.')
72− let paren_begin = getpos('.')
73− call setpos('.', pos)
74− if paren_begin[1] != paren_end[1]
75− return paren_begin[2] - 1
79− if line !~ '\<else\>'
98+ if prevline =~ '^\s*data\s\+[^=]\+\s\+=\s\+\S\+.*$'
80− let s = match(line, '\<if\>.*\&.*\zs\<then\>')
99+ return match(prevline, '=')
85− let s = match(line, '\<if\>')
102+ if prevline =~ 'with\s\+([^)]*)\s*$'
86− if s > 0
103+ return match(prevline, '\S') + &shiftwidth
87− return s + g:idris_indent_if
91− let s = match(line, '\<do\s\+\zs[^{]\|\<where\s\+\zs\w\|\<let\s\+\zs\S\|^\s*\zs|\s')
106+ if prevline =~ 'case\s\+.\+of\s*$'
92− if s > 0
107+ return match(prevline, 'case') + g:idris_indent_case
96− let s = match(line, '\<case\>')
110+ if prevline =~ '^\s*\(namespace\|data\)\s\+\S\+\s*$'
97− if s > 0
111+ return match(prevline, '\(namespace\|data\)') + &shiftwidth
98− return s + g:idris_indent_case
112+ endif
114+ if prevline =~ '^\s*using\s\+([^(]*)\s*$'
115+ return match(prevline, 'using') + &shiftwidth
101− return match(line, '\S')
118+ return match(prevline, '\S')
102endfunction
119endfunction