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

  1. " Vim indent file
  2. " Language:    Vim script
  3. " Maintainer:    Bram Moolenaar <Bram@vim.org>
  4. " Last Change:    2001 Aug 27
  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=GetVimIndent()
  13. setlocal indentkeys+==end,=else,0\\
  14.  
  15. " Only define the function once.
  16. if exists("*GetVimIndent")
  17.   finish
  18. endif
  19.  
  20. function GetVimIndent()
  21.   " Find a non-blank line above the current line.
  22.   let lnum = prevnonblank(v:lnum - 1)
  23.  
  24.   " If the current line doesn't start with '\' and below a line that starts
  25.   " with '\', use the indent of the line above it.
  26.   if getline(v:lnum) !~ '^\s*\\'
  27.     while lnum > 0 && getline(lnum) =~ '^\s*\\'
  28.       let lnum = lnum - 1
  29.     endwhile
  30.   endif
  31.  
  32.   " At the start of the file use zero indent.
  33.   if lnum == 0
  34.     return 0
  35.   endif
  36.  
  37.   " Add a 'shiftwidth' after :if, :while, :function and :else.
  38.   " Add it three times for a line that starts with '\' after a line that
  39.   " doesn't.
  40.   let ind = indent(lnum)
  41.   if getline(v:lnum) =~ '^\s*\\' && v:lnum > 1 && getline(lnum) !~ '^\s*\\'
  42.     let ind = ind + &sw * 3
  43.   elseif getline(lnum) =~ '^\s*\(if\>\|wh\|fu\|el\)'
  44.     let ind = ind + &sw
  45.   endif
  46.  
  47.   " Subtract a 'shiftwidth' on a :endif, :endwhile, :endfun and :else.
  48.   if getline(v:lnum) =~ '^\s*\(ene\@!\|el\)'
  49.     let ind = ind - &sw
  50.   endif
  51.  
  52.   return ind
  53. endfunction
  54.  
  55. " vim:sw=2
  56.