Mercurial > hg > RemoteEditor > vim7
annotate runtime/indent/lua.vim @ 48:67300faee616 v7-3-618
v7-3-618
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 01 Aug 2012 18:08:28 +0900 |
parents | e170173ecb68 |
children |
rev | line source |
---|---|
0 | 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> | |
34
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
5 " Last Change: 2007 Jul 23 |
0 | 6 |
7 " Only load this indent file when no other was loaded. | |
8 if exists("b:did_indent") | |
9 finish | |
10 endif | |
11 let b:did_indent = 1 | |
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 | |
21 " Only define the function once. | |
22 if exists("*GetLuaIndent") | |
23 finish | |
24 endif | |
25 | |
26 function! GetLuaIndent() | |
27 " Find a non-blank line above the current line. | |
34
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
28 let prevlnum = prevnonblank(v:lnum - 1) |
0 | 29 |
30 " Hit the start of the file, use zero indent. | |
34
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
31 if prevlnum == 0 |
0 | 32 return 0 |
33 endif | |
34 | |
35 " Add a 'shiftwidth' after lines that start a block: | |
36 " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{' | |
34
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
37 let ind = indent(prevlnum) |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
38 let prevline = getline(prevlnum) |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
39 let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)') |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
40 if midx == -1 |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
41 let midx = match(prevline, '{\s*$') |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
42 if midx == -1 |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
43 let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(') |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
44 endif |
0 | 45 endif |
46 | |
34
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
47 if midx != -1 |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
48 " Add 'shiftwidth' if what we found previously is not in a comment and |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
49 " an "end" or "until" is not present on the same line. |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
50 if synIDattr(synID(prevlnum, midx + 1, 1), "name") != "luaComment" && prevline !~ '\<end\>\|\<until\>' |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
51 let ind = ind + &shiftwidth |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
52 endif |
0 | 53 endif |
54 | |
55 " Subtract a 'shiftwidth' on end, else (and elseif), until and '}' | |
56 " This is the part that requires 'indentkeys'. | |
34
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
57 let midx = match(getline(v:lnum), '^\s*\%(end\|else\|until\|}\)') |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
58 if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment" |
0 | 59 let ind = ind - &shiftwidth |
60 endif | |
61 | |
62 return ind | |
63 endfunction |