Repository: neovim/neovim
File: src/nvim/highlight_group.c (C)

Code before:
  int id_S = -1;
  int id_SNC = 0;

  need_highlight_changed = false;

  /// Translate builtin highlight groups into attributes for quick lookup.
  for (int hlf = 0; hlf < HLF_COUNT; hlf++) {
    int id = syn_check_group(hlf_names[hlf], strlen(hlf_names[hlf]));
    if (id == 0) {
      abort();
    }
    int ns_id = -1;
    int final_id = id;
    syn_ns_get_final_id(&ns_id, &final_id);
    if (hlf == HLF_SNC) {
      id_SNC = final_id;
    } else if (hlf == HLF_S) {
      id_S = final_id;
    }

    highlight_attr[hlf] = hl_get_ui_attr(ns_id, hlf, final_id, hlf == HLF_INACTIVE);

    if (highlight_attr[hlf] != highlight_attr_last[hlf]) {
      if (hlf == HLF_MSG) {
        clear_cmdline = true;
        update_cmdline = true;
        HlAttrs attrs = syn_attr2entry(highlight_attr[hlf]);
        msg_grid.blending = attrs.hl_blend > -1;
      }
      ui_call_hl_group_set(cstr_as_string((char *)hlf_names[hlf]),
                           highlight_attr[hlf]);
      highlight_attr_last[hlf] = highlight_attr[hlf];
    }
  }

  // sentinel value. used when no highlight namespace is active
  highlight_attr[HLF_COUNT] = 0;

  //
  // Setup the user highlights
  //
  // Temporarily utilize 10 more hl entries:
  // 9 for User1-User9 combined with StatusLineNC
  // 1 for StatusLine default
  // Must to be in there simultaneously in case of table overflows in
  // get_attr_entry()
  ga_grow(&highlight_ga, 10);
  int hlcnt = highlight_ga.ga_len;
  if (id_S == -1) {
    // Make sure id_S is always valid to simplify code below. Use the last entry
    CLEAR_POINTER(&hl_table[hlcnt + 9]);

Review comment (suggestion):
a new variable in there not be a good choice. tried use `redraw_cmdline` in there seems not works correctly . still use an exist global status variable will be accept I think

Code after:
{
  int hl_id = *hl_idp;
  bool used = false;

  if (hl_id > highlight_ga.ga_len || hl_id < 1) {
    *hl_idp = 0;
    return false;  // Can be called from eval!!
  }

  // Follow links until there is no more.
  // Look out for loops!  Break after 100 links.
  for (int count = 100; --count >= 0;) {
    HlGroup *sgp = &hl_table[hl_id - 1];  // index is ID minus one

    // TODO(bfredl): when using "tmp" attribute (no link) the function might be
    // called twice. it needs be smart enough to remember attr only to
    // syn_id2attr time
    int check = ns_get_hl(ns_id, hl_id, true, sgp->sg_set);
    if (check == 0) {
      *hl_idp = hl_id;
      return true;  // how dare! it broke the link!
    } else if (check > 0) {
      used = true;
      hl_id = check;
      continue;
    }

    if (sgp->sg_link > 0 && sgp->sg_link <= highlight_ga.ga_len) {
      hl_id = sgp->sg_link;
    } else if (sgp->sg_cleared && sgp->sg_parent > 0) {
      hl_id = sgp->sg_parent;
    } else {
      break;
    }
  }

  *hl_idp = hl_id;
  return used;
}

/// Refresh the color attributes of all highlight groups.
void highlight_attr_set_all(void)
{
  for (int idx = 0; idx < highlight_ga.ga_len; idx++) {
    HlGroup *sgp = &hl_table[idx];
    if (sgp->sg_rgb_bg_idx == kColorIdxFg) {
      sgp->sg_rgb_bg = normal_fg;
    } else if (sgp->sg_rgb_bg_idx == kColorIdxBg) {
      sgp->sg_rgb_bg = normal_bg;
    }
    if (sgp->sg_rgb_fg_idx == kColorIdxFg) {