2152
|
1 " Vim indent file
|
|
2 " Language: ChaiScript
|
|
3 " Maintainer: Jason Turner <lefticus 'at' gmail com>
|
|
4
|
|
5 " Only load this indent file when no other was loaded.
|
|
6 if exists("b:did_indent")
|
|
7 finish
|
|
8 endif
|
|
9 let b:did_indent = 1
|
|
10
|
|
11 setlocal indentexpr=GetChaiScriptIndent()
|
|
12 setlocal autoindent
|
|
13
|
|
14 " Only define the function once.
|
|
15 if exists("*GetChaiScriptIndent")
|
|
16 finish
|
|
17 endif
|
|
18
|
|
19 function! GetChaiScriptIndent()
|
|
20 " Find a non-blank line above the current line.
|
|
21 let lnum = prevnonblank(v:lnum - 1)
|
|
22
|
|
23 " Hit the start of the file, use zero indent.
|
|
24 if lnum == 0
|
|
25 return 0
|
|
26 endif
|
|
27
|
|
28 " Add a 'shiftwidth' after lines that start a block:
|
|
29 " lines containing a {
|
|
30 let ind = indent(lnum)
|
|
31 let flag = 0
|
|
32 let prevline = getline(lnum)
|
|
33 if prevline =~ '^.*{.*'
|
11518
|
34 let ind = ind + shiftwidth()
|
2152
|
35 let flag = 1
|
|
36 endif
|
|
37
|
|
38 " Subtract a 'shiftwidth' after lines containing a { followed by a }
|
|
39 " to keep it balanced
|
|
40 if flag == 1 && prevline =~ '.*{.*}.*'
|
11518
|
41 let ind = ind - shiftwidth()
|
2152
|
42 endif
|
|
43
|
|
44 " Subtract a 'shiftwidth' on lines ending with }
|
|
45 if getline(v:lnum) =~ '^\s*\%(}\)'
|
11518
|
46 let ind = ind - shiftwidth()
|
2152
|
47 endif
|
|
48
|
|
49 return ind
|
|
50 endfunction
|