annotate runtime/syntax/xpm.vim @ 27980:40e35cefeac6 v8.2.4515

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