hamster.vim 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. " Vim indent file
  2. " Language: Hamster Script
  3. " Version: 2.0.6.1
  4. " Last Change: 2021 Oct 11
  5. " Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
  6. " Download: https://www.vim.org/scripts/script.php?script_id=1099
  7. "
  8. " 2.0.6.1 (Oct 2021)
  9. " Added b:undo_indent
  10. " Added cpo check
  11. "
  12. " Only load this indent file when no other was loaded.
  13. if exists("b:did_indent")
  14. finish
  15. endif
  16. let b:did_indent = 1
  17. setlocal indentkeys+==~if,=~else,=~endif,=~endfor,=~endwhile
  18. setlocal indentkeys+==~do,=~until,=~while,=~repeat,=~for,=~loop
  19. setlocal indentkeys+==~sub,=~endsub
  20. let b:undo_indent = "setl indentkeys<"
  21. " Define the appropriate indent function but only once
  22. setlocal indentexpr=HamGetFreeIndent()
  23. if exists("*HamGetFreeIndent")
  24. finish
  25. endif
  26. let s:keepcpo = &cpo
  27. set cpo&vim
  28. function HamGetIndent(lnum)
  29. let ind = indent(a:lnum)
  30. let prevline=getline(a:lnum)
  31. " Add a shiftwidth to statements following if, else, elseif,
  32. " case, select, default, do, until, while, for, start
  33. if prevline =~? '^\s*\<\(if\|else\%(if\)\?\|for\|repeat\|do\|while\|sub\)\>'
  34. let ind = ind + shiftwidth()
  35. endif
  36. " Subtract a shiftwidth from else, elseif, end(if|while|for), until
  37. let line = getline(v:lnum)
  38. if line =~? '^\s*\(else\|elseif\|loop\|until\|end\%(if\|while\|for\|sub\)\)\>'
  39. let ind = ind - shiftwidth()
  40. endif
  41. return ind
  42. endfunction
  43. function HamGetFreeIndent()
  44. " Find the previous non-blank line
  45. let lnum = prevnonblank(v:lnum - 1)
  46. " Use zero indent at the top of the file
  47. if lnum == 0
  48. return 0
  49. endif
  50. let ind=HamGetIndent(lnum)
  51. return ind
  52. endfunction
  53. " Restore:
  54. let &cpo = s:keepcpo
  55. unlet s:keepcpo
  56. " vim:sw=2 tw=80