dylan.vim 2.7 KB

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