code / vim-tomo

Lines184 vim script176 Markdown8
(57 lines)
1 " Language: Tomo
2 " Maintainer: Bruce Hill <bruce@bruce-hill.com>
3 " License: WTFPL
5 if exists("b:did_indent")
6 finish
7 endif
9 let b:did_indent = 1
11 setlocal autoindent
12 setlocal indentexpr=GetTomoIndent()
13 setlocal indentkeys+=s
15 " Only define the function once.
16 if exists("*GetTomoIndent")
17 finish
18 endif
20 function! GetTomoIndent()
21 let line = getline(v:lnum)
22 let current_ind = indent(v:lnum)
23 let previousNum = prevnonblank(v:lnum - 1)
24 let prev_line = getline(previousNum)
25 let ind = indent(previousNum)
27 if line =~ '^\s*else$'
28 if prev_line =~ '^\s*else \+if\> .* then .*$' && current_ind == ind
29 return current_ind
30 else
31 return current_ind - &tabstop
32 endif
33 endif
35 if line =~ '^\s*\(skip\|stop\|pass\|return\|break\|continue\|)\(.*\<if\>\)\@!$'
36 return current_ind - &tabstop
37 endif
39 if line =~ '^\s*is$'
40 if prev_line =~ '^\s*is .* then .*$' && current_ind == ind
41 return current_ind
42 else
43 return current_ind - &tabstop
44 endif
45 endif
47 if prev_line =~ '\(^\s*\<\(for\|while\|if\|repeat\|when\|func\|convert\|lang\|struct\|enum\)\>\)\|^[^#]*[:=]\s*$'
48 if prev_line !~ '^.* then '
49 let ind = ind + &tabstop
50 endif
51 endif
53 if ind == indent(previousNum)
54 return current_ind
55 endif
56 return ind
57 endfunction