home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim60.zip / vim60rt2.zip / vim / vim60 / indent / lua.vim < prev    next >
Text File  |  2001-09-26  |  2KB  |  53 lines

  1. " Vim indent file
  2. " Language: Lua script
  3. " Maintainer: Max Ischenko <mfi@ukr.net>
  4. " Last Change: 2001 Sep 02
  5.  
  6. " Only define the function once.
  7. if exists("*GetLuaIndent") | finish | endif
  8.  
  9. setlocal indentexpr=GetLuaIndent()
  10. setlocal autoindent
  11.  
  12. function! GetLuaIndent()
  13.   " Find a non-blank line above the current line.
  14.   let lnum = prevnonblank(v:lnum - 1)
  15.  
  16.   " Hit the start of the file, use zero indent.
  17.   if lnum == 0
  18.     return 0
  19.   endif
  20.  
  21.   " If the line trailed with a *, +, comma, . or (, trust the user
  22.   if getline(lnum) =~ '\(\*\|\.\|+\|,\|(\)\(\s*#.*\)\=$'
  23.         " return -1
  24.   endif
  25.  
  26.   " Add a 'shiftwidth' after lines beginning with:
  27.   " module, class, dev, if, for, while, until, else, elsif, case, when, {
  28.   let ind = indent(lnum)
  29.   let flag = 0
  30.   if getline(lnum) =~ '^\s*\(function\>\|if\>\|for\>\|while\>\|until\>\|else\>\|elsif\>\)' || getline(lnum) =~ '{\s*$' || getline(lnum) =~ '\({\|\<do\>\).*|.*|\s*$' || getline(lnum) =~ '\<do\>\(\s*#.*\)\=$' || getline(lnum) =~ '\(\s*=\s*function\)'
  31.     let ind = ind + &sw
  32.     let flag = 1
  33.   endif
  34.  
  35.   " Subtract a 'shiftwidth' after lines ending with
  36.   " "end" when they begin with while, if, for, until
  37.   if flag == 1 && getline(lnum) =~ '\<end\>\(\s*#.*\)\=$'
  38.     let ind = ind - &sw
  39.   endif
  40.  
  41.   " Subtract a 'shiftwidth' on end, else and, elsif, when and }
  42.   if getline(v:lnum) =~ '^\s*\(end\>\|else\>\|elsif\>\|}\)'
  43.     let ind = ind - &sw
  44.   endif
  45.  
  46.   " Subtract a 'shiftwidth' on end, else and, elsif, when and }
  47.   if getline(v:lnum) =~ '\(\<end\>\)'
  48.         " let ind = ind - &sw
  49.   endif
  50.  
  51.   return ind
  52. endfunction
  53.