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

  1. "  vim: set sw=4 sts=4:
  2. "  Maintainer    : Nikolai 'pcp' Weibull <da.box@home.se>
  3. "  Revised on    : Wed, 25 Jul 2001 21:19:41 CEST
  4. "  Language    : Cascading Style Sheets (CSS)
  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=GetCSSIndent()
  14. setlocal indentkeys-=:,0# indentkeys-=e
  15.  
  16. " Only define the function once.
  17. if exists("*GetCSSIndent")
  18.     finish
  19. endif
  20.  
  21. function! s:LookupLine(lnum)
  22.     " find a non-blank line above the current line
  23.     let lnum = prevnonblank(a:lnum - 1)
  24.  
  25.     if lnum == 0
  26.        return 0
  27.     endif
  28.  
  29.     let line = getline(lnum)
  30.  
  31.     " if the line has an end comment sequence we need to find a line
  32.     " that isn't affected by the comment.
  33.     if line =~ '\*/'
  34.     while line !~ '/\*'
  35.         let lnum = lnum - 1
  36.         let line = getline(lnum)
  37.     endwhile
  38.     endif
  39.  
  40.     " if the line we found only contained the comment and whitespace
  41.     " we need to find another line to use...
  42.     if line =~ '^\s*/\*'
  43.     return s:LookupLine(lnum)
  44.     else
  45.     return lnum
  46.     endif
  47. endfunction
  48.  
  49. function GetCSSIndent()
  50.     let lnum = s:LookupLine(v:lnum)
  51.  
  52.     if lnum == 0
  53.     return 0
  54.     endif
  55.  
  56.     " remove commented stuff from line
  57.     let line = substitute(getline(lnum), '/\*.\*/', '', 'eg')
  58.  
  59.     let ind = indent(lnum)
  60.  
  61.     " check for opening brace on the previous line
  62.     " skip if it also contains a closing brace...
  63.     if line =~ '{\(.*}\)\@!'
  64.        let ind = ind + &sw
  65.     endif
  66.  
  67.     let line = getline(v:lnum)
  68.  
  69.     " check for closing brace first on current line
  70.     if line =~ '^\s*}'
  71.     let ind    = ind - &sw
  72.     endif
  73.  
  74.     return ind
  75. endfunction
  76.