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

  1. " Description:    VisualBasic / SaxBasic indenter
  2. " Author:    Johannes Zellner <johannes@zellner.org>
  3. " URL:        http://www.zellner.org/vim/indent/vb.vim
  4. " Last Change:    Wed, 22 Aug 2001 16:31:30 W. Europe Standard Time
  5.  
  6. if exists("b:did_indent")
  7.     finish
  8. endif
  9. let b:did_indent = 1
  10.  
  11. setlocal indentexpr=VbGetIndent(v:lnum)
  12. setlocal indentkeys&
  13. setlocal indentkeys+==else,=Else,=end,=End,=wend,=Wend,=case,=Case,=next,=Next,=select,=Select,<:>
  14. " setlocal indentkeys-=0#
  15.  
  16. " Only define the function once.
  17. if exists("*VbGetIndent")
  18.     finish
  19. endif
  20.  
  21. fun! VbGetIndent(lnum)
  22.     " labels and preprocessor get zero indent immediately
  23.     let this_line = getline(a:lnum)
  24.     let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)'
  25.     if this_line =~? LABELS_OR_PREPROC
  26.     return 0
  27.     endif
  28.  
  29.     " Find a non-blank line above the current line.
  30.     " Skip over labels and preprocessor directives.
  31.     let lnum = a:lnum
  32.     while lnum > 0
  33.     let lnum = prevnonblank(lnum - 1)
  34.     let previous_line = getline(lnum)
  35.     if previous_line !~? LABELS_OR_PREPROC
  36.         break
  37.     endif
  38.     endwhile
  39.  
  40.     " Hit the start of the file, use zero indent.
  41.     if lnum == 0
  42.     return 0
  43.     endif
  44.  
  45.     let ind = indent(lnum)
  46.  
  47.     " Add
  48.     if previous_line =~? '^\s*\<\(begin\|\(private\s\+\)\=\(function\|sub\)\|select\|case\|default\|if\>.\{-}\<then\>\s*\|else\|do\|for\|while\)'
  49.     let ind = ind + &sw
  50.     endif
  51.  
  52.     " Subtract
  53.     if this_line =~? '^\s*\<end\>\s\+\<select\>'
  54.     if previous_line !~? '^\s*\<select\>'
  55.         let ind = ind - 2 * &sw
  56.     else
  57.         " this case is for an empty 'select' -- 'end select'
  58.         " (w/o any case statements) like:
  59.         "
  60.         " select case readwrite
  61.         " end select
  62.         let ind = ind - &sw
  63.     endif
  64.     elseif this_line =~? '^\s*\<\(end\|else\|until\|loop\|next\|wend\)'
  65.     let ind = ind - &sw
  66.     elseif this_line =~? '^\s*\<\(case\|default\)\>'
  67.     if previous_line !~? '^\s*\<select\>'
  68.         let ind = ind - &sw
  69.     endif
  70.     endif
  71.  
  72.     return ind
  73. endfun
  74.