Skip to content

Commit e8df010

Browse files
committed
patch 8.2.1705: "verbose hi Name" reports incorrect info after ":hi clear"
Problem: "verbose hi Name" reports incorrect info after ":hi clear". Solution: Store the script context. (Antony Scriven, closes #6975)
1 parent 77e5dcc commit e8df010

3 files changed

Lines changed: 48 additions & 9 deletions

File tree

src/highlight.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ typedef struct
7676
int sg_deflink; // default link; restored in highlight_clear()
7777
int sg_set; // combination of SG_* flags
7878
#ifdef FEAT_EVAL
79+
sctx_T sg_deflink_sctx; // script where the default link was set
7980
sctx_T sg_script_ctx; // script in which the group was last set
8081
#endif
8182
} hl_group_T;
@@ -746,7 +747,13 @@ do_highlight(
746747
{
747748
hlgroup = &HL_TABLE()[from_id - 1];
748749
if (dodefault && (forceit || hlgroup->sg_deflink == 0))
750+
{
749751
hlgroup->sg_deflink = to_id;
752+
#ifdef FEAT_EVAL
753+
hlgroup->sg_deflink_sctx = current_sctx;
754+
hlgroup->sg_deflink_sctx.sc_lnum += SOURCING_LNUM;
755+
#endif
756+
}
750757
}
751758

752759
if (from_id > 0 && (!init || hlgroup->sg_set == 0))
@@ -1691,16 +1698,12 @@ highlight_clear(int idx)
16911698
VIM_CLEAR(HL_TABLE()[idx].sg_font_name);
16921699
HL_TABLE()[idx].sg_gui_attr = 0;
16931700
#endif
1694-
#ifdef FEAT_EVAL
1695-
// Restore any default link.
1701+
// Restore default link and context if they exist. Otherwise clears.
16961702
HL_TABLE()[idx].sg_link = HL_TABLE()[idx].sg_deflink;
1697-
// Clear the script ID only when there is no link, since that is not
1698-
// cleared.
1699-
if (HL_TABLE()[idx].sg_link == 0)
1700-
{
1701-
HL_TABLE()[idx].sg_script_ctx.sc_sid = 0;
1702-
HL_TABLE()[idx].sg_script_ctx.sc_lnum = 0;
1703-
}
1703+
#ifdef FEAT_EVAL
1704+
// Since we set the default link, set the location to where the default
1705+
// link was set.
1706+
HL_TABLE()[idx].sg_script_ctx = HL_TABLE()[idx].sg_deflink_sctx;
17041707
#endif
17051708
}
17061709

src/testdir/test_highlight.vim

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
source view_util.vim
44
source screendump.vim
55
source check.vim
6+
source script_util.vim
67

78
func Test_highlight()
89
" basic test if ":highlight" doesn't crash
@@ -870,6 +871,39 @@ func Test_highlight_clear_restores_links()
870871
call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
871872
endfunc
872873

874+
func Test_highlight_clear_restores_context()
875+
func FuncContextDefault()
876+
hi def link Context ContextDefault
877+
endfun
878+
879+
func FuncContextRelink()
880+
" Dummy line
881+
hi link Context ContextRelink
882+
endfunc
883+
884+
let scriptContextDefault = MakeScript("FuncContextDefault")
885+
let scriptContextRelink = MakeScript("FuncContextRelink")
886+
let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
887+
let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
888+
889+
exec "source" scriptContextDefault
890+
let hlContextDefault = execute("verbose hi Context")
891+
call assert_match(patContextDefault, hlContextDefault)
892+
893+
exec "source" scriptContextRelink
894+
let hlContextRelink = execute("verbose hi Context")
895+
call assert_match(patContextRelink, hlContextRelink)
896+
897+
hi clear
898+
let hlContextAfterClear = execute("verbose hi Context")
899+
call assert_match(patContextDefault, hlContextAfterClear)
900+
901+
delfunc FuncContextDefault
902+
delfunc FuncContextRelink
903+
call delete(scriptContextDefault)
904+
call delete(scriptContextRelink)
905+
endfunc
906+
873907
func Test_highlight_default_colorscheme_restores_links()
874908
hi link TestLink Identifier
875909
hi TestHi ctermbg=red

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1705,
753755
/**/
754756
1704,
755757
/**/

0 commit comments

Comments
 (0)