Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling causes syntax highlighting to break for other color themes #65

Closed
rschmukler opened this issue May 26, 2016 · 9 comments
Closed

Comments

@rschmukler
Copy link

rschmukler commented May 26, 2016

I have a toggle function which switches between light and dark; I use a different dark theme but would love to use this for light. However, when switching back to my dark theme (or any other theme) the highlighting seems to break. If I go to PaperColor it all still works fine. See the attached screenshots for an example:

Dark mode before:

Image Dark Before

Enable Light - Still looks good
Image Switch to Light

Back to dark - Now broken
Image Switch to Light

Other themes broken too
Another dark theme also broken

@NLKNguyen
Copy link
Owner

Yeah, this is a problem I noticed early on too. I believe that it's because the other themes you used didn't handle background switching well. The way to handle that is hacky, and the themes themselves should handle that.

I got a PR that helped doing that #20
You can check out the changes to see how he did it. I hope the trick has the same effect outside of the theme code. It is copied from GruvBox theme, so I think if you test switching between dark GruvBox and light PaperColor, it will behave correctly.

Let me know how it works out!

@rschmukler
Copy link
Author

@NLKNguyen I am actually explicitly setting those (set background=dark) before calling color <other-theme> - just for kicks I tried re-setting it after calling color <other-theme> as well but to no-avail. If I understand the PR correctly, that is the trick you are referring to?

PS. Thank you for this theme; I worked in it all day and it has been a pleasure!

@NLKNguyen
Copy link
Owner

There are two parts of the trick. I put in the comment of the below theme snippet. I really don't understand why it has to be this way, but it works. So, I guess if you modify the other dark theme that you use to include this, then it probably will work

  let s:is_dark=(&background == 'dark')  " <-- trick #1: this variable can be used to correctly
  " check if the current background is dark

  " Vim Highlighting
  call s:HL("Normal", s:foreground, s:background, "")
  " ^^^^ this is just a helper function in PaperColor theme. It's not required.
  " The important thing is that it sets highlighting for `Normal` group by calling something like:
  " highlight Normal guifg=#444444 guibg=#F5F5F5 ctermfg=238 ctermbg=255 

  " trick #2:  call `set background` AFTER setting the above `Normal` group highlighting 
  " and BEFORE the rest of the syntax groups of the theme

  " Switching between dark & light variant through `set background`
  " https://github.com/NLKNguyen/papercolor-theme/pull/20
  if s:is_dark " DARK VARIANT
    set background=dark
  else " LIGHT VARIANT
    set background=light
  endif

  " ... other syntax group highlightings

Glad that the theme pleases you :) I enjoy using it as well.

@rschmukler
Copy link
Author

rschmukler commented May 27, 2016

I tried adding the trick as suggested but it didn't seem to make a difference sadly. I also checked out Gruvbox and the highlighting groups still seem to break. Specifically with Go (haven't tested others). I've also not run into this particular issue with toggling between light and dark with other color themes. Not saying it's PaperColor explicitly, just trying to help debug :)

Example snippet:

import (
  "fmt"
)

func main() {
  go doSomething()
  go doSomething()
  fmt.Printf("Hello world\n")
}

func doSomething() {
  fmt.Printf("  hello!")
}

my ToggleColor Function looks like this:

function! ToggleLightDark()
  if &background == "dark"
    set background=light
    let g:airline_theme='PaperColor'
    colorscheme PaperColor
  else
    set background=dark
    let g:airline_theme='gruvbox'
    color gruvbox
  endif
endfunction

@NLKNguyen
Copy link
Owner

Sure, it's good for me to know that there is something inconsistent about this theme. I'm inspecting this. What Go syntax plugin that you are using? I installed vim-go, but the highlighting seems like you are using something else.

@rschmukler
Copy link
Author

I am indeed using vim-go. As far as I know, I am not using anything else modifying my golang syntax. I am using truecolor nvim, if that'd make a difference...

@NLKNguyen
Copy link
Owner

After digging for a while, I finally found a way to solve the problem. It turned out that GruvBox and many other themes like Solarized relink the syntax highlighting groups, provided by the syntax plugins, to the theme's custom syntax highlighting groups. In altercation/solarized#102 tpope says that it's not the color scheme business, and Vim doesn't anticipate that. PaperColor, on the other hand, doesn't relink anything. xolox suggested that the color scheme switching issue is a Vim bug altercation/solarized#102 (comment), so he wrote this plugin https://github.com/xolox/vim-colorscheme-switcher to help handle that.

Now to fix this issue, you just install that plugin then replace your function with this:

" Default is gruvbox dark
set background=dark
colorscheme gruvbox

function! ToggleLightDark()
  if &background == 'dark'
    set background=light
    let g:airline_theme='PaperColor'
    call xolox#colorscheme_switcher#switch_to("PaperColor")
  else
    set background=dark
    let g:airline_theme='gruvbox'
    call xolox#colorscheme_switcher#switch_to("gruvbox")
  endif
endfunction

Note: in my test, it only works if GruvBox is the default, and I don't know why.

@rschmukler
Copy link
Author

@NLKNguyen apologies on the delay. Thank you a ton for the digging and the work around. Awesome theme again. Thanks for sharing it with everyone!

@NLKNguyen
Copy link
Owner

You're welcome :)
I'm working on a revision that enables different color palettes to co-exist on PaperColor. Once that happens, color palettes like GruvBox, Solarized, Molokai can be included within PaperColor easily, and internal theme switching won't be an issue ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants