diff options
Diffstat (limited to 'autoload/spectral/highlight.vim')
-rw-r--r-- | autoload/spectral/highlight.vim | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/autoload/spectral/highlight.vim b/autoload/spectral/highlight.vim new file mode 100644 index 0000000..6bbde34 --- /dev/null +++ b/autoload/spectral/highlight.vim @@ -0,0 +1,33 @@ +let s:done = {} + +function! spectral#highlight#highlight() abort + %s/#[a-fA-F0-9]\{6}/\=spectral#highlight#highlightOne(submatch(0))/g +endfunction + +function! spectral#highlight#highlightLine() abort + let curpos = getcurpos() + silent! '[,']s/#[a-fA-F0-9]\{6}/\=spectral#highlight#highlightOne(submatch(0))/g + call cursor(curpos[1:]) +endfunction + +function! spectral#highlight#highlightOne(match) abort + let match = a:match + let nohash = match[1:] + + if has_key(s:done, match) + return a:match + else + let s:done[match] = 1 + endif + + exec printf("syn match %s +%s+ containedIn=vimComment,vim9Comment,vimString,vimIsCommand,vimHiGuiRgb", nohash, match) + exec printf("hi %s guifg=#000000 guibg=%s", nohash, match) + + " Return exactly what was put in. We only care about the side effets. + return a:match +endfunction + +function! spectral#highlight#clearCache() abort + let s:done = {} + call spectral#highlight#highlight() +endfunction |