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

  1. " Vim indent file
  2. " Language:    Perl
  3. " Author:    Rafael Garcia-Suarez <rgarciasuarez@free.fr>
  4. " URL:        http://rgarciasuarez.free.fr/vim/indent/perl.vim
  5. " Last Change:    2001 Sep 03
  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 indentexpr=GetPerlIndent()
  14. setlocal indentkeys+=0=,0),=EO,=or,=and
  15.  
  16. " Only define the function once.
  17. if exists("*GetPerlIndent")
  18.   finish
  19. endif
  20.  
  21. function GetPerlIndent()
  22.   " Get the line to be indented
  23.   let cline = getline(v:lnum)
  24.  
  25.   " Don't indent POD markers ; don't indent end-of-heredocs markers
  26.   " (assuming they begin with 'EO')
  27.   if cline =~ '^\s*\(=\|EO\)'
  28.     return 0
  29.   endif
  30.  
  31.   " Find a non-blank line above the current line.
  32.   let lnum = prevnonblank(v:lnum - 1)
  33.   " Hit the start of the file, use zero indent.
  34.   if lnum == 0
  35.     return 0
  36.   endif
  37.   let line = getline(lnum)
  38.   let ind = indent(lnum)
  39.  
  40.   " Indent to column 0 if previous line contains <<XXX
  41.   if line =~ "<<[\"']*\\u\\+"
  42.     return 0
  43.   endif
  44.   " Find the indent of the first line before the beginning of a here-doc
  45.   if line =~ '^EO'
  46.     let lnum = search("<<[\"']*EO", "bW")
  47.     let line = getline(lnum)
  48.     let ind = indent(lnum)
  49.   endif
  50.   " Indent blocks enclosed by {} or ()
  51.   if line =~ '[{(]\s*\(#[^)}]*\)\=$'
  52.     let ind = ind + &sw
  53.   endif
  54.   if cline =~ '^\s*[)}]'
  55.     let ind = ind - &sw
  56.   endif
  57.   " Indent lines that begin with 'or' or 'and'
  58.   if cline =~ '^\s*\(or\|and\)\>'
  59.     if line !~ '^\s*\(or\|and\)\>'
  60.       let ind = ind + &sw
  61.     endif
  62.   elseif line =~ '^\s*\(or\|and\)\>'
  63.     let ind = ind - &sw
  64.   endif
  65.   " Don't indent comments
  66.   if line =~ '^\s*#'
  67.     return ind
  68.   endif
  69.  
  70.   return ind
  71. endfunction
  72.