obse.vim 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. " Vim indent file
  2. " Language: Oblivion Language (obl)
  3. " Original Creator: Kat <katisntgood@gmail.com>
  4. " Maintainer: Kat <katisntgood@gmail.com>
  5. " Created: 01 November 2021
  6. " Last Change: 13 November 2022
  7. if exists("b:did_indent")
  8. finish
  9. endif
  10. let b:did_indent = 1
  11. let b:undo_indent = 'setlocal indentkeys< indentexpr<'
  12. setlocal indentexpr=GetOblIndent()
  13. setlocal indentkeys+==~endif,=~else,=~loop,=~end
  14. if exists("*GetOblIndent")
  15. finish
  16. endif
  17. let s:keepcpo = &cpo
  18. set cpo&vim
  19. let s:SKIP_LINES = '^\s*\(;.*\)'
  20. function! GetOblIndent()
  21. let lnum = prevnonblank(v:lnum - 1)
  22. let cur_text = getline(v:lnum)
  23. if lnum == 0
  24. return 0
  25. endif
  26. let prev_text = getline(lnum)
  27. let found_cont = 0
  28. let ind = indent(lnum)
  29. " indent next line on start terms
  30. let i = match(prev_text, '\c^\s*\(\s\+\)\?\(\(if\|while\|foreach\|begin\|else\%[if]\)\>\)')
  31. if i >= 0
  32. let ind += shiftwidth()
  33. if strpart(prev_text, i, 1) == '|' && has('syntax_items')
  34. \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\)$'
  35. let ind -= shiftwidth()
  36. endif
  37. endif
  38. " indent current line on end/else terms
  39. if cur_text =~ '\c^\s*\(\s\+\)\?\(\(loop\|endif\|else\%[if]\)\>\)'
  40. let ind = ind - shiftwidth()
  41. " if we are at a begin block just go to column 0
  42. elseif cur_text =~ '\c^\s*\(\s\+\)\?\(\(begin\|end\)\>\)'
  43. let ind = 0
  44. endif
  45. return ind
  46. endfunction
  47. let &cpo = s:keepcpo
  48. unlet s:keepcpo