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