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