To: vim_dev@googlegroups.com Subject: Patch 8.1.1699 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1699 Problem: Highlight_ga can be local instead of global. Solution: Move highlight_ga into highlight.c. (Yegappan Lakshmanan, closes #4675) Files: src/globals.h, src/highlight.c, src/proto/highlight.pro, src/structs.h, src/syntax.c *** ../vim-8.1.1698/src/globals.h 2019-07-14 21:29:04.554965965 +0200 --- src/globals.h 2019-07-15 22:32:26.847700882 +0200 *************** *** 355,363 **** EXTERN int scroll_region INIT(= FALSE); /* term supports scroll region */ EXTERN int t_colors INIT(= 0); /* int value of T_CCO */ - // highlight groups for 'highlight' option - EXTERN garray_T highlight_ga INIT(= {0 COMMA 0 COMMA sizeof(hl_group_T) COMMA 10 COMMA NULL}); - #ifdef FEAT_CMDL_COMPL // Flags to indicate an additional string for highlight name completion. EXTERN int include_none INIT(= 0); // when 1 include "None" --- 355,360 ---- *** ../vim-8.1.1698/src/highlight.c 2019-07-14 21:29:04.558965949 +0200 --- src/highlight.c 2019-07-15 22:35:32.934935884 +0200 *************** *** 29,34 **** --- 29,92 ---- {HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_ITALIC, HL_INVERSE, HL_INVERSE, HL_NOCOMBINE, HL_STRIKETHROUGH, 0}; #define ATTR_COMBINE(attr_a, attr_b) ((((attr_b) & HL_NOCOMBINE) ? attr_b : (attr_a)) | (attr_b)) + /* + * Structure that stores information about a highlight group. + * The ID of a highlight group is also called group ID. It is the index in + * the highlight_ga array PLUS ONE. + */ + typedef struct + { + char_u *sg_name; // highlight group name + char_u *sg_name_u; // uppercase of sg_name + int sg_cleared; // "hi clear" was used + // for normal terminals + int sg_term; // "term=" highlighting attributes + char_u *sg_start; // terminal string for start highl + char_u *sg_stop; // terminal string for stop highl + int sg_term_attr; // Screen attr for term mode + // for color terminals + int sg_cterm; // "cterm=" highlighting attr + int sg_cterm_bold; // bold attr was set for light color + int sg_cterm_fg; // terminal fg color number + 1 + int sg_cterm_bg; // terminal bg color number + 1 + int sg_cterm_attr; // Screen attr for color term mode + // for when using the GUI + #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) + guicolor_T sg_gui_fg; // GUI foreground color handle + guicolor_T sg_gui_bg; // GUI background color handle + #endif + #ifdef FEAT_GUI + guicolor_T sg_gui_sp; // GUI special color handle + GuiFont sg_font; // GUI font handle + #ifdef FEAT_XFONTSET + GuiFontset sg_fontset; // GUI fontset handle + #endif + char_u *sg_font_name; // GUI font or fontset name + int sg_gui_attr; // Screen attr for GUI mode + #endif + #if defined(FEAT_GUI) || defined(FEAT_EVAL) + // Store the sp color name for the GUI or synIDattr() + int sg_gui; // "gui=" highlighting attributes + char_u *sg_gui_fg_name;// GUI foreground color name + char_u *sg_gui_bg_name;// GUI background color name + char_u *sg_gui_sp_name;// GUI special color name + #endif + int sg_link; // link to this highlight group ID + int sg_set; // combination of SG_* flags + #ifdef FEAT_EVAL + sctx_T sg_script_ctx; // script in which the group was last set + #endif + } hl_group_T; + + // highlight groups for 'highlight' option + static garray_T highlight_ga; + #define HL_TABLE() ((hl_group_T *)((highlight_ga.ga_data))) + + /* + * An attribute number is the index in attr_table plus ATTR_OFF. + */ + #define ATTR_OFF (HL_ALL + 1) + static void syn_unadd_group(void); static void set_hl_attr(int idx); static void highlight_list_one(int id); *************** *** 46,56 **** #endif /* - * An attribute number is the index in attr_table plus ATTR_OFF. - */ - #define ATTR_OFF (HL_ALL + 1) - - /* * The default highlight groups. These are compiled-in for fast startup and * they still work when the runtime files can't be found. * When making changes here, also change runtime/colors/default.vim! --- 104,109 ---- *************** *** 289,294 **** --- 342,374 ---- NULL }; + /* + * Returns the number of highlight groups. + */ + int + highlight_num_groups(void) + { + return highlight_ga.ga_len; + } + + /* + * Returns the name of a highlight group. + */ + char_u * + highlight_group_name(int id) + { + return HL_TABLE()[id].sg_name; + } + + /* + * Returns the ID of the link to a highlight group. + */ + int + highlight_link_id(int id) + { + return HL_TABLE()[id].sg_link; + } + void init_highlight( int both, // include groups where 'bg' doesn't matter *** ../vim-8.1.1698/src/proto/highlight.pro 2019-07-14 21:29:04.558965949 +0200 --- src/proto/highlight.pro 2019-07-15 22:35:37.574916664 +0200 *************** *** 1,4 **** --- 1,7 ---- /* highlight.c */ + int highlight_num_groups(void); + char_u *highlight_group_name(int id); + int highlight_link_id(int id); void init_highlight(int both, int reset); int load_colors(char_u *name); int lookup_color(int idx, int foreground, int *boldp); *************** *** 23,29 **** char_u *highlight_has_attr(int id, int flag, int modec); char_u *highlight_color(int id, char_u *what, int modec); long_u highlight_gui_color_rgb(int id, int fg); ! int syn_list_header(int did_header, int outlen, int id); int syn_name2id(char_u *name); int syn_name2attr(char_u *name); int highlight_exists(char_u *name); --- 26,32 ---- char_u *highlight_has_attr(int id, int flag, int modec); char_u *highlight_color(int id, char_u *what, int modec); long_u highlight_gui_color_rgb(int id, int fg); ! int syn_list_header(int did_header, int outlen, int id); int syn_name2id(char_u *name); int syn_name2attr(char_u *name); int highlight_exists(char_u *name); *** ../vim-8.1.1698/src/structs.h 2019-07-14 21:29:04.558965949 +0200 --- src/structs.h 2019-07-15 22:31:39.579893218 +0200 *************** *** 999,1054 **** }; #endif // FEAT_SYN_HL - /* - * Structure that stores information about a highlight group. - * The ID of a highlight group is also called group ID. It is the index in - * the highlight_ga array PLUS ONE. - */ - typedef struct - { - char_u *sg_name; // highlight group name - char_u *sg_name_u; // uppercase of sg_name - int sg_cleared; // "hi clear" was used - // for normal terminals - int sg_term; // "term=" highlighting attributes - char_u *sg_start; // terminal string for start highl - char_u *sg_stop; // terminal string for stop highl - int sg_term_attr; // Screen attr for term mode - // for color terminals - int sg_cterm; // "cterm=" highlighting attr - int sg_cterm_bold; // bold attr was set for light color - int sg_cterm_fg; // terminal fg color number + 1 - int sg_cterm_bg; // terminal bg color number + 1 - int sg_cterm_attr; // Screen attr for color term mode - // for when using the GUI - #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) - guicolor_T sg_gui_fg; // GUI foreground color handle - guicolor_T sg_gui_bg; // GUI background color handle - #endif - #ifdef FEAT_GUI - guicolor_T sg_gui_sp; // GUI special color handle - GuiFont sg_font; // GUI font handle - #ifdef FEAT_XFONTSET - GuiFontset sg_fontset; // GUI fontset handle - #endif - char_u *sg_font_name; // GUI font or fontset name - int sg_gui_attr; // Screen attr for GUI mode - #endif - #if defined(FEAT_GUI) || defined(FEAT_EVAL) - // Store the sp color name for the GUI or synIDattr() - int sg_gui; // "gui=" highlighting attributes - char_u *sg_gui_fg_name;// GUI foreground color name - char_u *sg_gui_bg_name;// GUI background color name - char_u *sg_gui_sp_name;// GUI special color name - #endif - int sg_link; // link to this highlight group ID - int sg_set; // combination of SG_* flags - #ifdef FEAT_EVAL - sctx_T sg_script_ctx; // script in which the group was last set - #endif - } hl_group_T; - - #define HL_TABLE() ((hl_group_T *)((highlight_ga.ga_data))) #define MAX_HL_ID 20000 // maximum value for a highlight ID. /* --- 999,1004 ---- *** ../vim-8.1.1698/src/syntax.c 2019-07-14 21:29:04.558965949 +0200 --- src/syntax.c 2019-07-15 22:35:59.334826498 +0200 *************** *** 3847,3853 **** /* * No argument: List all group IDs and all syntax clusters. */ ! for (id = 1; id <= highlight_ga.ga_len && !got_int; ++id) syn_list_one(id, syncing, FALSE); for (id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id) syn_list_cluster(id); --- 3847,3853 ---- /* * No argument: List all group IDs and all syntax clusters. */ ! for (id = 1; id <= highlight_num_groups() && !got_int; ++id) syn_list_one(id, syncing, FALSE); for (id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id) syn_list_cluster(id); *************** *** 3995,4001 **** if (SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_SKIP) put_pattern("skip", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); while (idx < curwin->w_s->b_syn_patterns.ga_len ! && SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_END) put_pattern("end", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); --idx; msg_putchar(' '); --- 3995,4001 ---- if (SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_SKIP) put_pattern("skip", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); while (idx < curwin->w_s->b_syn_patterns.ga_len ! && SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_END) put_pattern("end", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); --idx; msg_putchar(' '); *************** *** 4022,4029 **** msg_puts_attr("groupthere", attr); msg_putchar(' '); if (spp->sp_sync_idx >= 0) ! msg_outtrans(HL_TABLE()[SYN_ITEMS(curwin->w_s) ! [spp->sp_sync_idx].sp_syn.id - 1].sg_name); else msg_puts("NONE"); msg_putchar(' '); --- 4022,4029 ---- msg_puts_attr("groupthere", attr); msg_putchar(' '); if (spp->sp_sync_idx >= 0) ! msg_outtrans(highlight_group_name(SYN_ITEMS(curwin->w_s) ! [spp->sp_sync_idx].sp_syn.id - 1)); else msg_puts("NONE"); msg_putchar(' '); *************** *** 4031,4042 **** } /* list the link, if there is one */ ! if (HL_TABLE()[id - 1].sg_link && (did_header || link_only) && !got_int) { (void)syn_list_header(did_header, 999, id); msg_puts_attr("links to", attr); msg_putchar(' '); ! msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name); } } --- 4031,4042 ---- } /* list the link, if there is one */ ! if (highlight_link_id(id - 1) && (did_header || link_only) && !got_int) { (void)syn_list_header(did_header, 999, id); msg_puts_attr("links to", attr); msg_putchar(' '); ! msg_outtrans(highlight_group_name(highlight_link_id(id - 1) - 1)); } } *************** *** 4115,4121 **** msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name); } else ! msg_outtrans(HL_TABLE()[*p - 1].sg_name); if (p[1]) msg_putchar(','); } --- 4115,4121 ---- msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name); } else ! msg_outtrans(highlight_group_name(*p - 1)); if (p[1]) msg_putchar(','); } *************** *** 4144,4150 **** if (last_matchgroup == 0) msg_outtrans((char_u *)"NONE"); else ! msg_outtrans(HL_TABLE()[last_matchgroup - 1].sg_name); msg_putchar(' '); } --- 4144,4150 ---- if (last_matchgroup == 0) msg_outtrans((char_u *)"NONE"); else ! msg_outtrans(highlight_group_name(last_matchgroup - 1)); msg_putchar(' '); } *************** *** 5967,5975 **** regmatch.rm_ic = TRUE; id = 0; ! for (i = highlight_ga.ga_len; --i >= 0; ) { ! if (vim_regexec(®match, HL_TABLE()[i].sg_name, (colnr_T)0)) { if (round == 2) --- 5967,5975 ---- regmatch.rm_ic = TRUE; id = 0; ! for (i = highlight_num_groups(); --i >= 0; ) { ! if (vim_regexec(®match, highlight_group_name(i), (colnr_T)0)) { if (round == 2) *************** *** 6685,6691 **** msg_puts(" "); # endif msg_advance(50); ! msg_outtrans(HL_TABLE()[p->id - 1].sg_name); msg_puts(" "); msg_advance(69); --- 6685,6691 ---- msg_puts(" "); # endif msg_advance(50); ! msg_outtrans(highlight_group_name(p->id - 1)); msg_puts(" "); msg_advance(69); *** ../vim-8.1.1698/src/version.c 2019-07-15 22:03:36.274725437 +0200 --- src/version.c 2019-07-15 22:37:15.822508524 +0200 *************** *** 779,780 **** --- 779,782 ---- { /* Add new patch number below this line */ + /**/ + 1699, /**/ -- [Another hideous roar.] BEDEVERE: That's it! ARTHUR: What? BEDEVERE: It's The Legendary Black Beast of Aaaaarrrrrrggghhh! "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///