Mercurial > vim
comparison runtime/colors/tools/check_colors.vim @ 17350:072ae5089541 v8.1.1674
patch 8.1.1674: script to check a colorscheme can be improved
commit https://github.com/vim/vim/commit/4e63f9425e6623aec4cd016af6def0b354b935f1
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jul 12 22:46:47 2019 +0200
patch 8.1.1674: script to check a colorscheme can be improved
Problem: Script to check a colorscheme can be improved.
Solution: Match the whole group name. Don't warn for what is usually omitted.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 12 Jul 2019 23:00:05 +0200 |
parents | c002c4899529 |
children | 0db0640e16e0 |
comparison
equal
deleted
inserted
replaced
17349:77949b9b65da | 17350:072ae5089541 |
---|---|
6 set cpo&vim | 6 set cpo&vim |
7 | 7 |
8 func! Test_check_colors() | 8 func! Test_check_colors() |
9 let l:savedview = winsaveview() | 9 let l:savedview = winsaveview() |
10 call cursor(1,1) | 10 call cursor(1,1) |
11 let err={} | 11 let err = {} |
12 | 12 |
13 " 1) Check g:colors_name is existing | 13 " 1) Check g:colors_name is existing |
14 if !search('\<\%(g:\)\?colors_name\>', 'cnW') | 14 if !search('\<\%(g:\)\?colors_name\>', 'cnW') |
15 let err['colors_name'] = 'g:colors_name not set' | 15 let err['colors_name'] = 'g:colors_name not set' |
16 else | 16 else |
79 \ 'Visual', | 79 \ 'Visual', |
80 \ 'VisualNOS', | 80 \ 'VisualNOS', |
81 \ 'WarningMsg', | 81 \ 'WarningMsg', |
82 \ 'WildMenu', | 82 \ 'WildMenu', |
83 \ ] | 83 \ ] |
84 let groups={} | 84 let groups = {} |
85 for group in hi_groups | 85 for group in hi_groups |
86 if search('\c@suppress\s\+'.group, 'cnW') | 86 if search('\c@suppress\s\+\<' .. group .. '\>', 'cnW') |
87 " skip check, if the script contains a line like | 87 " skip check, if the script contains a line like |
88 " @suppress Visual: | 88 " @suppress Visual: |
89 let groups[group] = 'Ignoring '.group | 89 continue |
90 continue | 90 endif |
91 endif | 91 if search('hi\%[ghlight]!\= \+link \+' .. group, 'cnW') " Linked group |
92 if search('hi\%[ghlight]!\= \+link \+'.group, 'cnW') " Linked group | 92 continue |
93 continue | 93 endif |
94 endif | 94 if !search('hi\%[ghlight] \+\<' .. group .. '\>', 'cnW') |
95 if !search('hi\%[ghlight] \+'.group, 'cnW') | 95 let groups[group] = 'No highlight definition for ' .. group |
96 let groups[group] = 'No highlight definition for '.group | 96 continue |
97 continue | 97 endif |
98 endif | 98 if !search('hi\%[ghlight] \+\<' .. group .. '\>.*[bf]g=', 'cnW') |
99 if !search('hi\%[ghlight] \+'.group. '.*fg=', 'cnW') | 99 let groups[group] = 'Missing foreground or background color for ' .. group |
100 let groups[group] = 'Missing foreground color for '.group | 100 continue |
101 continue | 101 endif |
102 endif | 102 if search('hi\%[ghlight] \+\<' .. group .. '\>.*guibg=', 'cnW') && |
103 if search('hi\%[ghlight] \+'.group. '.*guibg=', 'cnW') && | 103 \ !search('hi\%[ghlight] \+\<' .. group .. '\>.*ctermbg=', 'cnW') |
104 \ !search('hi\%[ghlight] \+'.group. '.*ctermbg=', 'cnW') | 104 \ && group != 'Cursor' |
105 let groups[group] = 'Missing bg terminal color for '.group | 105 let groups[group] = 'Missing bg terminal color for ' .. group |
106 continue | 106 continue |
107 endif | 107 endif |
108 if !search('hi\%[ghlight] \+'.group. '.*guifg=', 'cnW') | 108 if !search('hi\%[ghlight] \+\<' .. group .. '\>.*guifg=', 'cnW') |
109 let groups[group] = 'Missing guifg definition for '.group | 109 \ && group !~ '^Diff' |
110 continue | 110 let groups[group] = 'Missing guifg definition for ' .. group |
111 endif | 111 continue |
112 if !search('hi\%[ghlight] \+'.group. '.*ctermfg=', 'cnW') | 112 endif |
113 let groups[group] = 'Missing ctermfg definition for '.group | 113 if !search('hi\%[ghlight] \+\<' .. group .. '\>.*ctermfg=', 'cnW') |
114 \ && group !~ '^Diff' | |
115 \ && group != 'Cursor' | |
116 let groups[group] = 'Missing ctermfg definition for ' .. group | |
114 continue | 117 continue |
115 endif | 118 endif |
116 " do not check for background colors, they could be intentionally left out | 119 " do not check for background colors, they could be intentionally left out |
117 call cursor(1,1) | 120 call cursor(1,1) |
118 endfor | 121 endfor |
119 let err['highlight'] = groups | 122 let err['highlight'] = groups |
120 | 123 |
121 " 3) Check, that it does not set background highlighting | 124 " 3) Check, that it does not set background highlighting |
122 " Doesn't ':hi Normal ctermfg=253 ctermfg=233' also set the background sometimes? | 125 " Doesn't ':hi Normal ctermfg=253 ctermfg=233' also set the background sometimes? |
123 let bg_set='\(set\?\|setl\(ocal\)\?\) .*\(background\|bg\)=\(dark\|light\)' | 126 let bg_set = '\(set\?\|setl\(ocal\)\?\) .*\(background\|bg\)=\(dark\|light\)' |
124 let bg_let='let \%([&]\%([lg]:\)\?\)\%(background\|bg\)\s*=\s*\([''"]\?\)\w\+\1' | 127 let bg_let = 'let \%([&]\%([lg]:\)\?\)\%(background\|bg\)\s*=\s*\([''"]\?\)\w\+\1' |
125 let bg_pat='\%('.bg_set. '\|'.bg_let.'\)' | 128 let bg_pat = '\%(' .. bg_set .. '\|' .. bg_let .. '\)' |
126 let line=search(bg_pat, 'cnW') | 129 let line = search(bg_pat, 'cnW') |
127 if search(bg_pat, 'cnW') | 130 if search(bg_pat, 'cnW') |
128 exe line | 131 exe line |
129 if search('hi \U\w\+\s\+\S', 'cbnW') | 132 if search('hi \U\w\+\s\+\S', 'cbnW') |
130 let err['background'] = 'Should not set background option after :hi statement' | 133 let err['background'] = 'Should not set background option after :hi statement' |
131 endif | 134 endif |
143 " 5) Initializes correctly, e.g. should have a section like | 146 " 5) Initializes correctly, e.g. should have a section like |
144 " hi clear | 147 " hi clear |
145 " if exists("syntax_on") | 148 " if exists("syntax_on") |
146 " syntax reset | 149 " syntax reset |
147 " endif | 150 " endif |
148 let pat='hi\%[ghlight]\s*clear\n\s*if\s*exists(\([''"]\)syntax_on\1)\n\s*syn\%[tax]\s*reset\n\s*endif' | 151 let pat = 'hi\%[ghlight]\s*clear\n\s*if\s*exists(\([''"]\)syntax_on\1)\n\s*syn\%[tax]\s*reset\n\s*endif' |
149 if !search(pat, 'cnW') | 152 if !search(pat, 'cnW') |
150 let err['init'] = 'No initialization' | 153 let err['init'] = 'No initialization' |
151 endif | 154 endif |
152 | 155 |
153 " 6) Does not use :syn on | 156 " 6) Does not use :syn on |
158 " 7) Does not define filetype specific groups like vimCommand, htmlTag, | 161 " 7) Does not define filetype specific groups like vimCommand, htmlTag, |
159 let hi_groups = filter(getcompletion('', 'filetype'), { _,v -> v !~# '\%[no]syn\%(color\|load\|tax\)' }) | 162 let hi_groups = filter(getcompletion('', 'filetype'), { _,v -> v !~# '\%[no]syn\%(color\|load\|tax\)' }) |
160 let ft_groups = [] | 163 let ft_groups = [] |
161 " let group = '\%('.join(hi_groups, '\|').'\)' " More efficient than a for loop, but less informative | 164 " let group = '\%('.join(hi_groups, '\|').'\)' " More efficient than a for loop, but less informative |
162 for group in hi_groups | 165 for group in hi_groups |
163 let pat='\Chi\%[ghlight]!\= *\%[link] \+\zs'.group.'\w\+\>\ze \+.' " Skips `hi clear` | 166 let pat = '\Chi\%[ghlight]!\= *\%[link] \+\zs' .. group .. '\w\+\>\ze \+.' " Skips `hi clear` |
164 if search(pat, 'cW') | 167 if search(pat, 'cW') |
165 call add(ft_groups, matchstr(getline('.'), pat)) | 168 call add(ft_groups, matchstr(getline('.'), pat)) |
166 endif | 169 endif |
167 call cursor(1,1) | 170 call cursor(1,1) |
168 endfor | 171 endfor |
170 let err['filetype'] = get(err, 'filetype', 'Should not define: ') . join(uniq(sort(ft_groups))) | 173 let err['filetype'] = get(err, 'filetype', 'Should not define: ') . join(uniq(sort(ft_groups))) |
171 endif | 174 endif |
172 | 175 |
173 " 8) Were debugPC and debugBreakpoint defined? | 176 " 8) Were debugPC and debugBreakpoint defined? |
174 for group in ['debugPC', 'debugBreakpoint'] | 177 for group in ['debugPC', 'debugBreakpoint'] |
175 let pat='\Chi\%[ghlight]!\= *\%[link] \+\zs'.group.'\>' | 178 let pat = '\Chi\%[ghlight]!\= *\%[link] \+\zs' .. group .. '\>' |
176 if search(pat, 'cnW') | 179 if search(pat, 'cnW') |
177 let line = search(pat, 'cW') | 180 let line = search(pat, 'cW') |
178 let err['filetype'] = get(err, 'filetype', 'Should not define: ') . matchstr(getline('.'), pat). ' ' | 181 let err['filetype'] = get(err, 'filetype', 'Should not define: ') . matchstr(getline('.'), pat). ' ' |
179 endif | 182 endif |
180 call cursor(1,1) | 183 call cursor(1,1) |