0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00
vim/runtime/indent/lua.vim

60 lines
1.6 KiB
VimL
Raw Normal View History

2004-06-13 20:20:40 +00:00
" Vim indent file
" Language: Lua script
2004-09-02 19:12:26 +00:00
" Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol.com.br>
" First Author: Max Ischenko <mfi 'at' ukr.net>
2005-06-25 23:04:51 +00:00
" Last Change: 2005 Jun 23
2005-06-13 22:28:56 +00:00
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
2004-06-13 20:20:40 +00:00
setlocal indentexpr=GetLuaIndent()
" To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until'
2005-06-25 23:04:51 +00:00
" on the current line ('else' is default and includes 'elseif').
2004-06-13 20:20:40 +00:00
setlocal indentkeys+=0=end,0=until
setlocal autoindent
2005-06-25 23:04:51 +00:00
" Only define the function once.
if exists("*GetLuaIndent")
finish
endif
2004-06-13 20:20:40 +00:00
function! GetLuaIndent()
" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)
" Hit the start of the file, use zero indent.
if lnum == 0
return 0
endif
2005-06-25 23:04:51 +00:00
" Add a 'shiftwidth' after lines that start a block:
" 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{'
2004-06-13 20:20:40 +00:00
let ind = indent(lnum)
let flag = 0
2004-09-02 19:12:26 +00:00
let prevline = getline(lnum)
2005-06-25 23:04:51 +00:00
if prevline =~ '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)'
\ || prevline =~ '{\s*$' || prevline =~ '\<function\>\s*\%(\k\|[.:]\)\{-}\s*('
2004-09-02 19:12:26 +00:00
let ind = ind + &shiftwidth
2004-06-13 20:20:40 +00:00
let flag = 1
endif
" Subtract a 'shiftwidth' after lines ending with
2005-06-25 23:04:51 +00:00
" 'end' when they begin with 'while', 'if', 'for', etc. too.
2004-09-02 19:12:26 +00:00
if flag == 1 && prevline =~ '\<end\>\|\<until\>'
let ind = ind - &shiftwidth
2004-06-13 20:20:40 +00:00
endif
" Subtract a 'shiftwidth' on end, else (and elseif), until and '}'
" This is the part that requires 'indentkeys'.
2004-09-02 19:12:26 +00:00
if getline(v:lnum) =~ '^\s*\%(end\|else\|until\|}\)'
let ind = ind - &shiftwidth
2004-06-13 20:20:40 +00:00
endif
return ind
endfunction