" Vim indent file " Language: Forth " Maintainer: Dick van Oudheusden " Created: 17 Aug 2008 " Last Change: 17 Aug 2008 " ToDo: single line constructions if exists("b:did_indent") finish endif let b:did_indent = 1 setlocal ignorecase setlocal indentexpr=GetForthIndent(v:lnum) setlocal indentkeys=;,0<:>,o,O setlocal indentkeys+==~IF,=~ELSE,=~THEN,=~CASE,=~ENDCASE setlocal indentkeys+==~BEGIN,=~DO,=~?DO,=~WHILE,=~REPEAT,=~UNTIL,=~AGAIN,=~DO,=~LOOP,=~+LOOP setlocal indentkeys+==~BEGIN-STRUCTURE,=~END-STRUCTURE if exists("*GetForthIndent") finish endif function! s:GetPrevNonComment(line_num) let SKIP = '^\s*\<[(\\]\>' let nline = a:line_num while nline > 0 let nline = prevnonblank(nline-1) if getline(nline) !~ SKIP break endif endwhile return nline endfunction function! GetForthIndent(line_num) " Line 0 always goes at column 0 if a:line_num == 0 return 0 endif let this_codeline = getline(a:line_num) let prev_codeline_num = s:GetPrevNonComment(a:line_num) let prev_codeline = getline(prev_codeline_num) let indnt = indent(prev_codeline_num) " Indent lines if previous line contains if,else,do,begin,while,?do,: " if prev_codeline =~ '^.*\<\(if\|else\|do\|while\|?do\|:\)\>' if prev_codeline =~ '^.*\<\(IF\|ELSE\|DO\|WHILE\|BEGIN\|CASE\|BEGIN-STRUCTURE\|?DO\|:\)\>' let indnt = indnt + &shiftwidth endif " Unindent lines starting with else,then,while,repeat,until,again,loop,+loop if this_codeline =~ '^\s*\<\(ELSE\|THEN\|WHILE\|REPEAT\|UNTIL\|AGAIN\|ENDCASE\|END-STRUCTURE\|LOOP\|;\)\>' let indnt = indnt - &shiftwidth endif " Unindent lines with +loop if this_codeline =~ '^.*\<+LOOP\>' let indnt = indnt - &shiftwidth endif " Unindent line with previous line ; if prev_codeline =~ '^.*\<;\>' let indnt = indnt - &shiftwidth endif return indnt endfunction