Copy the following to ~/.vim/indent/esterel.vim. Presto, automatic indentation for your Esterel code (gg=G to indent all, as usual). Syntax highlighting for Esterel is included already. <pre> " Vim indent file " Language: Shell Script " Maintainer: Saurabh Joshi <sbjoshi[at]gmail.com> " URL: " Latest Revision: 2007-01-12
" Only load this indent file when no other was loaded. if exists("b:did_indent")
finish
endif
let b:did_indent = 1 setlocal indentexpr=GetShIndent() setlocal indentkeys+==then,=else,=when setlocal indentkeys+==every,=loop,=end,=var,=sustain,=suspend,=present setlocal indentkeys+==trap,=end,=weak,=input,=output,=function,=relation,=sensor setlocal indentkeys-=:,0#
setlocal shiftwidth=4
" Only define the function once. if exists("*GetShIndent")
finish
endif
set cpoptions-=C
function GetShIndent()
" Find a non-blank line above the current line. let lnum = prevnonblank(v:lnum - 1)
" Hit the start of the file, use zero indent. if lnum == 0
return 0
endif
" Add a 'shiftwidth' after if, while, else, case, until, for, function() " Skip if the line also contains the closure for the above let ind = indent(lnum) let line = getline(lnum) if ((line =~ '\s*\(if\|loop\|sustain\|suspend\|var\|trap\|when\|every\|signal\|present\|then\|do\|weak abort\|abort\|else\)\>'
\ line =~ '\s*\<\h\w*\>\s*()\s*{' \ line =~ '\s*{' \ line =~ '\s*[' \ line =~ '\s* ' \ line =~ '\sdo$') \&& line !~ '\s*\(end\|esac\|fi\|done\|when\)\>\s*$' && line !~ '}\s*$' && line !~ ']\s*$')
let ind = ind + &sw
endif if ((line =~ '\s*when\s' && line !~ '\sdo\s*$')
\ line =~ '\s*\(input\|output\|relation\|function\|sensor\)\s') let ind = ind - &sw
endif
" Subtract a 'shiftwidth' on a then, do, else, esac, fi, done " Retain the indentation level if line matches fin (for find) let line = getline(v:lnum)
if (line =~ '\s*\(input\|output\|relation\|function\|sensor\)\s')
let ind = ind + &sw
endif
if (line =~ '\s*\(then\|do\|else\|when\|end\)\>' line =~ '\s*}' line =~ '\s*]' line =~ '\s* ') let ind = ind - &sw
endif if (line =~ '\s*when\s' && line !~ '\sdo\s*$')
let ind = ind - &sw
endif
return ind
endfunction
" vim: set sts=2 sw=2: </pre> ~