chrisbra / Colorizer

color hex codes and color names
547 stars 30 forks source link

Error in neovim 0.1.5 when coloring vim highlight command #48

Closed dkasak closed 8 years ago

dkasak commented 8 years ago

I'm getting an error when doing :ColorToggle on a vim config file containing highlight commands. I'm using neovim 0.1.5.

Colorizer: Some error occured here:  Colorize: ['^\s*\%(\%[Html]HiLink\s\+\w\+\s\+\w\+\)\|\(^\s*hi\%[ghlight]!\?\s\+\(clear\)\@!\S\+.*\)', function('<SNR>146_PreviewVimHighlight'), 'colorizer_vimhighlight', '&ft ==# "vim"', []]
Colorizer: Position: [0, 7, 1, 0]

I've managed to produce a minimal config file using only vim-plug (to install Colorizer) and Colorizer itself. The position in the error above is referring to the highlight line.

set termguicolors

call plug#begin("$HOME/tmp/colorizer_test/bundle")
Plug 'chrisbra/Colorizer'
call plug#end()

highlight! link DiffChange DiffAdd

Note that setting termguicolors is the new way to get truecolor support in neovim which supersedes the old way of setting $NVIM_TUI_ENABLE_TRUE_COLOR=1. I've tried changing this line to

    let s:term_true_color = ((has("nvim") && &termguicolors == 1) ||
                \ (exists('+tgc') && &tgc))

but it did not fix the error. Nevertheless, you should probably switch to it instead of using NVIM_TUI_ENABLE_TRUE_COLOR (or check for both, for backward compatibility).

EDIT: I forgot to mention that Colorizer works perfectly with other things such as hex colors. It seems that just highlight commands are breaking it.

chrisbra commented 8 years ago

I don't understand. For never neovims, that support the 'termguicolor' setting, this line:

let s:term_true_color = ((has("nvim") && &termguicolors == 1) ||
            \ (exists('+tgc') && &tgc))

that should return true. Shouldn't it? Now the real problem is, why does it fail in PreviewVimHighlight? What is in line 7?

dkasak commented 8 years ago

Line 7 is highlight! link DiffChange DiffAdd, since I used the above minimal vim config as both the configuration file for vim and the file I did :ColorToggle in.

I don't understand. For never neovims, that support the 'termguicolor' setting, this line: [...] that should return true.

That's correct, and it does return true, but this is not what the line currently looks like in Colorizer. I was just saying I changed it to look like that in an attempt to fix my error, but it didn't fix it.

chrisbra commented 8 years ago

Yeah, I think, it doesn't work in Vim as well. Ah, it doesn't seem to take care of the '!' and the 'link' attribute. Will look into it. Thanks for noticing.

dkasak commented 8 years ago

Thanks. Do you want me to make a pull request for handling the termguicolors setting?

chrisbra commented 8 years ago

can you check with current head?

chrisbra commented 8 years ago

Thanks. Do you want me to make a pull request for handling the termguicolors setting?

Sorry, I don't understand. This will break colorizer for older neovims, doesn't it? If I don't care about older neovims, this should be changed to this I think:

let s:term_true_color = (exists('+tgc') && &tgc))
dkasak commented 8 years ago

Ah, sorry, my brain totally missed that tgc is actually termguicolors. I can see now that it is already handled. Sorry for the noise.

Your fix works, thanks!