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 / runtime / indent / hamster.vim < prev    next >
Encoding:
Text File  |  2010-08-15  |  1.4 KB  |  56 lines

  1. " Vim indent file
  2. " Language:    Hamster Script 
  3. " Version:     2.0.6.0
  4. " Last Change: Wed Nov 08 2006 12:02:42 PM
  5. " Maintainer:  David Fishburn <fishburn@ianywhere.com>
  6.  
  7. " Only load this indent file when no other was loaded.
  8. if exists("b:did_indent")
  9.   finish
  10. endif
  11. let b:did_indent = 1
  12.  
  13. setlocal indentkeys+==~if,=~else,=~endif,=~endfor,=~endwhile
  14. setlocal indentkeys+==~do,=~until,=~while,=~repeat,=~for,=~loop
  15. setlocal indentkeys+==~sub,=~endsub
  16.  
  17. " Define the appropriate indent function but only once
  18. setlocal indentexpr=HamGetFreeIndent()
  19. if exists("*HamGetFreeIndent")
  20.   finish
  21. endif
  22.  
  23. function HamGetIndent(lnum)
  24.   let ind = indent(a:lnum)
  25.   let prevline=getline(a:lnum)
  26.  
  27.   " Add a shiftwidth to statements following if,  else, elseif,
  28.   " case, select, default, do, until, while, for, start
  29.   if prevline =~? '^\s*\<\(if\|else\%(if\)\?\|for\|repeat\|do\|while\|sub\)\>' 
  30.     let ind = ind + &sw
  31.   endif
  32.  
  33.   " Subtract a shiftwidth from else, elseif, end(if|while|for), until
  34.   let line = getline(v:lnum)
  35.   if line =~? '^\s*\(else\|elseif\|loop\|until\|end\%(if\|while\|for\|sub\)\)\>'
  36.     let ind = ind - &sw
  37.   endif
  38.  
  39.   return ind
  40. endfunction
  41.  
  42. function HamGetFreeIndent()
  43.   " Find the previous non-blank line
  44.   let lnum = prevnonblank(v:lnum - 1)
  45.  
  46.   " Use zero indent at the top of the file
  47.   if lnum == 0
  48.     return 0
  49.   endif
  50.  
  51.   let ind=HamGetIndent(lnum)
  52.   return ind
  53. endfunction
  54.  
  55. " vim:sw=2 tw=80
  56.