2
2
" Language: Lua script
3
3
" Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol.com.br>
4
4
" First Author: Max Ischenko <mfi 'at' ukr.net>
5
" Last Change: 2005 Jun 23
5
" Last Change: 2007 Jul 23
7
7
" Only load this indent file when no other was loaded.
8
8
if exists("b:did_indent")
26
26
function! GetLuaIndent()
27
27
" Find a non-blank line above the current line.
28
let lnum = prevnonblank(v:lnum - 1)
28
let prevlnum = prevnonblank(v:lnum - 1)
30
30
" Hit the start of the file, use zero indent.
35
35
" Add a 'shiftwidth' after lines that start a block:
36
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
37
let ind = indent(prevlnum)
38
let prevline = getline(prevlnum)
39
let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)')
41
let midx = match(prevline, '{\s*$')
43
let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(')
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
48
" Add 'shiftwidth' if what we found previously is not in a comment and
49
" an "end" or "until" is not present on the same line.
50
if synIDattr(synID(prevlnum, midx + 1, 1), "name") != "luaComment" && prevline !~ '\<end\>\|\<until\>'
51
let ind = ind + &shiftwidth
52
55
" Subtract a 'shiftwidth' on end, else (and elseif), until and '}'
53
56
" This is the part that requires 'indentkeys'.
54
if getline(v:lnum) =~ '^\s*\%(end\|else\|until\|}\)'
57
let midx = match(getline(v:lnum), '^\s*\%(end\|else\|until\|}\)')
58
if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment"
55
59
let ind = ind - &shiftwidth