home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim60.zip / vim60rt2.zip / vim / vim60 / indent / ocaml.vim < prev    next >
Text File  |  2001-09-26  |  3KB  |  103 lines

  1. " Vim indent file
  2. " Language:     OCaml
  3. " Maintainers:  Mike Leary    <leary@nwlink.com>
  4. "               Markus Mottl  <markus@oefai.at>
  5. " URL:          http://www.ai.univie.ac.at/~markus/vim/indent/ocaml.vim
  6. " Last Change:  2001 Sep 02 - set option 'expandtab'  (MM)
  7. "               2001 Aug 29 - revised all rules  (MM)
  8.  
  9. " Only load this indent file when no other was loaded.
  10. if exists("b:did_indent")
  11.   finish
  12. endif
  13. let b:did_indent = 1
  14.  
  15. setlocal expandtab
  16. setlocal indentexpr=GetOCamlIndent()
  17. setlocal indentkeys+=0=done,0=end,0=if,0=then,0=else,0=and,0=in,0=with,0=>],0=\|],0},0],0)
  18. setlocal nolisp
  19. setlocal nosmartindent
  20. setlocal textwidth=80
  21.  
  22. " Only define the function once.
  23. if exists("*GetOCamlIndent")
  24.   finish
  25. endif
  26.  
  27. function GetOCamlIndent()
  28.   " Find a non-blank line above the current line.
  29.   let lnum = prevnonblank(v:lnum - 1)
  30.  
  31.   " At the start of the file use zero indent.
  32.   if lnum == 0
  33.     return 0
  34.   endif
  35.  
  36.   let ind=indent(lnum)
  37.   let lline=getline(lnum)
  38.  
  39.   " Return double 'shiftwidth' after lines matching:
  40.   if lline =~ '^\s*|.*->\s*$'
  41.     return ind + &sw + &sw
  42.   endif
  43.  
  44.   " Add a 'shiftwidth' after lines ending with:
  45.   if lline =~ '\(:\|=\|->\|(\|[\|{\|[|\|[<\|(\*\|\<\(begin\|struct\|sig\|functor\|object\|try\|do\|if\|then\|else\|fun\|function\|parser\)\>\)\s*$'
  46.     let ind = ind + &sw
  47.   endif
  48.  
  49.   let line=getline(v:lnum)
  50.  
  51.   " Subtract a 'shiftwidth' if current line begins with:
  52.   if line =~ '^\s*\(\(done\|end\)\>\|>]\||]\|}\|]\|)\)'
  53.     return ind - &sw
  54.  
  55.   " Subtract a 'shiftwidth' if current line begins with 'if' and last
  56.   " line ends with 'else':
  57.   elseif line =~ '^\s*if\>'
  58.     if lline =~ '\<else\s*$'
  59.       return ind - &sw
  60.     else return ind
  61.     endif
  62.  
  63.   " Subtract a 'shiftwidth' if current line begins with 'in' and last
  64.   " line does not start with 'let' or 'and':
  65.   elseif line =~ '^\s*in\>'
  66.     if lline !~ '^\s*\(let\|and\)\>'
  67.       return ind - &sw
  68.     else return ind
  69.     endif
  70.  
  71.   " Subtract a 'shiftwidth' if current line begins with 'else' or 'then'
  72.   " and previous line does not start with 'if', 'then' or 'else'
  73.   elseif line =~ '^\s*\(else\|then\)\>'
  74.     if lline !~ '^\s*\(if\|else\|then\)\>'
  75.       return ind - &sw
  76.     else return ind
  77.     endif
  78.  
  79.   " Subtract a 'shiftwidth' if current line begins with 'and' and previous
  80.   " line does not start with 'let', 'and' or 'type' or end with 'end'
  81.   " (for classes):
  82.   elseif line =~ '^\s*and\>'
  83.     if lline !~ '^\s*\(let\|and\|type\)\>\|\<end\s*$'
  84.       return ind - &sw
  85.     else return ind
  86.     endif
  87.  
  88.   " Subtract a 'shiftwidth' if current line begins with 'with'
  89.   " and previous line does not start with 'match' or 'try':
  90.   elseif line =~ '^\s*with\>'
  91.     if lline !~ '^\s*\(match\|try\)\>'
  92.       return ind - &sw
  93.     else return ind
  94.     endif
  95.  
  96.   endif
  97.  
  98.   return ind
  99.  
  100. endfunction
  101.  
  102. " vim:sw=2
  103.