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

  1. " Description:    InstallShield indenter
  2. " Author:    Johannes Zellner <johannes@zellner.org>
  3. " URL:        http://www.zellner.org/vim/indent/ishd.vim
  4. " Last Change:    Tue, 07 Aug 2001 14:49:42 W. Europe Standard Time
  5.  
  6. " Only load this indent file when no other was loaded.
  7. if exists("b:did_indent")
  8.     finish
  9. endif
  10. let b:did_indent = 1
  11.  
  12. setlocal indentexpr=GetIshdIndent(v:lnum)
  13. setlocal indentkeys+==else,=elseif,=endif,=end,=begin
  14. " setlocal indentkeys-=0#
  15.  
  16. " Only define the function once.
  17. if exists("*GetIshdIndent")
  18.     finish
  19. endif
  20.  
  21. fun! GetIshdIndent(lnum)
  22.     " labels and preprocessor get zero indent immediately
  23.     let this_line = getline(a:lnum)
  24.     if this_line =~ '^\s*\(\<\k\+\>:\s*$\|#.*\)'
  25.     return 0
  26.     endif
  27.  
  28.     " Find a non-blank line above the current line.
  29.     " Skip over labels and preprocessor directives.
  30.     let lnum = a:lnum
  31.     while lnum > 0
  32.     let lnum = prevnonblank(lnum - 1)
  33.     let previous_line = getline(lnum)
  34.     if previous_line !~ '^\(\s*\<\k\+\>:\s*$\|#.*\)'
  35.         break
  36.     endif
  37.     endwhile
  38.  
  39.     " Hit the start of the file, use zero indent.
  40.     if lnum == 0
  41.     return 0
  42.     endif
  43.  
  44.     let ind = indent(lnum)
  45.  
  46.     " Add
  47.     if previous_line =~ '^\s*\<\(function\|begin\|switch\|case\|default\|if.\{-}then\|else\|elseif\|while\|repeat\)\>'
  48.     let ind = ind + &sw
  49.     endif
  50.  
  51.     " Subtract
  52.     if this_line =~ '^\s*\<endswitch\>'
  53.     let ind = ind - 2 * &sw
  54.     elseif this_line =~ '^\s*\<\(begin\|end\|endif\|endwhile\|else\|elseif\|until\)\>'
  55.     let ind = ind - &sw
  56.     elseif this_line =~ '^\s*\<\(case\|default\)\>'
  57.     if previous_line !~ '^\s*\<switch\>'
  58.         let ind = ind - &sw
  59.     endif
  60.     endif
  61.  
  62.     return ind
  63. endfun
  64.