comparison runtime/indent/lua.vim @ 359:6c62b9b939bd v7.0093

updated for version 7.0093
author vimboss
date Sat, 25 Jun 2005 23:04:51 +0000
parents 03b3684919e3
children 73fe8baea242
comparison
equal deleted inserted replaced
358:e111db373ca4 359:6c62b9b939bd
1 " Vim indent file 1 " Vim indent file
2 " Language: Lua script 2 " Language: Lua script
3 " Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol.com.br> 3 " Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol.com.br>
4 " First Author: Max Ischenko <mfi 'at' ukr.net> 4 " First Author: Max Ischenko <mfi 'at' ukr.net>
5 " Last Change: 2005 Jun 09 5 " Last Change: 2005 Jun 23
6 6
7 " Only load this indent file when no other was loaded. 7 " Only load this indent file when no other was loaded.
8 if exists("b:did_indent") 8 if exists("b:did_indent")
9 finish 9 finish
10 endif 10 endif
11 let b:did_indent = 1 11 let b:did_indent = 1
12 12
13 setlocal indentexpr=GetLuaIndent()
14
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
18
19 setlocal autoindent
20
13 " Only define the function once. 21 " Only define the function once.
14 if exists("*GetLuaIndent") 22 if exists("*GetLuaIndent")
15 finish 23 finish
16 endif 24 endif
17
18 setlocal indentexpr=GetLuaIndent()
19
20 " To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until'
21 " on the current line (else is default).
22 setlocal indentkeys+=0=end,0=until
23
24 setlocal autoindent
25 25
26 function! GetLuaIndent() 26 function! GetLuaIndent()
27 " Find a non-blank line above the current line. 27 " Find a non-blank line above the current line.
28 let lnum = prevnonblank(v:lnum - 1) 28 let lnum = prevnonblank(v:lnum - 1)
29 29
30 " Hit the start of the file, use zero indent. 30 " Hit the start of the file, use zero indent.
31 if lnum == 0 31 if lnum == 0
32 return 0 32 return 0
33 endif 33 endif
34 34
35 " Add a 'shiftwidth' after lines beginning with: 35 " Add a 'shiftwidth' after lines that start a block:
36 " function, if, for, while, repeat, else, elseif, '{' 36 " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{'
37 let ind = indent(lnum) 37 let ind = indent(lnum)
38 let flag = 0 38 let flag = 0
39 let prevline = getline(lnum) 39 let prevline = getline(lnum)
40 if prevline =~ '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\)' || prevline =~ '{\s*$' || prevline =~ '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(' 40 if prevline =~ '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)'
41 \ || prevline =~ '{\s*$' || prevline =~ '\<function\>\s*\%(\k\|[.:]\)\{-}\s*('
41 let ind = ind + &shiftwidth 42 let ind = ind + &shiftwidth
42 let flag = 1 43 let flag = 1
43 endif 44 endif
44 45
45 " Subtract a 'shiftwidth' after lines ending with 46 " Subtract a 'shiftwidth' after lines ending with
46 " 'end' when they begin with while, if, for, etc. 47 " 'end' when they begin with 'while', 'if', 'for', etc. too.
47 if flag == 1 && prevline =~ '\<end\>\|\<until\>' 48 if flag == 1 && prevline =~ '\<end\>\|\<until\>'
48 let ind = ind - &shiftwidth 49 let ind = ind - &shiftwidth
49 endif 50 endif
50 51
51 " Subtract a 'shiftwidth' on end, else (and elseif), until and '}' 52 " Subtract a 'shiftwidth' on end, else (and elseif), until and '}'