chaiscript.vim 1.1 KB

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