Patch 8.2.3536
Problem:The do_highlight() function is way too long.
Solution: Split it into several functions. (Yegappan Lakshmanan,
closes #9011)
Files: src/highlight.c
*** ../vim-8.2.3535/src/highlight.c 2021-10-15 22:25:37.785385044 +0100
--- src/highlight.c 2021-10-18 22:12:59.041516541 +0100
***
*** 377,386
#ifdef FEAT_EVAL
char_u*p;
! /*
! * Try finding the color scheme file. Used when a color file was loaded
! * and 'background' or 't_Co' is changed.
! */
p = get_var_value((char_u *)"g:colors_name");
if (p != NULL)
{
--- 377,384
#ifdef FEAT_EVAL
char_u*p;
! // Try finding the color scheme file. Used when a color file was loaded
! // and 'background' or 't_Co' is changed.
p = get_var_value((char_u *)"g:colors_name");
if (p != NULL)
{
***
*** 400,408
#endif
! /*
! * Didn't use a color file, use the compiled-in colors.
! */
if (both)
{
had_both = TRUE;
--- 398,404
#endif
! // Didn't use a color file, use the compiled-in colors.
if (both)
{
had_both = TRUE;
***
*** 441,449
}
#ifdef FEAT_SYN_HL
! /*
! * If syntax highlighting is enabled load the highlighting for it.
! */
if (get_var_value((char_u *)"g:syntax_on") != NULL)
{
static int recursive = 0;
--- 437,443
}
#ifdef FEAT_SYN_HL
! // If syntax highlighting is enabled load the highlighting for it.
if (get_var_value((char_u *)"g:syntax_on") != NULL)
{
static int recursive = 0;
***
*** 581,591
else if (t_colors == 16 || t_colors == 88
|| t_colors >= 256)
{
! /*
!* Guess: if the termcap entry ends in 'm', it is
!* probably an xterm-like terminal. Use the changed
!* order for colors.
!*/
if (*T_CAF != NUL)
p = T_CAF;
else
--- 575,583
else if (t_colors == 16 || t_colors == 88
|| t_colors >= 256)
{
! // Guess: if the termcap entry ends in 'm', it is
! // probably an xterm-like terminal. Use the changed
! // order for colors.
if (*T_CAF != NUL)
p = T_CAF;
else
***
*** 611,616
--- 603,1360
}
/*
+ * Link highlight group 'from_hg' to 'to_hg'.
+ * 'dodefault' is set to TRUE for ":highlight default link".
+ * 'forceit' is set to TRUE for ":higlight! link"
+ * 'init' is set to TRUE when initializing all the highlight groups.
+ */
+ static void
+ highlight_group_link(
+ char_u *from_hg,
+ int from_len,
+ char_u *to_hg,
+ int to_len,
+ int dodefault,
+ int forceit,
+ int init)
+ {
+ int from_id;
+ int to_id;
+ hl_group_T*hlgroup = NULL;
+
+ from_id = syn_check_group(from_hg, from_len);
+ if (STRNCMP(to_hg, "NONE", 4) == 0)
+ to_id = 0;
+ else
+ to_id = syn_check_group(to_hg, to_len);
+
+ if (from_id > 0)
+ {
+ hlgroup = &HL_TABLE()[from_id - 1];
+ if (dodefault && (forceit || hlgroup->sg_deflink == 0))
+ {
+ hlgroup->sg_deflink = to_id;
+ #ifdef FEAT_EVAL
+ hlgroup->sg_deflink_sctx = current_sctx;
+ hlgroup->sg_deflink_sctx.sc_lnum += SOURCING_LNUM;
+ #endif
+ }
+ }
+
+ if (from_id > 0 && (!init || hlgroup->sg_set == 0))
+ {
+ // Don't allow a link when there already is some highlighting
+ // for the group, unless '!' is used
+ if (to_id > 0 && !forceit && !init
+ && hl_has_settings(from_id - 1, dodefault))
+ {
+ if (SOURCING_NAME == NULL && !dodefault)
+ emsg(_("E414: group has settings, highlight link ignored"));
+ }
+ else if (hlgroup->sg_link != to_id
+ #ifdef FEAT_EVAL
+ || hlgroup->sg_script_ctx.sc_sid != current_sctx.sc_sid
+ #endif
+ || hlgroup->sg_cleared)
+ {
+ if (!init)
+ hlgroup->sg_set |= SG_LINK;
+ hlgroup->sg_link = to_id;
+ #ifdef FEAT_EVAL
+ hlgroup->sg_script_ctx = current_sctx;
+ hlgroup->sg_script_ctx.sc_lnum += SOURCING_LNUM;
+ #endif
+ hlgroup->sg_cleared = FALSE;
+ redraw_all_later(SOME_VALID);
+
+ // Only call highlight_changed() once after multiple changes.
+ need_highlight_changed =