home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / indent / lua.vim < prev    next >
Encoding:
Text File  |  2003-01-20  |  1.4 KB  |  50 lines

  1. " Vim indent file
  2. " Language:    Lua script
  3. " Maintainer:    Marcus Aurelius Farias <marcuscf@vant.com.br>
  4. " First Author:    Max Ischenko <mfi@ukr.net>
  5. " Last Change:    2003 Jan 20
  6.  
  7. " Only define the function once.
  8. if exists("*GetLuaIndent") | finish | endif
  9.  
  10. setlocal indentexpr=GetLuaIndent()
  11.  
  12. " To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until'
  13. " on the current line (else is default).
  14. setlocal indentkeys+=0=end,0=until
  15.  
  16. setlocal autoindent
  17.  
  18. function! GetLuaIndent()
  19.   " Find a non-blank line above the current line.
  20.   let lnum = prevnonblank(v:lnum - 1)
  21.  
  22.   " Hit the start of the file, use zero indent.
  23.   if lnum == 0
  24.     return 0
  25.   endif
  26.  
  27.   " Add a 'shiftwidth' after lines beginning with:
  28.   " function, if, for, while, repeat, else, elseif, '{'
  29.   let ind = indent(lnum)
  30.   let flag = 0
  31.   if getline(lnum) =~ '^\s*\(function\>\|if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\)' || getline(lnum) =~ '{\s*$' || getline(lnum) =~ '\s*=\s*function'
  32.     let ind = ind + &sw
  33.     let flag = 1
  34.   endif
  35.  
  36.   " Subtract a 'shiftwidth' after lines ending with
  37.   " 'end' when they begin with while, if, for, etc.
  38.   if flag == 1 && getline(lnum) =~ '\<end\>\|\<until\>'
  39.     let ind = ind - &sw
  40.   endif
  41.  
  42.   " Subtract a 'shiftwidth' on end, else (and elseif), until and '}'
  43.   " This is the part that requires 'indentkeys'.
  44.   if getline(v:lnum) =~ '^\s*\(end\|else\|until\|}\)'
  45.     let ind = ind - &sw
  46.   endif
  47.  
  48.   return ind
  49. endfunction
  50.