Mercurial > vim
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 |
rev | line source |
---|---|
7 | 1 " Vim indent file |
2 " Language: Lua script | |
22 | 3 " Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol.com.br> |
4 " First Author: Max Ischenko <mfi 'at' ukr.net> | |
11518 | 5 " Last Change: 2017 Jun 13 |
30324 | 6 " 2022 Sep 07: b:undo_indent added by Doug Kearns |
323 | 7 |
8 " Only load this indent file when no other was loaded. | |
9 if exists("b:did_indent") | |
10 finish | |
11 endif | |
12 let b:did_indent = 1 | |
7 | 13 |
359 | 14 setlocal indentexpr=GetLuaIndent() |
15 | |
16 " To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until' | |
17 " on the current line ('else' is default and includes 'elseif'). | |
18 setlocal indentkeys+=0=end,0=until | |
19 | |
20 setlocal autoindent | |
21 | |
30324 | 22 let b:undo_indent = "setlocal autoindent< indentexpr< indentkeys<" |
23 | |
7 | 24 " Only define the function once. |
22 | 25 if exists("*GetLuaIndent") |
26 finish | |
27 endif | |
7 | 28 |
29 function! GetLuaIndent() | |
30 " Find a non-blank line above the current line. | |
1620 | 31 let prevlnum = prevnonblank(v:lnum - 1) |
7 | 32 |
33 " Hit the start of the file, use zero indent. | |
1620 | 34 if prevlnum == 0 |
7 | 35 return 0 |
36 endif | |
37 | |
359 | 38 " Add a 'shiftwidth' after lines that start a block: |
39 " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{' | |
1620 | 40 let ind = indent(prevlnum) |
41 let prevline = getline(prevlnum) | |
42 let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)') | |
43 if midx == -1 | |
44 let midx = match(prevline, '{\s*$') | |
45 if midx == -1 | |
46 let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(') | |
47 endif | |
7 | 48 endif |
49 | |
1620 | 50 if midx != -1 |
51 " Add 'shiftwidth' if what we found previously is not in a comment and | |
52 " an "end" or "until" is not present on the same line. | |
53 if synIDattr(synID(prevlnum, midx + 1, 1), "name") != "luaComment" && prevline !~ '\<end\>\|\<until\>' | |
11518 | 54 let ind = ind + shiftwidth() |
1620 | 55 endif |
7 | 56 endif |
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 | 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 | 61 if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment" |
11518 | 62 let ind = ind - shiftwidth() |
7 | 63 endif |
64 | |
65 return ind | |
66 endfunction |