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 / runtime / indent / chaiscript.vim < prev    next >
Encoding:
Text File  |  2010-08-14  |  1.1 KB  |  51 lines

  1. " Vim indent file
  2. " Language:     ChaiScript
  3. " Maintainer:    Jason Turner <lefticus 'at' gmail com>
  4.  
  5. " Only load this indent file when no other was loaded.
  6. if exists("b:did_indent")
  7.   finish
  8. endif
  9. let b:did_indent = 1
  10.  
  11. setlocal indentexpr=GetChaiScriptIndent()
  12. setlocal autoindent
  13.  
  14. " Only define the function once.
  15. if exists("*GetChaiScriptIndent")
  16.   finish
  17. endif
  18.  
  19. function! GetChaiScriptIndent()
  20.   " Find a non-blank line above the current line.
  21.   let lnum = prevnonblank(v:lnum - 1)
  22.  
  23.   " Hit the start of the file, use zero indent.
  24.   if lnum == 0
  25.     return 0
  26.   endif
  27.  
  28.   " Add a 'shiftwidth' after lines that start a block:
  29.   " lines containing a {
  30.   let ind = indent(lnum)
  31.   let flag = 0
  32.   let prevline = getline(lnum)
  33.   if prevline =~ '^.*{.*'
  34.     let ind = ind + &shiftwidth
  35.     let flag = 1
  36.   endif
  37.  
  38.   " Subtract a 'shiftwidth' after lines containing a { followed by a }
  39.   " to keep it balanced
  40.   if flag == 1 && prevline =~ '.*{.*}.*'
  41.     let ind = ind - &shiftwidth
  42.   endif
  43.  
  44.   " Subtract a 'shiftwidth' on lines ending with }
  45.   if getline(v:lnum) =~ '^\s*\%(}\)'
  46.     let ind = ind - &shiftwidth
  47.   endif
  48.  
  49.   return ind
  50. endfunction
  51.