7
|
1 " Vim indent file
|
|
2 " Language: Lua script
|
|
3 " Maintainer: Marcus Aurelius Farias <marcuscf@vant.com.br>
|
|
4 " First Author: Max Ischenko <mfi@ukr.net>
|
|
5 " Last Change: 2003 Jan 20
|
|
6
|
|
7 " Only define the function once.
|
|
8 if exists("*GetLuaIndent") | finish | endif
|
|
9
|
|
10 setlocal indentexpr=GetLuaIndent()
|
|
11
|
|
12 " To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until'
|
|
13 " on the current line (else is default).
|
|
14 setlocal indentkeys+=0=end,0=until
|
|
15
|
|
16 setlocal autoindent
|
|
17
|
|
18 function! GetLuaIndent()
|
|
19 " Find a non-blank line above the current line.
|
|
20 let lnum = prevnonblank(v:lnum - 1)
|
|
21
|
|
22 " Hit the start of the file, use zero indent.
|
|
23 if lnum == 0
|
|
24 return 0
|
|
25 endif
|
|
26
|
|
27 " Add a 'shiftwidth' after lines beginning with:
|
|
28 " function, if, for, while, repeat, else, elseif, '{'
|
|
29 let ind = indent(lnum)
|
|
30 let flag = 0
|
|
31 if getline(lnum) =~ '^\s*\(function\>\|if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\)' || getline(lnum) =~ '{\s*$' || getline(lnum) =~ '\s*=\s*function'
|
|
32 let ind = ind + &sw
|
|
33 let flag = 1
|
|
34 endif
|
|
35
|
|
36 " Subtract a 'shiftwidth' after lines ending with
|
|
37 " 'end' when they begin with while, if, for, etc.
|
|
38 if flag == 1 && getline(lnum) =~ '\<end\>\|\<until\>'
|
|
39 let ind = ind - &sw
|
|
40 endif
|
|
41
|
|
42 " Subtract a 'shiftwidth' on end, else (and elseif), until and '}'
|
|
43 " This is the part that requires 'indentkeys'.
|
|
44 if getline(v:lnum) =~ '^\s*\(end\|else\|until\|}\)'
|
|
45 let ind = ind - &sw
|
|
46 endif
|
|
47
|
|
48 return ind
|
|
49 endfunction
|