dylan.vim 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. " Vim indent file
  2. " Language: Dylan
  3. " Version: 0.01
  4. " Last Change: 2017 Jun 13
  5. " Maintainer: Brent A. Fulgham <bfulgham@debian.org>
  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 indentkeys+==~begin,=~block,=~case,=~cleanup,=~define,=~end,=~else,=~elseif,=~exception,=~for,=~finally,=~if,=~otherwise,=~select,=~unless,=~while
  12. " Define the appropriate indent function but only once
  13. setlocal indentexpr=DylanGetIndent()
  14. if exists("*DylanGetIndent")
  15. finish
  16. endif
  17. function DylanGetIndent()
  18. " Get the line to be indented
  19. let cline = getline(v:lnum)
  20. " Don't reindent comments on first column
  21. if cline =~ '^/\[/\*]'
  22. return 0
  23. endif
  24. "Find the previous non-blank line
  25. let lnum = prevnonblank(v:lnum - 1)
  26. "Use zero indent at the top of the file
  27. if lnum == 0
  28. return 0
  29. endif
  30. let prevline=getline(lnum)
  31. let ind = indent(lnum)
  32. let chg = 0
  33. " If previous line was a comment, use its indent
  34. if prevline =~ '^\s*//'
  35. return ind
  36. endif
  37. " If previous line was a 'define', indent
  38. if prevline =~? '\(^\s*\(begin\|block\|case\|define\|else\|elseif\|for\|finally\|if\|select\|unless\|while\)\|\s*\S*\s*=>$\)'
  39. let chg = shiftwidth()
  40. " local methods indent the shift-width, plus 6 for the 'local'
  41. elseif prevline =~? '^\s*local'
  42. let chg = shiftwidth() + 6
  43. " If previous line was a let with no closing semicolon, indent
  44. elseif prevline =~? '^\s*let.*[^;]\s*$'
  45. let chg = shiftwidth()
  46. " If previous line opened a parenthesis, and did not close it, indent
  47. elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
  48. return = match( prevline, '(.*\((.*)\|[^)]\)*.*$') + 1
  49. "elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
  50. elseif prevline =~ '^[^(]*)\s*$'
  51. " This line closes a parenthesis. Find opening
  52. let curr_line = prevnonblank(lnum - 1)
  53. while curr_line >= 0
  54. let str = getline(curr_line)
  55. if str !~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
  56. let curr_line = prevnonblank(curr_line - 1)
  57. else
  58. break
  59. endif
  60. endwhile
  61. if curr_line < 0
  62. return -1
  63. endif
  64. let ind = indent(curr_line)
  65. " Although we found the closing parenthesis, make sure this
  66. " line doesn't start with an indentable command:
  67. let curr_str = getline(curr_line)
  68. if curr_str =~? '^\s*\(begin\|block\|case\|define\|else\|elseif\|for\|finally\|if\|select\|unless\|while\)'
  69. let chg = shiftwidth()
  70. endif
  71. endif
  72. " If a line starts with end, un-indent (even if we just indented!)
  73. if cline =~? '^\s*\(cleanup\|end\|else\|elseif\|exception\|finally\|otherwise\)'
  74. let chg = chg - shiftwidth()
  75. endif
  76. return ind + chg
  77. endfunction
  78. " vim:sw=2 tw=130