#78 make a highlight group impervious to hi clear

open
nobody
5
2013-02-05
2013-02-05
Anonymous
No

The standard procedure for a color scheme file is to first call `highlight clear`, which clears out all highlight groups defined by the user, including any that may be defined by scripts such as plugins. Because plugins are loaded before vimrcs, any groups defined in plugins are cleared when a colorscheme is loaded from a vimrc.

For example, I have a tabline plugin that I wrote which has a default set of non-standard highlight groups. These are group names that will not be redefined by a standard colorscheme script, yet they are cleared whenever a colorscheme is loaded at init time or during runtime. I've had to resort to an ugly workaround using a sentinel highlight group that I check during runtime to determine if I need to re-set my highlight groups.

I'd prefer a solution where I could make my custom highlight groups "sticky" so that a generic `highlight clear` does not clear them. Maybe something like: `highlight noclear MyGroup cterm=...`. In this scenario, `highlight clear` could perhaps set a flag on MyGroup that a clear had been attempted, and then any subsequent `highlight MyGroup ...` statements would be permitted to completely override MyGroup. This would prevent rogue use of `noclear` on standard groups.

Another possibility would be to incorporate scoping for highlight groups, such as `highlight s:MyGroup`, which would only be clearable with the correct <SID> prefix. This would also open the possibility for buffer-scoped highlight groups, which some people might want to have per-filetype syntax highlighting.

Discussion


  • Anonymous
    2013-02-05

    EDIT: I found a slightly better solution to my problem which is to use a ColorScheme autocmd to re-set my highlight groups, but this is still more work at runtime that could be avoided.