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

Persist highlighting on color scheme change #52

Closed
wants to merge 5 commits into from

Conversation

jchros
Copy link
Contributor

@jchros jchros commented Nov 15, 2020

Well-written Vim color schemes run the command :highlight clear to remove the highlight groups set by a previous color scheme. Unfortunately, this also removes the internal highlight group set by vim-exchange, effectively disabling vim-exchange's highlighting, and running :XchangeHighlightToggle does not reenable the plugin's highlighting, as demonstrated in the asciinema below:

asciicast

In this pull request, this is fixed by adding an autocmd to link the _exchange_region highlight group back to ExchangeRegion when the colorscheme is changed and the highlighting is enabled.

Alternatives considered

Toggle highlighting twice

I have rejected this approach for 2 reasons:

  • Allow for chaining of commands #51 must be merged first, otherwise changing the color schemes raises the following error:
    Error detected while processing ColorScheme Autocommands for "*":
    E488: Trailing characters: | XchangeHighlightToggle: XchangeHighlightToggle | XchangeHighlightToggle
    
  • It feels like a hack to me.

Well-written Vim color schemes run the command :highlight clear to
remove the highlight groups set by a previous color scheme.
Unfortunately, this also removes the internal highlight group set by
vim-exchange, effectively disabling vim-exchange's highlighting, and
running :XchangeHighlightToggle does not reenable the plugin's
highlighting.

In this commit, this is fixed by adding an autocmd to link the
_exchange_region highlight group back to ExchangeRegion when the color
scheme is changed and the highlighting is enabled.
@tommcdo
Copy link
Owner

tommcdo commented Dec 16, 2020

I hadn't had time to look into this in-depth, but I'm wondering if #53 addresses the issue?

@jchros
Copy link
Contributor Author

jchros commented Dec 16, 2020

I hadn't had time to look into this in-depth, but I'm wondering if #53 addresses the issue?

I just tried it (on Vim 8.2.2127) and it does fix the issue; thanks for replying!

@jchros jchros closed this Dec 16, 2020
@jchros
Copy link
Contributor Author

jchros commented Dec 20, 2020

I am reopening this pull request because I've noticed that #53 introduces the opposite problem; when the highlighting is turned off, changing the color scheme turns it back on, as demonstrated in the video below:

test1.mov

The persist-hl-on-cs-change branch does not exhibit this behavior.

@jchros jchros reopened this Dec 20, 2020
jchros and others added 4 commits December 20, 2020 14:56
New vim restores default highlight links, but fails to do it when there is no default link in the first place.

Without this fix, vim-exchange looses highlighting after `:colorscheme ...`

Relates to vim/vim#6970
Co-authored-by: Tom McDonald <tommcdo@gmail.com>
This reverts commit 17f1a2c, reversing
changes made to 13d3895.
@jchros jchros closed this Dec 20, 2020
@jchros jchros deleted the persist-hl-on-cs-change branch December 20, 2020 14:07
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 this pull request may close these issues.

None yet

3 participants