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