rpl.vim 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. " Vim indent file
  2. " Language: RPL/2
  3. " Version: 0.2
  4. " Last Change: 2017 Jun 13
  5. " Maintainer: BERTRAND Joël <rpl2@free.fr>
  6. " Only load this indent file when no other was loaded.
  7. if exists("b:did_indent")
  8. finish
  9. endif
  10. let b:did_indent = 1
  11. setlocal autoindent
  12. setlocal indentkeys+==~end,=~case,=~if,=~then,=~else,=~do,=~until,=~while,=~repeat,=~select,=~default,=~for,=~start,=~next,=~step,<<>,<>>
  13. " Define the appropriate indent function but only once
  14. setlocal indentexpr=RplGetFreeIndent()
  15. if exists("*RplGetFreeIndent")
  16. finish
  17. endif
  18. let b:undo_indent = "set ai< indentkeys< indentexpr<"
  19. function RplGetIndent(lnum)
  20. let ind = indent(a:lnum)
  21. let prevline=getline(a:lnum)
  22. " Strip tail comment
  23. let prevstat=substitute(prevline, '!.*$', '', '')
  24. " Add a shiftwidth to statements following if, iferr, then, else, elseif,
  25. " case, select, default, do, until, while, repeat, for, start
  26. if prevstat =~? '\<\(if\|iferr\|do\|while\)\>' && prevstat =~? '\<end\>'
  27. elseif prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)' && prevstat =~? '\s\+>>\($\|\s\+\)'
  28. elseif prevstat =~? '\<\(if\|iferr\|then\|else\|elseif\|select\|case\|do\|until\|while\|repeat\|for\|start\|default\)\>' || prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)'
  29. let ind = ind + shiftwidth()
  30. endif
  31. " Subtract a shiftwidth from then, else, elseif, end, until, repeat, next,
  32. " step
  33. let line = getline(v:lnum)
  34. if line =~? '^\s*\(then\|else\|elseif\|until\|repeat\|next\|step\|default\|end\)\>'
  35. let ind = ind - shiftwidth()
  36. elseif line =~? '^\s*>>\($\|\s\+\)'
  37. let ind = ind - shiftwidth()
  38. endif
  39. return ind
  40. endfunction
  41. function RplGetFreeIndent()
  42. " Find the previous non-blank line
  43. let lnum = prevnonblank(v:lnum - 1)
  44. " Use zero indent at the top of the file
  45. if lnum == 0
  46. return 0
  47. endif
  48. let ind=RplGetIndent(lnum)
  49. return ind
  50. endfunction
  51. " vim:sw=2 tw=130