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