summaryrefslogtreecommitdiff
path: root/src/highlight.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-09-17 19:59:26 +0200
committerBram Moolenaar <Bram@vim.org>2020-09-17 19:59:26 +0200
commit213da551dec465e193619684b260bf9d5a8d6afc (patch)
tree1be63c2be8d108c905a044db71d7bc5c629d0e10 /src/highlight.c
parentda697645d5917eb3d4168c06c3442bef9fb746bf (diff)
downloadvim-git-213da551dec465e193619684b260bf9d5a8d6afc.tar.gz
patch 8.2.1703: ":highlight clear" does not restore default linkv8.2.1703
Problem: ":highlight clear" does not restore default link. Solution: Remember the default link and restore it. (Antony Scriven, closes #6970, closes #4405)
Diffstat (limited to 'src/highlight.c')
-rw-r--r--src/highlight.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/highlight.c b/src/highlight.c
index 017507924..85745024c 100644
--- a/src/highlight.c
+++ b/src/highlight.c
@@ -73,6 +73,7 @@ typedef struct
char_u *sg_gui_sp_name;// GUI special color name
#endif
int sg_link; // link to this highlight group ID
+ int sg_deflink; // default link; restored in highlight_clear()
int sg_set; // combination of SG_* flags
#ifdef FEAT_EVAL
sctx_T sg_script_ctx; // script in which the group was last set
@@ -715,6 +716,7 @@ do_highlight(
char_u *to_end;
int from_id;
int to_id;
+ hl_group_T *hlgroup = NULL;
from_end = skiptowhite(from_start);
to_start = skipwhite(from_end);
@@ -740,7 +742,14 @@ do_highlight(
else
to_id = syn_check_group(to_start, (int)(to_end - to_start));
- if (from_id > 0 && (!init || HL_TABLE()[from_id - 1].sg_set == 0))
+ if (from_id > 0)
+ {
+ hlgroup = &HL_TABLE()[from_id - 1];
+ if (dodefault && (forceit || hlgroup->sg_deflink == 0))
+ hlgroup->sg_deflink = to_id;
+ }
+
+ if (from_id > 0 && (!init || hlgroup->sg_set == 0))
{
/*
* Don't allow a link when there already is some highlighting
@@ -752,21 +761,20 @@ do_highlight(
if (SOURCING_NAME == NULL && !dodefault)
emsg(_("E414: group has settings, highlight link ignored"));
}
- else if (HL_TABLE()[from_id - 1].sg_link != to_id
+ else if (hlgroup->sg_link != to_id
#ifdef FEAT_EVAL
- || HL_TABLE()[from_id - 1].sg_script_ctx.sc_sid
- != current_sctx.sc_sid
+ || hlgroup->sg_script_ctx.sc_sid != current_sctx.sc_sid
#endif
- || HL_TABLE()[from_id - 1].sg_cleared)
+ || hlgroup->sg_cleared)
{
if (!init)
- HL_TABLE()[from_id - 1].sg_set |= SG_LINK;
- HL_TABLE()[from_id - 1].sg_link = to_id;
+ hlgroup->sg_set |= SG_LINK;
+ hlgroup->sg_link = to_id;
#ifdef FEAT_EVAL
- HL_TABLE()[from_id - 1].sg_script_ctx = current_sctx;
- HL_TABLE()[from_id - 1].sg_script_ctx.sc_lnum += SOURCING_LNUM;
+ hlgroup->sg_script_ctx = current_sctx;
+ hlgroup->sg_script_ctx.sc_lnum += SOURCING_LNUM;
#endif
- HL_TABLE()[from_id - 1].sg_cleared = FALSE;
+ hlgroup->sg_cleared = FALSE;
redraw_all_later(SOME_VALID);
// Only call highlight_changed() once after multiple changes.
@@ -1684,6 +1692,8 @@ highlight_clear(int idx)
HL_TABLE()[idx].sg_gui_attr = 0;
#endif
#ifdef FEAT_EVAL
+ // Restore any default link.
+ HL_TABLE()[idx].sg_link = HL_TABLE()[idx].sg_deflink;
// Clear the script ID only when there is no link, since that is not
// cleared.
if (HL_TABLE()[idx].sg_link == 0)