chrisbra / Colorizer

color hex codes and color names
549 stars 31 forks source link

Text doesn't consistently colorize or stay colorized #77

Closed daveyarwood closed 2 years ago

daveyarwood commented 5 years ago

I'm using Conjure for Clojure development. It basically gives you a Clojure REPL integrated into Neovim, with a log buffer (ft=clojure) where output is displayed.

I have a project that prints text to stdout that contains ANSI color codes. My goal is to render the text in color in the Conjure log buffer.

With this configuration:

" I was hoping that this would enable colorizer for every filetype, but I still
" had to run :ColorHighlight (or :ColorToggle) manually even after adding this.
let g:colorizer_auto_color = 1

" Clojure is included here because colorizer interprets ANSI escape codes, and I
" use Conjure, which has a log buffer whose filetype is Clojure. Conjure +
" colorizer = awesome colored text output on stdout/stderr!
let g:colorizer_auto_filetype='scss,css,clojure'

I see this behavior:

https://daveyarwood.keybase.pub/misc/201911141433-conjure-colorizer.gif

The issues I'm noticing are:

daveyarwood commented 5 years ago

I've partially worked around the problem by adding this autocmd to my vimrc:

autocmd BufEnter,BufLeave /tmp/conjure.cljc ColorHighlight

It's still a little bit flaky, as you can see in this new gif:

https://daveyarwood.keybase.pub/misc/201911141526-conjure-colorizer.gif

I still have to enter the buffer in order to get color, and then after I leave, new entries in the log don't get colorized unless I enter the log buffer again. What I want is for that buffer to be colorized when it gets created and then I want it to stay colorized even if I move away into another split.

EDIT: Adding BufNewFile and BufRead didn't help either. I'm not sure what Conjure is doing, exactly, when it opens the log buffer. Is it a window? A split? @Olical ?

chrisbra commented 5 years ago

hm, is that specific to a terminal buffer?

daveyarwood commented 5 years ago

It's not a terminal buffer, it's a file /tmp/conjure.cljc (filetype: clojure)

Olical commented 5 years ago

The Conjure log is a regular old buffer, a few options get set upon creation though:

(source)

    vim.api.nvim_command("botright " .. size_abs .. split .. " " .. log_buf_name)
    vim.api.nvim_command("setlocal winfixwidth")
    vim.api.nvim_command("setlocal winfixheight")
    vim.api.nvim_command("setlocal buftype=nofile")
    vim.api.nvim_command("setlocal bufhidden=hide")
    vim.api.nvim_command("setlocal nowrap")
    vim.api.nvim_command("setlocal noswapfile")
    vim.api.nvim_command("setlocal nobuflisted")
    vim.api.nvim_command("setlocal nospell")
    vim.api.nvim_command("setlocal foldmethod=marker")
    vim.api.nvim_command("setlocal foldlevel=0")
    vim.api.nvim_command("setlocal foldmarker={{{,}}}")
    vim.api.nvim_command("normal! G")
chrisbra commented 5 years ago

I don't see why it shouldn't work. Is there an easy way to reproduce? Perhaps share a view or session file?

Am 15.11.2019 um 17:07 schrieb Oliver Caldwell notifications@github.com:

 The Conjure log is a regular old buffer, a few options get set upon creation though:

https://github.com/Olical/conjure/blob/52618ff54b164b648e2f84fd5e83fa8f81e23f3e/lua/conjure.lua#L71-L83

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

daveyarwood commented 5 years ago

I came up with a simpler repro:

https://daveyarwood.keybase.pub/misc/201911151455-colorizer-splits.gif

In this gif, I'm not using Conjure, I'm just editing a tiny CSS file and opening the same file in splits.

It appears that Colorizer is only colorizing the buffer that's in focus.

otreblan commented 4 years ago

I'm having a similar error, but with vim-dispatch and cmake. And quickfix.

daveyarwood commented 4 years ago

I tried a bunch of other autocmds and got a little bit further. Here's where I'm at now:

augroup auto_colorize
  autocmd!
  autocmd
        \ BufNewFile,BufRead,BufEnter,BufLeave,WinEnter,WinLeave,WinNew
        \ /tmp/conjure.cljc,*.css,*.scss
        \ ColorHighlight
augroup END

Adding WinEnter, WinLeave and WinNew seems to improve the behavior such that when I open a new split, it's colorized, (it still loses color when I make a change in one split of the same file, like in my gif above), and when I move between splits, the splits that lost color get colorized again.

It still seems like the behavior we're missing is that whenever you change text, it should re-colorize all the buffers/windows. I attempted to get this behavior by adding TextChanged and TextChangedI to the autocmd, but that didn't work.

daveyarwood commented 4 years ago

NB: With the above in place, I was able to comment out the following options because they make no difference in behavior:

" let g:colorizer_auto_color = 1
" let g:colorizer_auto_filetype='scss,css,clojure'
daveyarwood commented 4 years ago

I just discovered that Colorizer has an option to disable its default behavior where it de-colorizes whenever you leave a buffer. This gets me most of the way to fixing this issue:

let g:colorizer_auto_color = 1
let g:colorizer_auto_filetype='scss,css,clojure'
let g:colorizer_disable_bufleave = 1

The remaining issues I'm seeing are:

  1. Floating windows are not automatically colorized.
  2. Occasionally I see that certain lines / columns seem to be "stained" a certain color, perhaps as a relic of having colorized a different buffer:

2020-05-20-110914_802x369_scrot

her commented 4 years ago

Thanks for the comments everyone, very helpful.

I also noticed that,

let g:colorizer_auto_color = 1
let g:colorizer_auto_filetype='scss,css,js'
let g:colorizer_disable_bufleave = 1

made no effect, unless I sourced my .vimrc in a loaded buffer :so $MYVIMRC. Which makes me think that it could be an initialization problem with this plugin. It's just not sourcing these at the right time.

In any case, this works for me:

augroup auto_colorize
  autocmd!
  autocmd
        \ BufNewFile,BufRead,BufEnter,BufLeave,WinEnter,WinLeave,WinNew
        \ *.js,*.css,*.scss,*.sass
        \ ColorHighlight
augroup END

So I'll run with this for now and if I get some free time maybe look at the code here.

Cris-lml007 commented 2 years ago

I think a better direction to get it activated in a summary is:
autocmd FileType * : ColorHighlight with that the colors for all languages would be activated

chrisbra commented 2 years ago

would you please create a PR with a doc improvement for this please?

Cris-lml007 commented 2 years ago

I don't think it's convenient to modify or implement the command that mentions the script, since this makes vim slow down a bit, but if you want the plugin to be initialized when opening a file no matter that vim slows down, you can add the command mentioned above in .vimrc. autocmd FileType * : ColorHighlight

chrisbra commented 2 years ago

let me add this to the documentation at least