3 " Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol.com.br>
4 " First Author: Max Ischenko <mfi 'at' ukr.net>
5 " Last Change: 2005 Jun 23
7 " Only load this indent file when no other was loaded.
8 if exists("b:did_indent")
13 setlocal indentexpr=GetLuaIndent()
15 " To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until'
16 " on the current line ('else' is default and includes 'elseif').
17 setlocal indentkeys+=0=end,0=until
21 " Only define the function once.
22 if exists("*GetLuaIndent")
26 function! GetLuaIndent()
27 " Find a non-blank line above the current line.
28 let lnum = prevnonblank(v:lnum - 1)
30 " Hit the start of the file, use zero indent.
35 " Add a 'shiftwidth' after lines that start a block:
36 " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{'
37 let ind = indent(lnum)
39 let prevline = getline(lnum)
40 if prevline =~ '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)'
41 \ || prevline =~ '{\s*$' || prevline =~ '\<function\>\s*\%(\k\|[.:]\)\{-}\s*('
42 let ind = ind + &shiftwidth
46 " Subtract a 'shiftwidth' after lines ending with
47 " 'end' when they begin with 'while', 'if', 'for', etc. too.
48 if flag == 1 && prevline =~ '\<end\>\|\<until\>'
49 let ind = ind - &shiftwidth
52 " Subtract a 'shiftwidth' on end, else (and elseif), until and '}'
53 " This is the part that requires 'indentkeys'.
54 if getline(v:lnum) =~ '^\s*\%(end\|else\|until\|}\)'
55 let ind = ind - &shiftwidth