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

Fix :GoSameIds for light background, GUI, and after changing colour schemes #983

Merged
merged 2 commits into from
Aug 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions syntax/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,27 @@ if g:go_highlight_build_constraints != 0
hi def link goPackageComment Comment
endif

" :GoSameIds
hi def goSameId term=bold cterm=bold ctermbg=white ctermfg=black

" :GoCoverage commands
hi def link goCoverageNormalText Comment
hi def goCoverageCovered ctermfg=green guifg=#A6E22E
hi def goCoverageUncover ctermfg=red guifg=#F92672

function! s:hi()
" :GoSameIds
if &background == 'dark'
hi def goSameId term=bold cterm=bold ctermbg=white ctermfg=black guibg=white guifg=black
else
hi def goSameId term=bold cterm=bold ctermbg=14 guibg=Cyan
endif

" :GoCoverage commands
hi def goCoverageCovered ctermfg=green guifg=#A6E22E
hi def goCoverageUncover ctermfg=red guifg=#F92672
endfunction

augroup vim-go-hi
autocmd!
autocmd ColorScheme * call s:hi()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we apply ColorScheme to all files? And why do we have it?

Copy link
Contributor Author

@arp242 arp242 Aug 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern for the ColorScheme autocommand is matched against the colour scheme name, not the file name (see :help ColorScheme).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrigth, back to my question. Why do we need to call this automatically?

Copy link
Contributor Author

@arp242 arp242 Aug 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed because using :colorscheme foo will reset all custom highlight groups − see the message above:

  :hi goSameId
  goSameId       xxx term=bold cterm=bold ctermfg=0 ctermbg=121

  :colorscheme default

  :hi goSameId
  goSameId       xxx cleared

It's a bit ugly, but as far as I know there's no "clean" way to avoid this...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand the case. So you mean we have to add this for users who override it? colorscheme is only called once in vimrc. Or is this for people who dynamically change the colorscheme ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few different scenarios:

  • Perhaps the most common case is when you reload the vimrc file with :source ~/.vim/vimrc. This will run the colorscheme command but won't re-run the syntax files (you can use :e to fix this though, but it's annoying).
  • I've seen some people use different colour schemes for different filetypes − this autocommand will be run after the syntax file and there is no real way to fix this other than than the above ColorScheme autocommand.
  • As you mentioned, it helps people who change colour schemes while Vim is running. I know some people who like to switch between a dark and light version depending on ambient light conditions. Again, :e will fix this, but it's annoying.

augroup end
call s:hi()

" Search backwards for a global declaration to start processing the syntax.
"syn sync match goSync grouphere NONE /^\(const\|var\|type\|func\)\>/
Expand Down