problem: users are unable to restore default highlighting
solution: treat cleared highlight group as "has no hl-settings"
Fixes #4405
https://github.com/vim/vim/pull/6956
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Merging #6956 into master will increase coverage by
0.03%.
The diff coverage is100.00%.
@@ Coverage Diff @@ ## master #6956 +/- ## ========================================== + Coverage 88.55% 88.58% +0.03% ========================================== Files 148 148 Lines 161412 161413 +1 ========================================== + Hits 142936 142993 +57 + Misses 18476 18420 -56
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/highlight.c | 90.31% <100.00%> (+<0.01%) |
⬆️ |
| src/ex_getln.c | 91.34% <0.00%> (-0.35%) |
⬇️ |
| src/getchar.c | 86.20% <0.00%> (-0.30%) |
⬇️ |
| src/gui_gtk_x11.c | 58.73% <0.00%> (+0.09%) |
⬆️ |
| src/sign.c | 94.94% <0.00%> (+0.17%) |
⬆️ |
| src/if_xcmdsrv.c | 88.73% <0.00%> (+0.17%) |
⬆️ |
| src/drawline.c | 84.91% <0.00%> (+0.20%) |
⬆️ |
| src/gui_gtk.c | 31.67% <0.00%> (+0.27%) |
⬆️ |
| src/term.c | 82.95% <0.00%> (+0.43%) |
⬆️ |
| src/profiler.c | 93.03% <0.00%> (+0.55%) |
⬆️ |
| ... and 4 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered by Codecov. Last update 9b123d8...a673b34. Read the comment docs.
I'm wondering: would it also work to remove the SG_LINK flag from sg_set in highlight_clear() ?
Since you know what you are fixing, can you also add a test for that?
In case I wasn't clear before, I'm wondering if could you save sg_link
in do_highlight() when doing ":hi def link", and then restore it in
highlight_clear(). Or would there be unintended consequences?
I've not had any highlighting issues since trying it out (altering links
and then changing colorschemes), but I'm not a heavy user of syntax
highlighting and I'm not sure what the implications would be.
--Antony
Since you know what you are fixing, can you also add a test for that?
Test has been added.
I'm wondering: would it also work to remove the SG_LINK flag from sg_set in highlight_clear() ?
Looks like it also solves the issue.
Removed check for cleared in hl_has_settings
Added HL_TABLE()[idx].sg_set = 0; to highlight_clear
Should I make this change instead?
Should I make this change instead?
It looks like this flag is reset outside of the highlight_clear:
https://github.com/vim/vim/blob/8b51b7f0f17af149a8ce76e805050977857f9e50/src/highlight.c#L882-L888
But I am not sure if there is a combination of forceit==1 and init==1 and doclear == 0 we can call from vimscript, as was revealed by @andymass: #4405 (comment)
> I think that proper check for cleared in 'hl_has_settings' is simpler
> though.
Yeah I know. I'm only mentioning this alternative because it doesn't
require that syntax is reloaded. This seems to be welcome behaviour but
I can't decide whether this is an intrusive change or not. --Antony
Bram, I have actually just pushed a new variant, like a seconds before you closed the PR :)
It might be better in the end, but it is up to you to decide.
This approach is from Antony Scriven @adscriven:
- default hi-links are saved on
hi def- and restored in
hi clearHaving this user doesn't have to do neither
syntax onnorsyntax enableto be able to apply default links on a cleared highlight groups.Thus there will be no need to update old colorschemes to make it work.
@habamax does Bram's commit resolve the issue I pointed out in that comment? (If so can you briefly explain how?)
@andymass there is a code path checking if default link is being set for a highlight group and if it has any settings.
// Return if "default" was used and the group already has settings.
if (dodefault && hl_has_settings(idx, TRUE))
return;
That function was always false for a cleared highlight group thus preventing :hi def GroupName
So with the patch cleared hi group is treated as the group without hl-settings.
—
It is in an old PR as a new commit, I can make it as a separate PR.
ср, 16 сент. 2020 г., 22:50 Bram Moolenaar <notifi...@github.com>:
> > E.g. syntax/html.vim links htmlTagName to Statement, but a fancy
> > colorscheme may choose to give htmlTagName specific colours. This sort
> > of thing happens frequently.
> >
> > If you then switch from one of these fancy colorschemes to one that uses
> > only the standard groups, htmlTagName won't be highlighted with
> > Statement colours as you might expect, because the link has gone. It
> > looks like the second colorscheme is broken.
> >
> > The idea was that if default links as well as default colours are
> > restored on ":hi clear", then colorschemes will be working with a more
> > consistent initial state, and produce the colours that the user expects
> > to see.
>
> Can you make a new pull request, so we can see the difference with the
> already included solution? The test would also need updating.
after look over #6970, maybe a silly question but one concern:
if one colorscheme was on, and it set or override one 'hi def', then now issued 'colo default' (had a 'hi clear'), what would happened on that 'hi def', or just supposed that/all 'hi def' would not impact (not existed in) 'colo default' ?
specially 'hi clear', perhaps i would run 'hi clear' and/or specially some vim scripts had 'hi clear' in it, but user did not expect those such kind 'hi def' impact its previous logic/effect.
was it possible to happen, or i missunderstood sth ?
means just wish really only the default 'hi def' which not 3rd-party made ones to be restored after 'hi clear'.
after look over #6970, maybe a silly question but one concern:
if one colorscheme was on, and it set or override one 'hi def', then now issued 'colo default' (had a 'hi clear'), what would happened on that 'hi def', or just supposed that/all 'hi def' would not impact (not existed in) 'colo default' ?
if there was no syntax loaded, meaning there was no :hi def GroupName defined, then colorscheme will define it and :hi clear will make it cleared:
Colorscheme redefines
:hi vimOption ctermbg=red
Then you do:
:hi clear
:hi vimOption --> cleared
Before the patch, it would stay cleared and it was impossible to make it default again as :hi def vimOption just didn't work for cleared. You could only override it with :hi vimOption in some other colorscheme.
specially 'hi clear', perhaps i would run 'hi clear' and/or specially some vim scripts had 'hi clear' in it, but user did not expect those such kind 'hi def' impact its previous logic/effect.
was it possible to happen, or i missunderstood sth ?
means just wish really only the default 'hi def' which not 3rd-party made ones to be restored after 'hi clear'.
With the #6970 patch vim also restores default links defined in syntax files, thus if some colorscheme redefines vimOption it would be restored on :hi clear as if it was initially defined in syntax file.
If you check issue description it has all the details: #4405
Before the patch, it would stay cleared and it was impossible to make it default again as
:hi def vimOptionjust didn't work for cleared. You could only override it with:hi vimOptionin some other colorscheme.
yes, that is what i am doing for 'restore' default.
With the #6970 patch vim also restores default links defined in syntax files, thus if some colorscheme redefines vimOption it would be restored on
:hi clearas if it was initially defined in syntax file.
actually my concern was - for example:
one 3rd part colorschema had a 'hi! def link difftext foo' in it, then now, after your patch, whatever 'colo default' or 'hi clear', after one of them, what would happened, would it back to original 'difftext' ? just wish you gave me a confirm answer. :)
actually my concern was - for example:
one 3rd part colorschema had a 'hi! def link difftext foo' in it, then now, after your patch, whatever 'colo default' or 'hi clear', after one of them, what would happened, would it back to original 'difftext' ? or still is 'foo' ? since now that 'def link' is 'foo' now.
just wish you gave me a confirm answer. :)
with patches:
hi difftext
output:
DiffText xxx term=reverse cterm=bold ctermbg=9 gui=bold guibg=Red
hi! def link difftext foo
hi difftext
output:
DiffText xxx term=reverse cterm=bold ctermbg=9 gui=bold guibg=Red
links to foo
colo default
hi difftext
output:
DiffText xxx term=reverse cterm=bold ctermbg=9 gui=bold guibg=Red
good, looks nice. would try again after/if that patch merged. thx.
tried (that pr merged today), so far have not found side-effect, but one maybe a tiny issue: the bg after 'colo default' did not recover to that ft syntax default, then hi/color actually (by eye) was not really same like it was (that ft default).
and #6975 looks found sth, btw.
// anyway, i actually did not count on this to restore default, just wish it would not impact user previous code.