To: vim_dev@googlegroups.com Subject: Patch 8.1.1674 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1674 Problem: Script to check a colorscheme can be improved. Solution: Match the whole group name. Don't warn for what is usually omitted. Files: runtime/colors/tools/check_colors.vim *** ../vim-8.1.1673/runtime/colors/tools/check_colors.vim 2017-12-16 18:42:07.000000000 +0100 --- runtime/colors/tools/check_colors.vim 2019-07-12 22:40:39.668777947 +0200 *************** *** 1,13 **** ! " This script tests a color scheme for some errors. Load the scheme and source ! " this script. e.g. :e colors/desert.vim | :so test_colors.vim ! " Will output possible errors. let s:save_cpo= &cpo set cpo&vim func! Test_check_colors() call cursor(1,1) ! let err={} " 1) Check g:colors_name is existing if !search('\<\%(g:\)\?colors_name\>', 'cnW') --- 1,14 ---- ! " This script tests a color scheme for some errors and lists potential errors. ! " Load the scheme and source this script, like this: ! " :edit colors/desert.vim | :so colors/tools/check_colors.vim let s:save_cpo= &cpo set cpo&vim func! Test_check_colors() + let l:savedview = winsaveview() call cursor(1,1) ! let err = {} " 1) Check g:colors_name is existing if !search('\<\%(g:\)\?colors_name\>', 'cnW') *************** *** 17,64 **** endif " 2) Check for some well-defined highlighting groups ! " Some items, check several groups, e.g. Diff, Spell ! let hi_groups = ['ColorColumn', 'Diff', 'ErrorMsg', 'Folded', ! \ 'FoldColumn', 'IncSearch', 'LineNr', 'ModeMsg', 'MoreMsg', 'NonText', ! \ 'Normal', 'Pmenu', 'Todo', 'Search', 'Spell', 'StatusLine', 'TabLine', ! \ 'Title', 'Visual', 'WarningMsg', 'WildMenu'] ! let groups={} for group in hi_groups ! if search('\c@suppress\s\+'.group, 'cnW') " skip check, if the script contains a line like " @suppress Visual: - let groups[group] = 'Ignoring '.group continue endif ! if !search('hi\%[ghlight] \+'.group, 'cnW') ! let groups[group] = 'No highlight definition for '.group continue endif ! if !search('hi\%[ghlight] \+'.group. '.*fg=', 'cnW') ! let groups[group] = 'Missing foreground color for '.group continue endif ! if search('hi\%[ghlight] \+'.group. '.*guibg=', 'cnW') && ! \ !search('hi\%[ghlight] \+'.group. '.*ctermbg=', 'cnW') ! let groups[group] = 'Missing bg terminal color for '.group continue endif ! call search('hi\%[ghlight] \+'.group, 'cW') ! " only check in the current line ! if !search('guifg', 'cnW', line('.')) || !search('ctermfg', 'cnW', line('.')) ! " do not check for background colors, they could be intentionally left out ! let groups[group] = 'Missing fg definition for '.group endif call cursor(1,1) endfor let err['highlight'] = groups " 3) Check, that it does not set background highlighting " Doesn't ':hi Normal ctermfg=253 ctermfg=233' also set the background sometimes? ! let bg_set='\(set\?\|setl\(ocal\)\?\) .*\(background\|bg\)=\(dark\|light\)' ! let bg_let='let \%([&]\%([lg]:\)\?\)\%(background\|bg\)\s*=\s*\([''"]\?\)\w\+\1' ! let bg_pat='\%('.bg_set. '\|'.bg_let.'\)' ! let line=search(bg_pat, 'cnW') if search(bg_pat, 'cnW') exe line if search('hi \U\w\+\s\+\S', 'cbnW') --- 18,132 ---- endif " 2) Check for some well-defined highlighting groups ! let hi_groups = [ ! \ 'ColorColumn', ! \ 'Comment', ! \ 'Conceal', ! \ 'Constant', ! \ 'Cursor', ! \ 'CursorColumn', ! \ 'CursorLine', ! \ 'CursorLineNr', ! \ 'DiffAdd', ! \ 'DiffChange', ! \ 'DiffDelete', ! \ 'DiffText', ! \ 'Directory', ! \ 'EndOfBuffer', ! \ 'Error', ! \ 'ErrorMsg', ! \ 'FoldColumn', ! \ 'Folded', ! \ 'Identifier', ! \ 'Ignore', ! \ 'IncSearch', ! \ 'LineNr', ! \ 'MatchParen', ! \ 'ModeMsg', ! \ 'MoreMsg', ! \ 'NonText', ! \ 'Normal', ! \ 'Pmenu', ! \ 'PmenuSbar', ! \ 'PmenuSel', ! \ 'PmenuThumb', ! \ 'PreProc', ! \ 'Question', ! \ 'QuickFixLine', ! \ 'Search', ! \ 'SignColumn', ! \ 'Special', ! \ 'SpecialKey', ! \ 'SpellBad', ! \ 'SpellCap', ! \ 'SpellLocal', ! \ 'SpellRare', ! \ 'Statement', ! \ 'StatusLine', ! \ 'StatusLineNC', ! \ 'StatusLineTerm', ! \ 'StatusLineTermNC', ! \ 'TabLine', ! \ 'TabLineFill', ! \ 'TabLineSel', ! \ 'Title', ! \ 'Todo', ! \ 'ToolbarButton', ! \ 'ToolbarLine', ! \ 'Type', ! \ 'Underlined', ! \ 'VertSplit', ! \ 'Visual', ! \ 'VisualNOS', ! \ 'WarningMsg', ! \ 'WildMenu', ! \ ] ! let groups = {} for group in hi_groups ! if search('\c@suppress\s\+\<' .. group .. '\>', 'cnW') " skip check, if the script contains a line like " @suppress Visual: continue endif ! if search('hi\%[ghlight]!\= \+link \+' .. group, 'cnW') " Linked group continue endif ! if !search('hi\%[ghlight] \+\<' .. group .. '\>', 'cnW') ! let groups[group] = 'No highlight definition for ' .. group continue endif ! if !search('hi\%[ghlight] \+\<' .. group .. '\>.*[bf]g=', 'cnW') ! let groups[group] = 'Missing foreground or background color for ' .. group continue endif ! if search('hi\%[ghlight] \+\<' .. group .. '\>.*guibg=', 'cnW') && ! \ !search('hi\%[ghlight] \+\<' .. group .. '\>.*ctermbg=', 'cnW') ! \ && group != 'Cursor' ! let groups[group] = 'Missing bg terminal color for ' .. group ! continue ! endif ! if !search('hi\%[ghlight] \+\<' .. group .. '\>.*guifg=', 'cnW') ! \ && group !~ '^Diff' ! let groups[group] = 'Missing guifg definition for ' .. group ! continue endif + if !search('hi\%[ghlight] \+\<' .. group .. '\>.*ctermfg=', 'cnW') + \ && group !~ '^Diff' + \ && group != 'Cursor' + let groups[group] = 'Missing ctermfg definition for ' .. group + continue + endif + " do not check for background colors, they could be intentionally left out call cursor(1,1) endfor let err['highlight'] = groups " 3) Check, that it does not set background highlighting " Doesn't ':hi Normal ctermfg=253 ctermfg=233' also set the background sometimes? ! let bg_set = '\(set\?\|setl\(ocal\)\?\) .*\(background\|bg\)=\(dark\|light\)' ! let bg_let = 'let \%([&]\%([lg]:\)\?\)\%(background\|bg\)\s*=\s*\([''"]\?\)\w\+\1' ! let bg_pat = '\%(' .. bg_set .. '\|' .. bg_let .. '\)' ! let line = search(bg_pat, 'cnW') if search(bg_pat, 'cnW') exe line if search('hi \U\w\+\s\+\S', 'cbnW') *************** *** 80,86 **** " if exists("syntax_on") " syntax reset " endif ! let pat='hi\%[ghlight]\s*clear\n\s*if\s*exists(\([''"]\)syntax_on\1)\n\s*syn\%[tax]\s*reset\n\s*endif' if !search(pat, 'cnW') let err['init'] = 'No initialization' endif --- 148,154 ---- " if exists("syntax_on") " syntax reset " endif ! let pat = 'hi\%[ghlight]\s*clear\n\s*if\s*exists(\([''"]\)syntax_on\1)\n\s*syn\%[tax]\s*reset\n\s*endif' if !search(pat, 'cnW') let err['init'] = 'No initialization' endif *************** *** 90,105 **** let err['background'] = 'Should not issue :syn on' endif ! " 7) Does not define filetype specfic groups like vimCommand, htmlTag, ! let hi_groups = ['vim', 'html', 'python', 'sh', 'ruby'] for group in hi_groups ! let pat='\Chi\%[ghlight]\s*\zs'.group.'\w\+\>' if search(pat, 'cnW') let line = search(pat, 'cW') let err['filetype'] = get(err, 'filetype', 'Should not define: ') . matchstr(getline('.'), pat). ' ' endif call cursor(1,1) endfor let g:err = err " print Result --- 158,201 ---- let err['background'] = 'Should not issue :syn on' endif ! " 7) Does not define filetype specific groups like vimCommand, htmlTag, ! let hi_groups = filter(getcompletion('', 'filetype'), { _,v -> v !~# '\%[no]syn\%(color\|load\|tax\)' }) ! let ft_groups = [] ! " let group = '\%('.join(hi_groups, '\|').'\)' " More efficient than a for loop, but less informative for group in hi_groups ! let pat = '\Chi\%[ghlight]!\= *\%[link] \+\zs' .. group .. '\w\+\>\ze \+.' " Skips `hi clear` ! if search(pat, 'cW') ! call add(ft_groups, matchstr(getline('.'), pat)) ! endif ! call cursor(1,1) ! endfor ! if !empty(ft_groups) ! let err['filetype'] = get(err, 'filetype', 'Should not define: ') . join(uniq(sort(ft_groups))) ! endif ! ! " 8) Were debugPC and debugBreakpoint defined? ! for group in ['debugPC', 'debugBreakpoint'] ! let pat = '\Chi\%[ghlight]!\= *\%[link] \+\zs' .. group .. '\>' if search(pat, 'cnW') let line = search(pat, 'cW') let err['filetype'] = get(err, 'filetype', 'Should not define: ') . matchstr(getline('.'), pat). ' ' endif call cursor(1,1) endfor + + " 9) Normal should be defined first, not use reverse, fg or bg + call cursor(1,1) + let pat = 'hi\%[light] \+\%(link\|clear\)\@!\w\+\>' + call search(pat, 'cW') " Look for the first hi def, skipping `hi link` and `hi clear` + if getline('.') !~# '\m\' + let err['highlight']['Normal'] = 'Should be defined first' + elseif getline('.') =~# '\m\%(=\%(fg\|bg\)\)' + let err['highlight']['Normal'] = "Should not use 'fg' or 'bg'" + elseif getline('.') =~# '\m=\%(inv\|rev\)erse' + let err['highlight']['Normal'] = 'Should not use reverse mode' + endif + + call winrestview(l:savedview) let g:err = err " print Result *************** *** 107,117 **** endfu fu! Result(err) ! let do_roups = 0 echohl Title|echomsg "---------------"|echohl Normal for key in sort(keys(a:err)) if key is# 'highlight' ! let do_groups = 1 continue else if a:err[key] !~ 'OK' --- 203,213 ---- endfu fu! Result(err) ! let do_groups = 0 echohl Title|echomsg "---------------"|echohl Normal for key in sort(keys(a:err)) if key is# 'highlight' ! let do_groups = !empty(a:err[key]) continue else if a:err[key] !~ 'OK' *** ../vim-8.1.1673/src/version.c 2019-07-12 21:07:49.533756948 +0200 --- src/version.c 2019-07-12 22:43:49.431844870 +0200 *************** *** 779,780 **** --- 779,782 ---- { /* Add new patch number below this line */ + /**/ + 1674, /**/ -- Proofread carefully to see if you any words out. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///