@@ -0,0 +1,102 @@
1+" indentation for idris (idris-lang.org)
2+"
3+" Based on haskell indentation by motemen <motemen@gmail.com>
4+"
5+" author: raichoo (raichoo@googlemail.com)
6+" date: Sep 21 2012
7+"
8+" Modify g:idris_indent_if and g:idris_indent_case to
9+" change indentation for `if'(default 3) and `case'(default 5).
10+" Example (in .vimrc):
11+" > let g:idris_indent_if = 2
12+
13+if exists('b:did_indent')
14+ finish
15+endif
16+
17+let b:did_indent = 1
18+
19+if !exists('g:idris_indent_if')
20+ " if bool
21+ " >>>then ...
22+ " >>>else ...
23+ let g:idris_indent_if = 3
24+endif
25+
26+if !exists('g:idris_indent_case')
27+ " case xs of
28+ " >>>>>[] -> ...
29+ " >>>>>(y:ys) -> ...
30+ let g:idris_indent_case = 5
31+endif
32+
33+setlocal indentexpr=GetIdrisIndent()
34+setlocal indentkeys=!^F,o,O
35+
36+function! GetIdrisIndent()
37+ let line = substitute(getline(getpos('.')[1] - 1), '\t', repeat(' ', &tabstop), 'g')
38+
39+ if line =~ '[!#$%&*+./<=>?@\\^|~-]$\|\<do$'
40+ return match(line, '\s*where \zs\|\S') + &shiftwidth
41+ endif
42+
43+ if line =~ '{$'
44+ return match(line, '\s*where \zs\|\S') + &shiftwidth
45+ endif
46+
47+ if line =~ '^\s*\(data\|instance\|class\).*\&.*where$'
48+ return match(line, '\(data\|instance\|class\)') + &shiftwidth
49+ endif
50+
51+ if line =~ '^\s*using\s*(.\+)$'
52+ return match(line, 'using') + &shiftwidth
53+ endif
54+
55+ if line =~ '\<with\>'
56+ return &shiftwidth
57+ endif
58+
59+ if line =~ '^\s*data\s\+\S*\s\+=\s\+\S\+$'
60+ return match(line, '=')
61+ endif
62+
63+ if line =~ '^\s*namespace\s\+\S\+$'
64+ return match(line, 'namespace') + &shiftwidth
65+ endif
66+
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
78+
79+ if line !~ '\<else\>'
80+ let s = match(line, '\<if\>.*\&.*\zs\<then\>')
81+ if s > 0
82+ return s
83+ endif
84+
85+ let s = match(line, '\<if\>')
86+ if s > 0
87+ return s + g:idris_indent_if
88+ endif
89+ endif
90+
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
95+
96+ let s = match(line, '\<case\>')
97+ if s > 0
98+ return s + g:idris_indent_case
99+ endif
100+
101+ return match(line, '\S')
102+endfunction