annotate runtime/syntax/xpm2.vim @ 29500:57d7422e07fa

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