Skip to content

Commit 2ac6e82

Browse files
committed
patch 8.1.1699: highlight_ga can be local instead of global
Problem: Highlight_ga can be local instead of global. Solution: Move highlight_ga into highlight.c. (Yegappan Lakshmanan, closes #4675)
1 parent 5d68445 commit 2ac6e82

6 files changed

Lines changed: 102 additions & 70 deletions

File tree

src/globals.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,6 @@ EXTERN char_u hash_removed;
355355
EXTERN int scroll_region INIT(= FALSE); /* term supports scroll region */
356356
EXTERN int t_colors INIT(= 0); /* int value of T_CCO */
357357

358-
// highlight groups for 'highlight' option
359-
EXTERN garray_T highlight_ga INIT(= {0 COMMA 0 COMMA sizeof(hl_group_T) COMMA 10 COMMA NULL});
360-
361358
#ifdef FEAT_CMDL_COMPL
362359
// Flags to indicate an additional string for highlight name completion.
363360
EXTERN int include_none INIT(= 0); // when 1 include "None"

src/highlight.c

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,64 @@ static int hl_attr_table[] =
2929
{HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_ITALIC, HL_INVERSE, HL_INVERSE, HL_NOCOMBINE, HL_STRIKETHROUGH, 0};
3030
#define ATTR_COMBINE(attr_a, attr_b) ((((attr_b) & HL_NOCOMBINE) ? attr_b : (attr_a)) | (attr_b))
3131

32+
/*
33+
* Structure that stores information about a highlight group.
34+
* The ID of a highlight group is also called group ID. It is the index in
35+
* the highlight_ga array PLUS ONE.
36+
*/
37+
typedef struct
38+
{
39+
char_u *sg_name; // highlight group name
40+
char_u *sg_name_u; // uppercase of sg_name
41+
int sg_cleared; // "hi clear" was used
42+
// for normal terminals
43+
int sg_term; // "term=" highlighting attributes
44+
char_u *sg_start; // terminal string for start highl
45+
char_u *sg_stop; // terminal string for stop highl
46+
int sg_term_attr; // Screen attr for term mode
47+
// for color terminals
48+
int sg_cterm; // "cterm=" highlighting attr
49+
int sg_cterm_bold; // bold attr was set for light color
50+
int sg_cterm_fg; // terminal fg color number + 1
51+
int sg_cterm_bg; // terminal bg color number + 1
52+
int sg_cterm_attr; // Screen attr for color term mode
53+
// for when using the GUI
54+
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
55+
guicolor_T sg_gui_fg; // GUI foreground color handle
56+
guicolor_T sg_gui_bg; // GUI background color handle
57+
#endif
58+
#ifdef FEAT_GUI
59+
guicolor_T sg_gui_sp; // GUI special color handle
60+
GuiFont sg_font; // GUI font handle
61+
#ifdef FEAT_XFONTSET
62+
GuiFontset sg_fontset; // GUI fontset handle
63+
#endif
64+
char_u *sg_font_name; // GUI font or fontset name
65+
int sg_gui_attr; // Screen attr for GUI mode
66+
#endif
67+
#if defined(FEAT_GUI) || defined(FEAT_EVAL)
68+
// Store the sp color name for the GUI or synIDattr()
69+
int sg_gui; // "gui=" highlighting attributes
70+
char_u *sg_gui_fg_name;// GUI foreground color name
71+
char_u *sg_gui_bg_name;// GUI background color name
72+
char_u *sg_gui_sp_name;// GUI special color name
73+
#endif
74+
int sg_link; // link to this highlight group ID
75+
int sg_set; // combination of SG_* flags
76+
#ifdef FEAT_EVAL
77+
sctx_T sg_script_ctx; // script in which the group was last set
78+
#endif
79+
} hl_group_T;
80+
81+
// highlight groups for 'highlight' option
82+
static garray_T highlight_ga;
83+
#define HL_TABLE() ((hl_group_T *)((highlight_ga.ga_data)))
84+
85+
/*
86+
* An attribute number is the index in attr_table plus ATTR_OFF.
87+
*/
88+
#define ATTR_OFF (HL_ALL + 1)
89+
3290
static void syn_unadd_group(void);
3391
static void set_hl_attr(int idx);
3492
static void highlight_list_one(int id);
@@ -45,11 +103,6 @@ static int set_group_colors(char_u *name, guicolor_T *fgp, guicolor_T *bgp, int
45103
static void hl_do_font(int idx, char_u *arg, int do_normal, int do_menu, int do_tooltip, int free_font);
46104
#endif
47105

48-
/*
49-
* An attribute number is the index in attr_table plus ATTR_OFF.
50-
*/
51-
#define ATTR_OFF (HL_ALL + 1)
52-
53106
/*
54107
* The default highlight groups. These are compiled-in for fast startup and
55108
* they still work when the runtime files can't be found.
@@ -289,6 +342,33 @@ static char *(highlight_init_dark[]) = {
289342
NULL
290343
};
291344

345+
/*
346+
* Returns the number of highlight groups.
347+
*/
348+
int
349+
highlight_num_groups(void)
350+
{
351+
return highlight_ga.ga_len;
352+
}
353+
354+
/*
355+
* Returns the name of a highlight group.
356+
*/
357+
char_u *
358+
highlight_group_name(int id)
359+
{
360+
return HL_TABLE()[id].sg_name;
361+
}
362+
363+
/*
364+
* Returns the ID of the link to a highlight group.
365+
*/
366+
int
367+
highlight_link_id(int id)
368+
{
369+
return HL_TABLE()[id].sg_link;
370+
}
371+
292372
void
293373
init_highlight(
294374
int both, // include groups where 'bg' doesn't matter

src/proto/highlight.pro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/* highlight.c */
2+
int highlight_num_groups(void);
3+
char_u *highlight_group_name(int id);
4+
int highlight_link_id(int id);
25
void init_highlight(int both, int reset);
36
int load_colors(char_u *name);
47
int lookup_color(int idx, int foreground, int *boldp);
@@ -23,7 +26,7 @@ attrentry_T *syn_cterm_attr2entry(int attr);
2326
char_u *highlight_has_attr(int id, int flag, int modec);
2427
char_u *highlight_color(int id, char_u *what, int modec);
2528
long_u highlight_gui_color_rgb(int id, int fg);
26-
int syn_list_header(int did_header, int outlen, int id);
29+
int syn_list_header(int did_header, int outlen, int id);
2730
int syn_name2id(char_u *name);
2831
int syn_name2attr(char_u *name);
2932
int highlight_exists(char_u *name);

src/structs.h

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -999,56 +999,6 @@ struct syn_state
999999
};
10001000
#endif // FEAT_SYN_HL
10011001

1002-
/*
1003-
* Structure that stores information about a highlight group.
1004-
* The ID of a highlight group is also called group ID. It is the index in
1005-
* the highlight_ga array PLUS ONE.
1006-
*/
1007-
typedef struct
1008-
{
1009-
char_u *sg_name; // highlight group name
1010-
char_u *sg_name_u; // uppercase of sg_name
1011-
int sg_cleared; // "hi clear" was used
1012-
// for normal terminals
1013-
int sg_term; // "term=" highlighting attributes
1014-
char_u *sg_start; // terminal string for start highl
1015-
char_u *sg_stop; // terminal string for stop highl
1016-
int sg_term_attr; // Screen attr for term mode
1017-
// for color terminals
1018-
int sg_cterm; // "cterm=" highlighting attr
1019-
int sg_cterm_bold; // bold attr was set for light color
1020-
int sg_cterm_fg; // terminal fg color number + 1
1021-
int sg_cterm_bg; // terminal bg color number + 1
1022-
int sg_cterm_attr; // Screen attr for color term mode
1023-
// for when using the GUI
1024-
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
1025-
guicolor_T sg_gui_fg; // GUI foreground color handle
1026-
guicolor_T sg_gui_bg; // GUI background color handle
1027-
#endif
1028-
#ifdef FEAT_GUI
1029-
guicolor_T sg_gui_sp; // GUI special color handle
1030-
GuiFont sg_font; // GUI font handle
1031-
#ifdef FEAT_XFONTSET
1032-
GuiFontset sg_fontset; // GUI fontset handle
1033-
#endif
1034-
char_u *sg_font_name; // GUI font or fontset name
1035-
int sg_gui_attr; // Screen attr for GUI mode
1036-
#endif
1037-
#if defined(FEAT_GUI) || defined(FEAT_EVAL)
1038-
// Store the sp color name for the GUI or synIDattr()
1039-
int sg_gui; // "gui=" highlighting attributes
1040-
char_u *sg_gui_fg_name;// GUI foreground color name
1041-
char_u *sg_gui_bg_name;// GUI background color name
1042-
char_u *sg_gui_sp_name;// GUI special color name
1043-
#endif
1044-
int sg_link; // link to this highlight group ID
1045-
int sg_set; // combination of SG_* flags
1046-
#ifdef FEAT_EVAL
1047-
sctx_T sg_script_ctx; // script in which the group was last set
1048-
#endif
1049-
} hl_group_T;
1050-
1051-
#define HL_TABLE() ((hl_group_T *)((highlight_ga.ga_data)))
10521002
#define MAX_HL_ID 20000 // maximum value for a highlight ID.
10531003

10541004
/*

src/syntax.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,7 +3847,7 @@ syn_cmd_list(
38473847
/*
38483848
* No argument: List all group IDs and all syntax clusters.
38493849
*/
3850-
for (id = 1; id <= highlight_ga.ga_len && !got_int; ++id)
3850+
for (id = 1; id <= highlight_num_groups() && !got_int; ++id)
38513851
syn_list_one(id, syncing, FALSE);
38523852
for (id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id)
38533853
syn_list_cluster(id);
@@ -3995,7 +3995,7 @@ syn_list_one(
39953995
if (SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_SKIP)
39963996
put_pattern("skip", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr);
39973997
while (idx < curwin->w_s->b_syn_patterns.ga_len
3998-
&& SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_END)
3998+
&& SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_END)
39993999
put_pattern("end", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr);
40004000
--idx;
40014001
msg_putchar(' ');
@@ -4022,21 +4022,21 @@ syn_list_one(
40224022
msg_puts_attr("groupthere", attr);
40234023
msg_putchar(' ');
40244024
if (spp->sp_sync_idx >= 0)
4025-
msg_outtrans(HL_TABLE()[SYN_ITEMS(curwin->w_s)
4026-
[spp->sp_sync_idx].sp_syn.id - 1].sg_name);
4025+
msg_outtrans(highlight_group_name(SYN_ITEMS(curwin->w_s)
4026+
[spp->sp_sync_idx].sp_syn.id - 1));
40274027
else
40284028
msg_puts("NONE");
40294029
msg_putchar(' ');
40304030
}
40314031
}
40324032

40334033
/* list the link, if there is one */
4034-
if (HL_TABLE()[id - 1].sg_link && (did_header || link_only) && !got_int)
4034+
if (highlight_link_id(id - 1) && (did_header || link_only) && !got_int)
40354035
{
40364036
(void)syn_list_header(did_header, 999, id);
40374037
msg_puts_attr("links to", attr);
40384038
msg_putchar(' ');
4039-
msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name);
4039+
msg_outtrans(highlight_group_name(highlight_link_id(id - 1) - 1));
40404040
}
40414041
}
40424042

