@@ -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+
3290static void syn_unadd_group (void );
3391static void set_hl_attr (int idx );
3492static 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
45103static 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
293373init_highlight (
294374 int both , // include groups where 'bg' doesn't matter
0 commit comments