annotate runtime/indent/lua.vim @ 31135:759b181807f7 v9.0.0902

patch 9.0.0902: some mouse scroll code is not in a good place Commit: https://github.com/vim/vim/commit/696d0a86250636602d42e29e57d8923f538e0549 Author: Christopher Plewright <chris@createng.com> Date: Fri Nov 18 17:53:34 2022 +0000 patch 9.0.0902: some mouse scroll code is not in a good place Problem: Some mouse scroll code is not in a good place. Solution: Refactor the code. (Christopher Plewright, closes https://github.com/vim/vim/issues/11561)
author Bram Moolenaar <Bram@vim.org>
date Fri, 18 Nov 2022 19:00:05 +0100
parents 0827d3d6d8c0
children f7576cf3640f
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
30324
0827d3d6d8c0 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
6 " 2022 Sep 07: b:undo_indent added by Doug Kearns
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
7
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
8 " Only load this indent file when no other was loaded.
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
9 if exists("b:did_indent")
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
10 finish
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
11 endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 22
diff changeset
12 let b:did_indent = 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
14 setlocal indentexpr=GetLuaIndent()
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
15
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
16 " To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until'
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
17 " on the current line ('else' is default and includes 'elseif').
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
18 setlocal indentkeys+=0=end,0=until
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
19
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
20 setlocal autoindent
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
21
30324
0827d3d6d8c0 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
22 let b:undo_indent = "setlocal autoindent< indentexpr< indentkeys<"
0827d3d6d8c0 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
23
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " Only define the function once.
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
25 if exists("*GetLuaIndent")
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
26 finish
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
27 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 function! GetLuaIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 " Find a non-blank line above the current line.
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
31 let prevlnum = prevnonblank(v:lnum - 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 " Hit the start of the file, use zero indent.
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
34 if prevlnum == 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
38 " Add a 'shiftwidth' after lines that start a block:
6c62b9b939bd updated for version 7.0093
vimboss
parents: 323
diff changeset
39 " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{'
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
40 let ind = indent(prevlnum)
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
41 let prevline = getline(prevlnum)
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
42 let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)')
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
43 if midx == -1
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
44 let midx = match(prevline, '{\s*$')
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
45 if midx == -1
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
46 let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(')
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
47 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
50 if midx != -1
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
51 " Add 'shiftwidth' if what we found previously is not in a comment and
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
52 " an "end" or "until" is not present on the same line.
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
53 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
54 let ind = ind + shiftwidth()
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
55 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57
7557
502ca0a62fd8 commit https://github.com/vim/vim/commit/acb4f221c715a333f4c49a2235a8006c6ac6e4d5
Christian Brabandt <cb@256bit.org>
parents: 6369
diff changeset
58 " Subtract a 'shiftwidth' on end, else, elseif, until and '}'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 " 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
60 let midx = match(getline(v:lnum), '^\s*\%(end\>\|else\>\|elseif\>\|until\>\|}\)')
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 359
diff changeset
61 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
62 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 endfunction