@@ -0,0 +1,102 @@
1+" indentation for idris (idris-lang.org)
3+" Based on haskell indentation by motemen <motemen@gmail.com>
5+" author: raichoo (raichoo@googlemail.com)
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
13+if exists('b:did_indent')
19+if !exists('g:idris_indent_if')
23+ let g:idris_indent_if = 3
26+if !exists('g:idris_indent_case')
30+ let g:idris_indent_case = 5
33+setlocal indentexpr=GetIdrisIndent()
34+setlocal indentkeys=!^F,o,O
36+function! GetIdrisIndent()
37+ let line = substitute(getline(getpos('.')[1] - 1), '\t', repeat(' ', &tabstop), 'g')
39+ if line =~ '[!#$%&*+./<=>?@\\^|~-]$\|\<do$'
40+ return match(line, '\s*where \zs\|\S') + &shiftwidth
44+ return match(line, '\s*where \zs\|\S') + &shiftwidth
47+ if line =~ '^\s*\(data\|instance\|class\).*\&.*where$'
48+ return match(line, '\(data\|instance\|class\)') + &shiftwidth
51+ if line =~ '^\s*using\s*(.\+)$'
52+ return match(line, 'using') + &shiftwidth
55+ if line =~ '\<with\>'
59+ if line =~ '^\s*data\s\+\S*\s\+=\s\+\S\+$'
60+ return match(line, '=')
63+ if line =~ '^\s*namespace\s\+\S\+$'
64+ return match(line, 'namespace') + &shiftwidth
68+ let pos = getpos('.')
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\>'
80+ let s = match(line, '\<if\>.*\&.*\zs\<then\>')
85+ let s = match(line, '\<if\>')
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')
96+ let s = match(line, '\<case\>')
98+ return s + g:idris_indent_case
101+ return match(line, '\S')