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

  1. " Maintainer    : Nikolai 'pcp' Weibull <da.box@home.se>
  2. " URL        : http://www.pcppopper.org/
  3. " Revised on    : Tue, 28 Aug 2001 14:38:52 +0200
  4. " Language    : readline configuration file
  5.  
  6. " Only load this indent file when no other was loaded.
  7. if exists("b:did_indent")
  8.     finish
  9. endif
  10.  
  11. let b:did_indent = 1
  12.  
  13. setlocal indentexpr=GetReadlineIndent()
  14. setlocal indentkeys=!^F,o,O,=$else,=$endif
  15.  
  16. " Only define the function once.
  17. if exists("*GetReadlineIndent")
  18.     finish
  19. endif
  20.  
  21. function GetReadlineIndent()
  22.     let lnum = prevnonblank(v:lnum - 1)
  23.  
  24.     if lnum == 0
  25.     return 0
  26.     endif
  27.  
  28.     let line    = getline(lnum)
  29.     let ind    = indent(lnum)
  30.  
  31.     " increase indent if previous line started with $if or $else
  32.     if  line =~ '^\s*$\(if\|else\)\>'
  33.     let ind = ind + &sw
  34.     endif
  35.  
  36.     let line    = getline(v:lnum)
  37.  
  38.     " decrease indent if this line starts with $else or $endif
  39.     if line =~ '^\s*$\(else\|endif\)\>'
  40.     let ind = ind - &sw
  41.     endif
  42.  
  43.     return ind
  44. endfunction
  45.  
  46. " vim: set sw=4 sts=4:
  47.  
  48.