Mercurial > hg > RemoteEditor > vim7
comparison runtime/indent/lua.vim @ 34:e170173ecb68 current-release
before ack base protocol.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 26 Nov 2008 15:02:10 +0900 |
parents | 76efa0be13f1 |
children |
comparison
equal
deleted
inserted
replaced
33:7d0d8b831f5a | 34:e170173ecb68 |
---|---|
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 23 | 5 " Last Change: 2007 Jul 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 |
23 finish | 23 finish |
24 endif | 24 endif |
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 prevlnum = 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 prevlnum == 0 |
32 return 0 | 32 return 0 |
33 endif | 33 endif |
34 | 34 |
35 " Add a 'shiftwidth' after lines that start a block: | 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(prevlnum) |
38 let flag = 0 | 38 let prevline = getline(prevlnum) |
39 let prevline = getline(lnum) | 39 let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)') |
40 if prevline =~ '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)' | 40 if midx == -1 |
41 \ || prevline =~ '{\s*$' || prevline =~ '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(' | 41 let midx = match(prevline, '{\s*$') |
42 let ind = ind + &shiftwidth | 42 if midx == -1 |
43 let flag = 1 | 43 let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(') |
44 endif | |
44 endif | 45 endif |
45 | 46 |
46 " Subtract a 'shiftwidth' after lines ending with | 47 if midx != -1 |
47 " 'end' when they begin with 'while', 'if', 'for', etc. too. | 48 " Add 'shiftwidth' if what we found previously is not in a comment and |
48 if flag == 1 && prevline =~ '\<end\>\|\<until\>' | 49 " an "end" or "until" is not present on the same line. |
49 let ind = ind - &shiftwidth | 50 if synIDattr(synID(prevlnum, midx + 1, 1), "name") != "luaComment" && prevline !~ '\<end\>\|\<until\>' |
51 let ind = ind + &shiftwidth | |
52 endif | |
50 endif | 53 endif |
51 | 54 |
52 " Subtract a 'shiftwidth' on end, else (and elseif), until and '}' | 55 " Subtract a 'shiftwidth' on end, else (and elseif), until and '}' |
53 " This is the part that requires 'indentkeys'. | 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 let ind = ind - &shiftwidth | 59 let ind = ind - &shiftwidth |
56 endif | 60 endif |
57 | 61 |
58 return ind | 62 return ind |
59 endfunction | 63 endfunction |