home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / mac / vim55rt.sit / runtime / syntax / xpm.vim < prev    next >
Encoding:
Text File  |  1999-09-25  |  3.9 KB  |  129 lines  |  [TEXT/VIM!]

  1. " Vim syntax file
  2. " Language:    X Pixmap
  3. " Maintainer:    Ronald Schild <rs@scutum.de>
  4. " Last change:    1999 Jul 05
  5. " Version:    5.4n.1
  6.  
  7. " Remove any old syntax stuff hanging around
  8. syn clear
  9.  
  10. syn keyword xpmType        char
  11. syn keyword xpmStorageClass    static
  12. syn keyword xpmTodo        TODO FIXME XXX  contained
  13. syn region  xpmComment        start="/\*"  end="\*/"  contains=xpmTodo
  14. syn region  xpmPixelString    start=+"+  skip=+\\\\\|\\"+  end=+"+  contains=@xpmColors
  15.  
  16. if has("gui_running")
  17.  
  18. let color  = ""
  19. let chars  = ""
  20. let colors = 0
  21. let cpp    = 0
  22. let n      = 0
  23. let i      = 1
  24.  
  25. while i <= line("$")        " scanning all lines
  26.  
  27.    let s = matchstr(getline(i), '".\{-1,}"')
  28.    if s != ""            " does line contain a string?
  29.  
  30.       if n == 0            " first string is the Values string
  31.  
  32.      " get the 3rd value: colors = number of colors
  33.      let colors = substitute(s, '"\s*\d\+\s\+\d\+\s\+\(\d\+\).*"', '\1', '')
  34.      " get the 4th value: cpp = number of character per pixel
  35.      let cpp = substitute(s, '"\s*\d\+\s\+\d\+\s\+\d\+\s\+\(\d\+\).*"', '\1', '')
  36.  
  37.      " highlight the Values string as normal string (no pixel string)
  38.      exe 'syn match xpmValues /'.s.'/'
  39.      hi link xpmValues String
  40.  
  41.      let n = 1        " n = color index
  42.  
  43.       elseif n <= colors    " string is a color specification
  44.  
  45.      " get chars = <cpp> length string representing the pixels
  46.      " (first incl. the following whitespace)
  47.      let chars = substitute(s, '"\(.\{'.cpp.'}\s\).*"', '\1', '')
  48.  
  49.      " now get color, first try 'c' key if any (color visual)
  50.      let color = substitute(s, '".*\sc\s\+\(.\{-}\)\s*\(\(g4\=\|[ms]\)\s.*\)*\s*"', '\1', '')
  51.      if color == s
  52.         " no 'c' key, try 'g' key (grayscale with more than 4 levels)
  53.         let color = substitute(s, '".*\sg\s\+\(.\{-}\)\s*\(\(g4\|[ms]\)\s.*\)*\s*"', '\1', '')
  54.         if color == s
  55.            " next try: 'g4' key (4-level grayscale)
  56.            let color = substitute(s, '".*\sg4\s\+\(.\{-}\)\s*\([ms]\s.*\)*\s*"', '\1', '')
  57.            if color == s
  58.           " finally try 'm' key (mono visual)
  59.           let color = substitute(s, '".*\sm\s\+\(.\{-}\)\s*\(s\s.*\)*\s*"', '\1', '')
  60.           if color == s
  61.              let color = ""
  62.           endif
  63.            endif
  64.         endif
  65.      endif
  66.  
  67.      " Vim cannot handle RGB codes with more than 6 hex digits
  68.      if color =~ '#\x\{10,}$'
  69.         let color = substitute(color, '\(\x\x\)\x\x', '\1', 'g')
  70.      elseif color =~ '#\x\{7,}$'
  71.         let color = substitute(color, '\(\x\x\)\x', '\1', 'g')
  72.      " nor with 3 digits
  73.      elseif color =~ '#\x\{3}$'
  74.         let color = substitute(color, '\(\x\)\(\x\)\(\x\)', '0\10\20\3', '')
  75.      endif
  76.  
  77.      " escape meta characters in patterns
  78.      let s = escape(s, '/\*^$.~[]')
  79.      let chars = escape(chars, '/\*^$.~[]')
  80.  
  81.      " now create syntax items
  82.      " highlight the color string as normal string (no pixel string)
  83.      exe 'syn match xpmCol'.n.'Def /'.s.'/ contains=xpmCol'.n.'inDef'
  84.      exe 'hi link xpmCol'.n.'Def String'
  85.  
  86.      " but highlight the first whitespace after chars in its color
  87.      exe 'syn match xpmCol'.n.'inDef /"'.chars.'/hs=s+'.(cpp+1).' contained'
  88.      exe 'hi link xpmCol'.n.'inDef xpmColor'.n
  89.  
  90.      " remove the following whitespace from chars
  91.      let chars = substitute(chars, '.$', '', '')
  92.  
  93.      " and create the syntax item contained in the pixel strings
  94.      exe 'syn match xpmColor'.n.' /'.chars.'/ contained'
  95.      exe 'syn cluster xpmColors add=xpmColor'.n
  96.  
  97.      " if no color or color = "None" show background
  98.      if color == ""  ||  substitute(color, '.*', '\L&', '') == 'none'
  99.         exe 'hi xpmColor'.n.' guifg=bg'
  100.         exe 'hi xpmColor'.n.' guibg=NONE'
  101.      else
  102.         exe 'hi xpmColor'.n." guifg='".color."'"
  103.         exe 'hi xpmColor'.n." guibg='".color."'"
  104.      endif
  105.      let n = n + 1
  106.       else
  107.      break        " no more color string
  108.       endif
  109.    endif
  110.    let i = i + 1
  111. endwhile
  112.  
  113. unlet color chars colors cpp n i s
  114.  
  115. endif        " has("gui_running")
  116.  
  117. if !exists("did_xpm_syntax_inits")
  118.    let did_xpm_syntax_inits = 1
  119.    hi link xpmType        Type
  120.    hi link xpmStorageClass    StorageClass
  121.    hi link xpmTodo        Todo
  122.    hi link xpmComment        Comment
  123.    hi link xpmPixelString    String
  124. endif
  125.  
  126. let b:current_syntax = "xpm"
  127.  
  128. " vim: ts=8:sw=3:noet:
  129.