comparison src/highlight.c @ 22308:19e0784ef769 v8.2.1703

patch 8.2.1703: ":highlight clear" does not restore default link Commit: https://github.com/vim/vim/commit/213da551dec465e193619684b260bf9d5a8d6afc Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 17 19:59:26 2020 +0200 patch 8.2.1703: ":highlight clear" does not restore default link Problem: ":highlight clear" does not restore default link. Solution: Remember the default link and restore it. (Antony Scriven, closes #6970, closes #4405)
author Bram Moolenaar <Bram@vim.org>
date Thu, 17 Sep 2020 20:00:07 +0200
parents a9ff3e0d6d54
children e06ba60fbbd8
comparison
equal deleted inserted replaced
22307:f43d6cbbaa5b 22308:19e0784ef769
71 char_u *sg_gui_fg_name;// GUI foreground color name 71 char_u *sg_gui_fg_name;// GUI foreground color name
72 char_u *sg_gui_bg_name;// GUI background color name 72 char_u *sg_gui_bg_name;// GUI background color name
73 char_u *sg_gui_sp_name;// GUI special color name 73 char_u *sg_gui_sp_name;// GUI special color name
74 #endif 74 #endif
75 int sg_link; // link to this highlight group ID 75 int sg_link; // link to this highlight group ID
76 int sg_deflink; // default link; restored in highlight_clear()
76 int sg_set; // combination of SG_* flags 77 int sg_set; // combination of SG_* flags
77 #ifdef FEAT_EVAL 78 #ifdef FEAT_EVAL
78 sctx_T sg_script_ctx; // script in which the group was last set 79 sctx_T sg_script_ctx; // script in which the group was last set
79 #endif 80 #endif
80 } hl_group_T; 81 } hl_group_T;
713 char_u *from_end; 714 char_u *from_end;
714 char_u *to_start; 715 char_u *to_start;
715 char_u *to_end; 716 char_u *to_end;
716 int from_id; 717 int from_id;
717 int to_id; 718 int to_id;
719 hl_group_T *hlgroup = NULL;
718 720
719 from_end = skiptowhite(from_start); 721 from_end = skiptowhite(from_start);
720 to_start = skipwhite(from_end); 722 to_start = skipwhite(from_end);
721 to_end = skiptowhite(to_start); 723 to_end = skiptowhite(to_start);
722 724
738 if (STRNCMP(to_start, "NONE", 4) == 0) 740 if (STRNCMP(to_start, "NONE", 4) == 0)
739 to_id = 0; 741 to_id = 0;
740 else 742 else
741 to_id = syn_check_group(to_start, (int)(to_end - to_start)); 743 to_id = syn_check_group(to_start, (int)(to_end - to_start));
742 744
743 if (from_id > 0 && (!init || HL_TABLE()[from_id - 1].sg_set == 0)) 745 if (from_id > 0)
746 {
747 hlgroup = &HL_TABLE()[from_id - 1];
748 if (dodefault && (forceit || hlgroup->sg_deflink == 0))
749 hlgroup->sg_deflink = to_id;
750 }
751
752 if (from_id > 0 && (!init || hlgroup->sg_set == 0))
744 { 753 {
745 /* 754 /*
746 * Don't allow a link when there already is some highlighting 755 * Don't allow a link when there already is some highlighting
747 * for the group, unless '!' is used 756 * for the group, unless '!' is used
748 */ 757 */
750 && hl_has_settings(from_id - 1, dodefault)) 759 && hl_has_settings(from_id - 1, dodefault))
751 { 760 {
752 if (SOURCING_NAME == NULL && !dodefault) 761 if (SOURCING_NAME == NULL && !dodefault)
753 emsg(_("E414: group has settings, highlight link ignored")); 762 emsg(_("E414: group has settings, highlight link ignored"));
754 } 763 }
755 else if (HL_TABLE()[from_id - 1].sg_link != to_id 764 else if (hlgroup->sg_link != to_id
756 #ifdef FEAT_EVAL 765 #ifdef FEAT_EVAL
757 || HL_TABLE()[from_id - 1].sg_script_ctx.sc_sid 766 || hlgroup->sg_script_ctx.sc_sid != current_sctx.sc_sid
758 != current_sctx.sc_sid 767 #endif
759 #endif 768 || hlgroup->sg_cleared)
760 || HL_TABLE()[from_id - 1].sg_cleared)
761 { 769 {
762 if (!init) 770 if (!init)
763 HL_TABLE()[from_id - 1].sg_set |= SG_LINK; 771 hlgroup->sg_set |= SG_LINK;
764 HL_TABLE()[from_id - 1].sg_link = to_id; 772 hlgroup->sg_link = to_id;
765 #ifdef FEAT_EVAL 773 #ifdef FEAT_EVAL
766 HL_TABLE()[from_id - 1].sg_script_ctx = current_sctx; 774 hlgroup->sg_script_ctx = current_sctx;
767 HL_TABLE()[from_id - 1].sg_script_ctx.sc_lnum += SOURCING_LNUM; 775 hlgroup->sg_script_ctx.sc_lnum += SOURCING_LNUM;
768 #endif 776 #endif
769 HL_TABLE()[from_id - 1].sg_cleared = FALSE; 777 hlgroup->sg_cleared = FALSE;
770 redraw_all_later(SOME_VALID); 778 redraw_all_later(SOME_VALID);
771 779
772 // Only call highlight_changed() once after multiple changes. 780 // Only call highlight_changed() once after multiple changes.
773 need_highlight_changed = TRUE; 781 need_highlight_changed = TRUE;
774 } 782 }
1682 # endif 1690 # endif
1683 VIM_CLEAR(HL_TABLE()[idx].sg_font_name); 1691 VIM_CLEAR(HL_TABLE()[idx].sg_font_name);
1684 HL_TABLE()[idx].sg_gui_attr = 0; 1692 HL_TABLE()[idx].sg_gui_attr = 0;
1685 #endif 1693 #endif
1686 #ifdef FEAT_EVAL 1694 #ifdef FEAT_EVAL
1695 // Restore any default link.
1696 HL_TABLE()[idx].sg_link = HL_TABLE()[idx].sg_deflink;
1687 // Clear the script ID only when there is no link, since that is not 1697 // Clear the script ID only when there is no link, since that is not
1688 // cleared. 1698 // cleared.
1689 if (HL_TABLE()[idx].sg_link == 0) 1699 if (HL_TABLE()[idx].sg_link == 0)
1690 { 1700 {
1691 HL_TABLE()[idx].sg_script_ctx.sc_sid = 0; 1701 HL_TABLE()[idx].sg_script_ctx.sc_sid = 0;