Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
lua.vim78 linesDownload Raw Back to indent
1" Vim indent file2" Language:	Lua script3" Maintainer:	Marcus Aurelius Farias <marcus.cf 'at' bol.com.br>4" First Author:	Max Ischenko <mfi 'at' ukr.net>5" Last Change:	2017 Jun 136"		2022 Sep 07: b:undo_indent added by Doug Kearns7"		2024 Jul 27: by Vim project: match '(', ')' in function GetLuaIndentIntern()8 9" Only load this indent file when no other was loaded.10if exists("b:did_indent")11  finish12endif13let b:did_indent = 114 15setlocal indentexpr=GetLuaIndent()16 17" To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until'18" on the current line ('else' is default and includes 'elseif').19setlocal indentkeys+=0=end,0=until20 21setlocal autoindent22 23let b:undo_indent = "setlocal autoindent< indentexpr< indentkeys<"24 25" Only define the function once.26if exists("*GetLuaIndent")27  finish28endif29 30function! GetLuaIndent()31    let ignorecase_save = &ignorecase32  try33    let &ignorecase = 034    return GetLuaIndentIntern()35  finally36    let &ignorecase = ignorecase_save37  endtry38endfunction39 40function! GetLuaIndentIntern()41  " Find a non-blank line above the current line.42  let prevlnum = prevnonblank(v:lnum - 1)43 44  " Hit the start of the file, use zero indent.45  if prevlnum == 046    return 047  endif48 49  " Add a 'shiftwidth' after lines that start a block:50  " 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{', '('51  let ind = indent(prevlnum)52  let prevline = getline(prevlnum)53  let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)')54  if midx == -155    let midx = match(prevline, '\%({\|(\)\s*\%(--\%([^[].*\)\?\)\?$')56    if midx == -157      let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(')58    endif59  endif60 61  if midx != -162    " Add 'shiftwidth' if what we found previously is not in a comment and63    " an "end" or "until" is not present on the same line.64    if synIDattr(synID(prevlnum, midx + 1, 1), "name") != "luaComment" && prevline !~ '\<end\>\|\<until\>'65      let ind = ind + shiftwidth()66    endif67  endif68 69  " Subtract a 'shiftwidth' on end, else, elseif, until, '}' and ')'70  " This is the part that requires 'indentkeys'.71  let midx = match(getline(v:lnum), '^\s*\%(end\>\|else\>\|elseif\>\|until\>\|}\|)\)')72  if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment"73    let ind = ind - shiftwidth()74  endif75 76  return ind77endfunction78 
codekingpro/portable-devtools · Team Ai