Mercurial > hg > RemoteEditor > vim7
annotate runtime/syntax/xpm.vim @ 49:000769ce6c9d default tip
Added tag v7-3-618 for changeset 67300faee616
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 01 Aug 2012 18:08:37 +0900 |
parents | e170173ecb68 |
children |
rev | line source |
---|---|
0 | 1 " Vim syntax file |
2 " Language: X Pixmap | |
3 " Maintainer: Ronald Schild <rs@scutum.de> | |
34
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
4 " Last Change: 2008 May 28 |
0 | 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', '') | |
34
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
41 if cpp =~ '[^0-9]' |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
42 break " if cpp is not made of digits there must be something wrong |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
43 endif |
0 | 44 |
34
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
45 " Highlight the Values string as normal string (no pixel string). |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
46 " Only when there is no slash, it would terminate the pattern. |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
47 if s !~ '/' |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
48 exe 'syn match xpmValues /' . s . '/' |
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
49 endif |
0 | 50 hi link xpmValues String |
51 | |
52 let n = 1 " n = color index | |
53 | |
54 elseif n <= colors " string is a color specification | |
55 | |
56 " get chars = <cpp> length string representing the pixels | |
57 " (first incl. the following whitespace) | |
58 let chars = substitute(s, '"\(.\{'.cpp.'}\s\).*"', '\1', '') | |
59 | |
60 " now get color, first try 'c' key if any (color visual) | |
61 let color = substitute(s, '".*\sc\s\+\(.\{-}\)\s*\(\(g4\=\|[ms]\)\s.*\)*\s*"', '\1', '') | |
62 if color == s | |
63 " no 'c' key, try 'g' key (grayscale with more than 4 levels) | |
64 let color = substitute(s, '".*\sg\s\+\(.\{-}\)\s*\(\(g4\|[ms]\)\s.*\)*\s*"', '\1', '') | |
65 if color == s | |
66 " next try: 'g4' key (4-level grayscale) | |
67 let color = substitute(s, '".*\sg4\s\+\(.\{-}\)\s*\([ms]\s.*\)*\s*"', '\1', '') | |
68 if color == s | |
69 " finally try 'm' key (mono visual) | |
70 let color = substitute(s, '".*\sm\s\+\(.\{-}\)\s*\(s\s.*\)*\s*"', '\1', '') | |
71 if color == s | |
72 let color = "" | |
73 endif | |
74 endif | |
75 endif | |
76 endif | |
77 | |
78 " Vim cannot handle RGB codes with more than 6 hex digits | |
79 if color =~ '#\x\{10,}$' | |
80 let color = substitute(color, '\(\x\x\)\x\x', '\1', 'g') | |
81 elseif color =~ '#\x\{7,}$' | |
82 let color = substitute(color, '\(\x\x\)\x', '\1', 'g') | |
83 " nor with 3 digits | |
84 elseif color =~ '#\x\{3}$' | |
85 let color = substitute(color, '\(\x\)\(\x\)\(\x\)', '0\10\20\3', '') | |
86 endif | |
87 | |
88 " escape meta characters in patterns | |
89 let s = escape(s, '/\*^$.~[]') | |
90 let chars = escape(chars, '/\*^$.~[]') | |
91 | |
92 " now create syntax items | |
93 " highlight the color string as normal string (no pixel string) | |
94 exe 'syn match xpmCol'.n.'Def /'.s.'/ contains=xpmCol'.n.'inDef' | |
95 exe 'hi link xpmCol'.n.'Def String' | |
96 | |
97 " but highlight the first whitespace after chars in its color | |
98 exe 'syn match xpmCol'.n.'inDef /"'.chars.'/hs=s+'.(cpp+1).' contained' | |
99 exe 'hi link xpmCol'.n.'inDef xpmColor'.n | |
100 | |
101 " remove the following whitespace from chars | |
102 let chars = substitute(chars, '.$', '', '') | |
103 | |
104 " and create the syntax item contained in the pixel strings | |
105 exe 'syn match xpmColor'.n.' /'.chars.'/ contained' | |
106 exe 'syn cluster xpmColors add=xpmColor'.n | |
107 | |
108 " if no color or color = "None" show background | |
109 if color == "" || substitute(color, '.*', '\L&', '') == 'none' | |
110 exe 'hi xpmColor'.n.' guifg=bg' | |
111 exe 'hi xpmColor'.n.' guibg=NONE' | |
34
e170173ecb68
before ack base protocol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
112 elseif color !~ "'" |
0 | 113 exe 'hi xpmColor'.n." guifg='".color."'" |
114 exe 'hi xpmColor'.n." guibg='".color."'" | |
115 endif | |
116 let n = n + 1 | |
117 else | |
118 break " no more color string | |
119 endif | |
120 endif | |
121 let i = i + 1 | |
122 endwhile | |
123 | |
124 unlet color chars colors cpp n i s | |
125 | |
126 endif " has("gui_running") | |
127 | |
128 " Define the default highlighting. | |
129 " For version 5.7 and earlier: only when not done already | |
130 " For version 5.8 and later: only when an item doesn't have highlighting yet | |
131 if version >= 508 || !exists("did_xpm_syntax_inits") | |
132 if version < 508 | |
133 let did_xpm_syntax_inits = 1 | |
134 command -nargs=+ HiLink hi link <args> | |
135 else | |
136 command -nargs=+ HiLink hi def link <args> | |
137 endif | |
138 | |
139 HiLink xpmType Type | |
140 HiLink xpmStorageClass StorageClass | |
141 HiLink xpmTodo Todo | |
142 HiLink xpmComment Comment | |
143 HiLink xpmPixelString String | |
144 | |
145 delcommand HiLink | |
146 endif | |
147 | |
148 let b:current_syntax = "xpm" | |
149 | |
150 " vim: ts=8:sw=3:noet: |