annotate runtime/indent/lua.vim @ 23150:90b16a0022e5 v8.2.2121

patch 8.2.2121: internal error when using ze before zs in a pattern Commit: https://github.com/vim/vim/commit/a7a691cc142439e266f4ceb1f208bb952b57aa71 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 9 16:36:04 2020 +0100 patch 8.2.2121: internal error when using \ze before \zs in a pattern Problem: Internal error when using \ze before \zs in a pattern. Solution: Check the end is never before the start. (closes https://github.com/vim/vim/issues/7442)
author Bram Moolenaar <Bram@vim.org>
date Wed, 09 Dec 2020 16:45:04 +0100
parents 63b0b7b79b25
children 0827d3d6d8c0
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>
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7557
diff changeset
5 " Last Change: 2017 Jun 13
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\>'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7557
diff changeset
51 let ind = ind + shiftwidth()
1620
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
7557
502ca0a62fd8 commit https://github.com/vim/vim/commit/acb4f221c715a333f4c49a2235a8006c6ac6e4d5
Christian Brabandt <cb@256bit.org>
parents: 6369
diff changeset
55 " Subtract a 'shiftwidth' on end, else, elseif, until and '}'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 " This is the part that requires 'indentkeys'.
7557
502ca0a62fd8 commit https://github.com/vim/vim/commit/acb4f221c715a333f4c49a2235a8006c6ac6e4d5
Christian Brabandt <cb@256bit.org>
parents: 6369
diff changeset
57 let midx = match(getline(v:lnum), '^\s*\%(end\>\|else\>\|elseif\>\|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"
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7557
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