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