@@ -4115,7 +4115,7 @@ put_id_list(char_u *name, short *list, int attr)
41154115
msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name);
41164116
}
41174117
else
4118-
msg_outtrans(HL_TABLE()[*p - 1].sg_name);
4118+
msg_outtrans(highlight_group_name(*p - 1));
41194119
if (p[1])
41204120
msg_putchar(',');
41214121
}
@@ -4144,7 +4144,7 @@ put_pattern(
41444144
if (last_matchgroup == 0)
41454145
msg_outtrans((char_u *)"NONE");
41464146
else
4147-
msg_outtrans(HL_TABLE()[last_matchgroup - 1].sg_name);
4147+
msg_outtrans(highlight_group_name(last_matchgroup - 1));
41484148
msg_putchar(' ');
41494149
}
41504150

@@ -5967,9 +5967,9 @@ get_id_list(
59675967

59685968
regmatch.rm_ic = TRUE;
59695969
id = 0;
5970-
for (i = highlight_ga.ga_len; --i >= 0; )
5970+
for (i = highlight_num_groups(); --i >= 0; )
59715971
{
5972-
if (vim_regexec(&regmatch, HL_TABLE()[i].sg_name,
5972+
if (vim_regexec(&regmatch, highlight_group_name(i),
59735973
(colnr_T)0))
59745974
{
59755975
if (round == 2)
@@ -6685,7 +6685,7 @@ syntime_report(void)
66856685
msg_puts(" ");
66866686
# endif
66876687
msg_advance(50);
6688-
msg_outtrans(HL_TABLE()[p->id - 1].sg_name);
6688+
msg_outtrans(highlight_group_name(p->id - 1));
66896689
msg_puts(" ");
66906690

66916691
msg_advance(69);

src/version.c

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

778778
static int included_patches[] =
779779
{ /* Add new patch number below this line */
780+
/**/
781+
1699,
780782
/**/
781783
1698,
782784
/**/

0 commit comments

Comments
 (0)