Skip to content

Commit

Permalink
add back autocmd for pandoc setup after colorscheme switch
Browse files Browse the repository at this point in the history
as kindly pointed out by @chrisbra
  • Loading branch information
Konfekt authored Apr 9, 2024
1 parent 7a7951b commit 4550845
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions syntax/pandoc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,33 @@ function! s:SetupPandocHighlights()
hi def link pandocHRule Delimiter
endfunction

" Whenever the colorscheme changes, all highlights are cleared.
"
" The most common circumstance is that the vimrc picks a colorscheme *at
" startup*, then a file is opened and the syntax is set based on that file. So
" the most common situation is that the colorscheme runs, then the syntax
" runs, and that's that. So if the code for the syntax (e.g., this code here
" in vim-pandoc-syntax) *adds* new highlighting groups that weren't defined in
" the colorscheme, that's almost always fine because the colorscheme rarely
" changes after startup.
"
" But the colorscheme *can* change after startup. This happens for example any
" time the user toggles their background (:set bg=light or :set bg=dark), or
" picks another colorscheme (:colorscheme something_else). In these cases, the
" new colorscheme calls `:highlight clear`, clearing any custom pandoc
" highlighting groups.
"
" The solution is to register an autocommand that runs whenever the
" ColorScheme changes, so that we can re-register vim-pandoc-syntax's custom
" highlighting groups, after the new colorscheme has cleared them.
"
" (This also affects popular plugins like goyo.vim, which call `:colorscheme`
" with your chosen colorscheme to approximate undoing any custom highlighting
" modifications that they've made.)
augroup vim-pandoc-syntax
autocmd!
autocmd ColorScheme * call s:SetupPandocHighlights()
augroup end
call s:SetupPandocHighlights()

" }}}1
Expand Down

0 comments on commit 4550845

Please sign in to comment.