" Vim indent file " Language: Refal " Maintainer: Anton Orlov " Last Change: Fri Jul 20 13:58:35 MSD 2001 " Only load this indent file when no other was loaded. if exists("b:did_indent") finish endif let b:did_indent = 1 setlocal indentexpr=GetRefalIndent() setlocal indentkeys+=} " Only define the function once. if exists("*GetRefalIndent") finish endif " This function gets indentation level relative to an outer block and returns " present indent or -1 if outer block doesn't exist. function! s:ComputeIndent(shift) " echomsg "πΟΕΘΑΜΙ..." v:lnum let lnum = search('^\S', 'bW') while lnum > 0 && synIDattr(synID(lnum, 1, 0), "name") !~ "Symbol" let lnum = search('^\S', 'bW') endwhile if lnum == 0 let lnum = 1 endif " echomsg "lnum =" lnum let open_brs = 0 if getline(v:lnum) =~ "}$" let close_brs = -1 else let close_brs = 0 endif " exec "normal " . lnum . "G^" exec lnum while search('{', 'W') && line(".") < v:lnum if synIDattr(synID(line("."), col("."), 0), "name") !~ "Symbol\\|Comment" let open_brs = open_brs + 1 endif endwhile " exec "normal " . lnum . "G^" exec lnum while search('}', 'W') && line(".") <= v:lnum if synIDattr(synID(line("."), col("."), 0), "name") !~ "Symbol\\|Comment" let close_brs = close_brs + 1 endif endwhile " echomsg "open_brs =" open_brs " echomsg "close_brs =" close_brs if open_brs > close_brs " exec "normal " . v:lnum . "G$" exec v:lnum let block_start = searchpair('{', '', '}', 'bW', \ 'synIDattr(synID(line("."), col("."), 0), "name") =~ "Symbol\\|Comment"') if block_start > 0 " exec "normal " . s:top_line . "G^" " exec "normal " . s:bot_line . "G^" return indent(block_start) + a:shift * &sw endif endif " echo search('\%$') " exec "normal " . s:top_line . "G^" " exec "normal " . s:bot_line . "G^" if a:shift > 0 return (a:shift - 1) * &sw endif return -1 endfunction function! GetRefalIndent() " normal H " let s:top_line = line(".") " normal L " let s:bot_line = line(".") " echomsg s:top_line s:bot_line " For closing brace use indentation of outer block (i.e. opening brace). if getline(v:lnum) =~ '^[}[:blank:]]*}' " normal h " echomsg "}" return s:ComputeIndent(0) endif " Find a non-blank line above the current line. let lnum = prevnonblank(v:lnum - 1) let prev_line = getline(lnum) " " If previous line was begining of a function definition then indent by one. " if prev_line !~ ';\s*$' && synIDattr(synID(lnum, 1, 0), "name") =~ "Symbol" " return &sw " endif " After opening brace always increase indentation by one. if prev_line =~ '{\s*$' && \ synIDattr(synID(lnum, strlen(getline(lnum)), 0), "name") !~ \ "Symbol\\|Comment" " echomsg "{" return indent(lnum) + &sw endif " Shift new sentence by one from outer block. if prev_line =~ ';\s*$' return s:ComputeIndent(1) endif " Shift continuing of a sentence by two. if prev_line =~ '[=,]\|\\!\|\\?\s*$' return s:ComputeIndent(2) endif " Leave everything else as is. return -1 endfunction " vim:sw=2 ts=2 et