home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / indent / eiffel.vim < prev    next >
Encoding:
Text File  |  2003-04-25  |  2.9 KB  |  107 lines

  1. " Vim indent file
  2. " Language:    Eiffel
  3. " Maintainer:    David Clarke <gadicath@dishevelled.net>
  4. " $Date: 2002/05/15 07:01:50 $
  5. " $Revision: 1.19 $
  6. " URL: http://gadicath.webhop.net/other/eiffel.vim
  7.  
  8. " Only load this indent file when no other was loaded.
  9. if exists("b:did_indent")
  10.   finish
  11. endif
  12. let b:did_indent = 1
  13.  
  14. setlocal indentexpr=GetEiffelIndent()
  15. setlocal nolisp
  16. setlocal nosmartindent
  17. setlocal nocindent
  18. setlocal autoindent
  19. setlocal comments=:--
  20. setlocal indentkeys+==end,=else,=ensure,=require,=check,=loop,=until
  21. setlocal indentkeys+==creation,=feature,=inherit,=class,=is,=redefine,=rename,=variant
  22. setlocal indentkeys+==invariant,=do,=local,=export
  23. setlocal sw=3
  24. setlocal tw=78
  25.  
  26. " Define some stuff
  27. " keywords grouped by indenting
  28. let s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$'
  29. let s:relative_indent = '^\s*\(deferred\|class\|feature\|creation\|inherit\|loop\|from\|until\|if\|else\|elseif\|ensure\|require\|check\|do\|local\|invariant\|variant\|rename\|redefine\|do\|export\)\>'
  30. let s:outdent = '^\s*\(else\|invariant\|variant\|do\|require\|until\|loop\|local\)\>'
  31. let s:no_indent = '^\s*\(class\|feature\|creation\|inherit\)\>'
  32. let s:single_dent = '^[^-]\+[[:alnum:]]\+ is\(\s*\(--\).*\)\=$'
  33. let s:inheritance_dent = '\s*\(redefine\|rename\|export\)\>'
  34.  
  35.  
  36. " Only define the function once.
  37. if exists("*GetEiffelIndent")
  38.   finish
  39. endif
  40.  
  41. function GetEiffelIndent()
  42.  
  43.   " Eiffel Class indenting
  44.   "
  45.   " Find a non-blank line above the current line.
  46.   let lnum = prevnonblank(v:lnum - 1)
  47.  
  48.   " At the start of the file use zero indent.
  49.   if lnum == 0
  50.     return 0
  51.   endif
  52.  
  53.   " trust the user's indenting
  54.   if getline(lnum) =~ s:trust_user_indent
  55.     return -1
  56.   endif
  57.  
  58.   " Add a 'shiftwidth' after lines that start with an indent word
  59.   let ind = indent(lnum)
  60.   if getline(lnum) =~ s:relative_indent
  61.     let ind = ind + &sw
  62.   endif
  63.  
  64.   " Indent to single indent
  65.   if getline(v:lnum) =~ s:single_dent && getline(v:lnum) !~ s:relative_indent
  66.        \ && getline(v:lnum) !~ '\s*\<\(and\|or\|implies\)\>'
  67.      let ind = &sw
  68.   endif
  69.  
  70.   " Indent to double indent
  71.   if getline(v:lnum) =~ s:inheritance_dent
  72.      let ind = 2 * &sw
  73.   endif
  74.  
  75.   " Indent line after the first line of the function definition
  76.   if getline(lnum) =~ s:single_dent
  77.      let ind = ind + &sw
  78.   endif
  79.  
  80.   " The following should always be at the start of a line, no indenting
  81.   if getline(v:lnum) =~ s:no_indent
  82.      let ind = 0
  83.   endif
  84.  
  85.   " Subtract a 'shiftwidth', if this isn't the first thing after the 'is'
  86.   " or first thing after the 'do'
  87.   if getline(v:lnum) =~ s:outdent && getline(v:lnum - 1) !~ s:single_dent
  88.     \ && getline(v:lnum - 1) !~ '^\s*do\>'
  89.     let ind = ind - &sw
  90.   endif
  91.  
  92.   " Subtract a shiftwidth for end statements
  93.   if getline(v:lnum) =~ '^\s*end\>'
  94.     let ind = ind - &sw
  95.   endif
  96.  
  97.   " set indent of zero end statements that are at an indent of 3, this should
  98.   " only ever be the class's end.
  99.   if getline(v:lnum) =~ '^\s*end\>' && ind == 3
  100.     let ind = 0
  101.   endif
  102.  
  103.   return ind
  104. endfunction
  105.  
  106. " vim:sw=2
  107.