annotate runtime/syntax/xpm2.vim @ 6170:3ee39fe2df7d v7.4.421

updated for version 7.4.421 Problem: Crash when searching for "\ze*". (Urtica Dioica) Solution: Disallow a multi after \ze and \zs.
author Bram Moolenaar <bram@vim.org>
date Fri, 29 Aug 2014 11:56:32 +0200
parents 9cb3a75a20b9
children 43efa4f5a8ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim syntax file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: X Pixmap v2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Steve Wall (hitched97@velnet.com)
3557
9cb3a75a20b9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3312
diff changeset
4 " Last Change: 2012 Jun 01
9cb3a75a20b9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3312
diff changeset
5 " (Dominique Pelle added @Spell)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " Version: 5.8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 " Made from xpm.vim by Ronald Schild <rs@scutum.de>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 " For version 5.x: Clear all syntax items
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 " For version 6.x: Quit when a syntax file was already loaded
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 if version < 600
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 syntax clear
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 elseif exists("b:current_syntax")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
18 let s:cpo_save = &cpo
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
19 set cpo&vim
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
20
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 syn region xpm2PixelString start="^" end="$" contains=@xpm2Colors
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 syn keyword xpm2Todo TODO FIXME XXX contained
3557
9cb3a75a20b9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3312
diff changeset
23 syn match xpm2Comment "\!.*$" contains=@Spell,xpm2Todo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 if version < 508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 command -nargs=+ HiLink hi link <args>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 command -nargs=+ Hi hi <args>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 command -nargs=+ HiLink hi def link <args>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 command -nargs=+ Hi hi def <args>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 if has("gui_running")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 let color = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 let chars = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let colors = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 let cpp = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let n = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 let i = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 while i <= line("$") " scanning all lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 let s = getline(i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 if match(s,"\!.*$") != -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 let s = matchstr(s, "^[^\!]*")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 if s != "" " does line contain a string?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 if n == 0 " first string is the Values string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 " get the 3rd value: colors = number of colors
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 let colors = substitute(s, '\s*\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 " get the 4th value: cpp = number of character per pixel
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 let cpp = substitute(s, '\s*\d\+\s\+\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '')
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 7
diff changeset
57 if cpp =~ '[^0-9]'
73fe8baea242 updated for version 7.2a
vimboss
parents: 7
diff changeset
58 break " if cpp is not made of digits there must be something wrong
73fe8baea242 updated for version 7.2a
vimboss
parents: 7
diff changeset
59 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 7
diff changeset
61 " Highlight the Values string as normal string (no pixel string).
73fe8baea242 updated for version 7.2a
vimboss
parents: 7
diff changeset
62 " Only when there is no slash, it would terminate the pattern.
73fe8baea242 updated for version 7.2a
vimboss
parents: 7
diff changeset
63 if s !~ '/'
73fe8baea242 updated for version 7.2a
vimboss
parents: 7
diff changeset
64 exe 'syn match xpm2Values /' . s . '/'
73fe8baea242 updated for version 7.2a
vimboss
parents: 7
diff changeset
65 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 HiLink xpm2Values Statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 let n = 1 " n = color index
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 elseif n <= colors " string is a color specification
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 " get chars = <cpp> length string representing the pixels
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 " (first incl. the following whitespace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 let chars = substitute(s, '\(.\{'.cpp.'}\s\+\).*', '\1', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 " now get color, first try 'c' key if any (color visual)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 let color = substitute(s, '.*\sc\s\+\(.\{-}\)\s*\(\(g4\=\|[ms]\)\s.*\)*\s*', '\1', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 if color == s
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 " no 'c' key, try 'g' key (grayscale with more than 4 levels)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 let color = substitute(s, '.*\sg\s\+\(.\{-}\)\s*\(\(g4\|[ms]\)\s.*\)*\s*', '\1', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 if color == s
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 " next try: 'g4' key (4-level grayscale)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 let color = substitute(s, '.*\sg4\s\+\(.\{-}\)\s*\([ms]\s.*\)*\s*', '\1', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 if color == s
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 " finally try 'm' key (mono visual)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 let color = substitute(s, '.*\sm\s\+\(.\{-}\)\s*\(s\s.*\)*\s*', '\1', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 if color == s
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 let color = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 " Vim cannot handle RGB codes with more than 6 hex digits
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 if color =~ '#\x\{10,}$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 let color = substitute(color, '\(\x\x\)\x\x', '\1', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 elseif color =~ '#\x\{7,}$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 let color = substitute(color, '\(\x\x\)\x', '\1', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 " nor with 3 digits
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 elseif color =~ '#\x\{3}$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 let color = substitute(color, '\(\x\)\(\x\)\(\x\)', '0\10\20\3', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 " escape meta characters in patterns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 let s = escape(s, '/\*^$.~[]')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 let chars = escape(chars, '/\*^$.~[]')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 " change whitespace to "\s\+"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 let s = substitute(s, "[ \t][ \t]*", "\\\\s\\\\+", "g")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 let chars = substitute(chars, "[ \t][ \t]*", "\\\\s\\\\+", "g")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 " now create syntax items
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 " highlight the color string as normal string (no pixel string)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 exe 'syn match xpm2Col'.n.'Def /'.s.'/ contains=xpm2Col'.n.'inDef'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 exe 'HiLink xpm2Col'.n.'Def Constant'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 " but highlight the first whitespace after chars in its color
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 exe 'syn match xpm2Col'.n.'inDef /^'.chars.'/hs=s+'.(cpp).' contained'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 exe 'HiLink xpm2Col'.n.'inDef xpm2Color'.n
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 " remove the following whitespace from chars
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 let chars = substitute(chars, '\\s\\+$', '', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 " and create the syntax item contained in the pixel strings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 exe 'syn match xpm2Color'.n.' /'.chars.'/ contained'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 exe 'syn cluster xpm2Colors add=xpm2Color'.n
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 " if no color or color = "None" show background
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 if color == "" || substitute(color, '.*', '\L&', '') == 'none'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 exe 'Hi xpm2Color'.n.' guifg=bg guibg=NONE'
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 7
diff changeset
131 elseif color !~ "'"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 exe 'Hi xpm2Color'.n." guifg='".color."' guibg='".color."'"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 let n = n + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 break " no more color string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 let i = i + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 unlet color chars colors cpp n i s
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 endif " has("gui_running")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 " Define the default highlighting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 " For version 5.7 and earlier: only when not done already
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 " For version 5.8 and later: only when an item doesn't have highlighting yet
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 if version >= 508 || !exists("did_xpm2_syntax_inits")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 if version < 508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 let did_xpm2_syntax_inits = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 " The default highlighting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 HiLink xpm2Type Type
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 HiLink xpm2StorageClass StorageClass
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 HiLink xpm2Todo Todo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 HiLink xpm2Comment Comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 HiLink xpm2PixelString String
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 delcommand HiLink
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 delcommand Hi
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 let b:current_syntax = "xpm2"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
166 let &cpo = s:cpo_save
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
167 unlet s:cpo_save
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 " vim: ts=8:sw=2:noet: