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