annotate runtime/indent/lua.vim @ 6820:41745c0fdee4

Added tag v7-4-731 for changeset 5f24d6d51333
author Bram Moolenaar <bram@vim.org>
date Tue, 09 Jun 2015 19:14:24 +0200
parents c5d53d4c3e2e
children 502ca0a62fd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: Lua script
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
3 " Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol.com.br>
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
4 " First Author: Max Ischenko <mfi 'at' ukr.net>
6369
c5d53d4c3e2e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
5 " Last Change: 2014 Nov 12
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
6
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
7 " Only load this indent file when no other was loaded.
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
8 if exists("b:did_indent")
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
9 finish
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
10 endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
11 let b:did_indent = 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
13 setlocal indentexpr=GetLuaIndent()
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
14
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
15 " To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until'
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
16 " on the current line ('else' is default and includes 'elseif').
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
17 setlocal indentkeys+=0=end,0=until
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
18
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
19 setlocal autoindent
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
20
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 " Only define the function once.
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
22 if exists("*GetLuaIndent")
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
23 finish
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
24 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 function! GetLuaIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 " Find a non-blank line above the current line.
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
28 let prevlnum = prevnonblank(v:lnum - 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 " Hit the start of the file, use zero indent.
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
31 if prevlnum == 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
35 " Add a 'shiftwidth' after lines that start a block:
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
36 " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{'
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
37 let ind = indent(prevlnum)
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
38 let prevline = getline(prevlnum)
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
39 let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)')
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
40 if midx == -1
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
41 let midx = match(prevline, '{\s*$')
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
42 if midx == -1
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
43 let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(')
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
44 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
47 if midx != -1
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
48 " Add 'shiftwidth' if what we found previously is not in a comment and
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
49 " an "end" or "until" is not present on the same line.
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
50 if synIDattr(synID(prevlnum, midx + 1, 1), "name") != "luaComment" && prevline !~ '\<end\>\|\<until\>'
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
51 let ind = ind + &shiftwidth
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
52 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 " Subtract a 'shiftwidth' on end, else (and elseif), until and '}'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 " This is the part that requires 'indentkeys'.
6369
c5d53d4c3e2e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
57 let midx = match(getline(v:lnum), '^\s*\%(end\>\|else\>\|until\>\|}\)')
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
58 if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment"
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
59 let ind = ind - &shiftwidth
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 endfunction