From 696e24f311acbb0ccfa1818fb016f19f0497d950 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 8 Apr 2018 09:49:20 +0200 Subject: highlight: extract low-level highlight logic from syntax, ui --- src/nvim/api/ui.c | 1 + src/nvim/api/vim.c | 1 + src/nvim/buffer.c | 1 + src/nvim/ex_cmds.c | 1 + src/nvim/ex_getln.c | 1 + src/nvim/highlight.c | 252 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/nvim/highlight.h | 12 +++ src/nvim/main.c | 1 + src/nvim/memory.c | 1 + src/nvim/screen.c | 1 + src/nvim/syntax.c | 185 +------------------------------------ src/nvim/terminal.c | 1 + src/nvim/tui/tui.c | 1 + src/nvim/ui.c | 62 +------------ 14 files changed, 277 insertions(+), 244 deletions(-) create mode 100644 src/nvim/highlight.c create mode 100644 src/nvim/highlight.h (limited to 'src') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index b6e0b9a566..01e6e0ca03 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -16,6 +16,7 @@ #include "nvim/api/private/helpers.h" #include "nvim/popupmnu.h" #include "nvim/cursor_shape.h" +#include "nvim/highlight.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/ui.c.generated.h" diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 03567ddfd8..64d6d68c12 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -21,6 +21,7 @@ #include "nvim/vim.h" #include "nvim/buffer.h" #include "nvim/file_search.h" +#include "nvim/highlight.h" #include "nvim/window.h" #include "nvim/types.h" #include "nvim/ex_docmd.h" diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 81bbc56eb9..4152c16588 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -45,6 +45,7 @@ #include "nvim/fold.h" #include "nvim/getchar.h" #include "nvim/hashtab.h" +#include "nvim/highlight.h" #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/main.h" diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 115df815c6..3c6a8b1074 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -34,6 +34,7 @@ #include "nvim/fileio.h" #include "nvim/fold.h" #include "nvim/getchar.h" +#include "nvim/highlight.h" #include "nvim/indent.h" #include "nvim/buffer_updates.h" #include "nvim/main.h" diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 4b9ef5d819..d6f55ae7f7 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -31,6 +31,7 @@ #include "nvim/fileio.h" #include "nvim/func_attr.h" #include "nvim/getchar.h" +#include "nvim/highlight.h" #include "nvim/if_cscope.h" #include "nvim/indent.h" #include "nvim/main.h" diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c new file mode 100644 index 0000000000..022e086834 --- /dev/null +++ b/src/nvim/highlight.c @@ -0,0 +1,252 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + +// highlight.c: low level code for both UI, syntax and :terminal highlighting + +#include "nvim/vim.h" +#include "nvim/highlight.h" +#include "nvim/highlight_defs.h" +#include "nvim/map.h" +#include "nvim/screen.h" +#include "nvim/syntax.h" +#include "nvim/api/private/defs.h" +#include "nvim/api/private/helpers.h" + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "highlight.c.generated.h" +#endif + +/// An attribute number is the index in attr_entries plus ATTR_OFF. +#define ATTR_OFF 1 + +/// Table with the specifications for an attribute number. +/// Note that this table is used by ALL buffers. This is required because the +/// GUI can redraw at any time for any buffer. +static garray_T attr_table = GA_EMPTY_INIT_VALUE; + +static inline HlAttrs * ATTR_ENTRY(int idx) +{ + return &((HlAttrs *)attr_table.ga_data)[idx]; +} + + +/// Return the attr number for a set of colors and font. +/// Add a new entry to the term_attr_table, attr_table or gui_attr_table +/// if the combination is new. +/// @return 0 for error. +int get_attr_entry(HlAttrs *aep) +{ + garray_T *table = &attr_table; + HlAttrs *taep; + static int recursive = false; + + /* + * Init the table, in case it wasn't done yet. + */ + table->ga_itemsize = sizeof(HlAttrs); + ga_set_growsize(table, 7); + + // Try to find an entry with the same specifications. + for (int i = 0; i < table->ga_len; i++) { + taep = &(((HlAttrs *)table->ga_data)[i]); + if (aep->cterm_ae_attr == taep->cterm_ae_attr + && aep->cterm_fg_color == taep->cterm_fg_color + && aep->cterm_bg_color == taep->cterm_bg_color + && aep->rgb_ae_attr == taep->rgb_ae_attr + && aep->rgb_fg_color == taep->rgb_fg_color + && aep->rgb_bg_color == taep->rgb_bg_color + && aep->rgb_sp_color == taep->rgb_sp_color) { + return i + ATTR_OFF; + } + } + + if (table->ga_len + ATTR_OFF > MAX_TYPENR) { + /* + * Running out of attribute entries! remove all attributes, and + * compute new ones for all groups. + * When called recursively, we are really out of numbers. + */ + if (recursive) { + EMSG(_("E424: Too many different highlighting attributes in use")); + return 0; + } + recursive = TRUE; + + clear_hl_tables(); + + must_redraw = CLEAR; + + highlight_attr_set_all(); + + recursive = FALSE; + } + + // This is a new combination of colors and font, add an entry. + taep = GA_APPEND_VIA_PTR(HlAttrs, table); + memset(taep, 0, sizeof(*taep)); + taep->cterm_ae_attr = aep->cterm_ae_attr; + taep->cterm_fg_color = aep->cterm_fg_color; + taep->cterm_bg_color = aep->cterm_bg_color; + taep->rgb_ae_attr = aep->rgb_ae_attr; + taep->rgb_fg_color = aep->rgb_fg_color; + taep->rgb_bg_color = aep->rgb_bg_color; + taep->rgb_sp_color = aep->rgb_sp_color; + + return table->ga_len - 1 + ATTR_OFF; +} + +// Clear all highlight tables. +void clear_hl_tables(void) +{ + ga_clear(&attr_table); +} + +// Combine special attributes (e.g., for spelling) with other attributes +// (e.g., for syntax highlighting). +// "prim_attr" overrules "char_attr". +// This creates a new group when required. +// Since we expect there to be few spelling mistakes we don't cache the +// result. +// Return the resulting attributes. +int hl_combine_attr(int char_attr, int prim_attr) +{ + HlAttrs *char_aep = NULL; + HlAttrs *spell_aep; + HlAttrs new_en = HLATTRS_INIT; + + if (char_attr == 0) { + return prim_attr; + } + + if (prim_attr == 0) { + return char_attr; + } + + // Find the entry for char_attr + char_aep = syn_cterm_attr2entry(char_attr); + + if (char_aep != NULL) { + // Copy all attributes from char_aep to the new entry + new_en = *char_aep; + } + + spell_aep = syn_cterm_attr2entry(prim_attr); + if (spell_aep != NULL) { + new_en.cterm_ae_attr |= spell_aep->cterm_ae_attr; + new_en.rgb_ae_attr |= spell_aep->rgb_ae_attr; + + if (spell_aep->cterm_fg_color > 0) { + new_en.cterm_fg_color = spell_aep->cterm_fg_color; + } + + if (spell_aep->cterm_bg_color > 0) { + new_en.cterm_bg_color = spell_aep->cterm_bg_color; + } + + if (spell_aep->rgb_fg_color >= 0) { + new_en.rgb_fg_color = spell_aep->rgb_fg_color; + } + + if (spell_aep->rgb_bg_color >= 0) { + new_en.rgb_bg_color = spell_aep->rgb_bg_color; + } + + if (spell_aep->rgb_sp_color >= 0) { + new_en.rgb_sp_color = spell_aep->rgb_sp_color; + } + } + return get_attr_entry(&new_en); +} + +/// \note this function does not apply exclusively to cterm attr contrary +/// to what its name implies +/// \warn don't call it with attr 0 (i.e., the null attribute) +HlAttrs *syn_cterm_attr2entry(int attr) +{ + attr -= ATTR_OFF; + if (attr >= attr_table.ga_len) { + // did ":syntax clear" + return NULL; + } + return ATTR_ENTRY(attr); +} + +/// Gets highlight description for id `attr_id` as a map. +Dictionary hl_get_attr_by_id(Integer attr_id, Boolean rgb, Error *err) +{ + HlAttrs *aep = NULL; + Dictionary dic = ARRAY_DICT_INIT; + + if (attr_id == 0) { + return dic; + } + + aep = syn_cterm_attr2entry((int)attr_id); + if (!aep) { + api_set_error(err, kErrorTypeException, + "Invalid attribute id: %" PRId64, attr_id); + return dic; + } + + return hlattrs2dict(aep, rgb); +} + +/// Converts an HlAttrs into Dictionary +/// +/// @param[in] aep data to convert +/// @param use_rgb use 'gui*' settings if true, else resorts to 'cterm*' +Dictionary hlattrs2dict(const HlAttrs *aep, bool use_rgb) +{ + assert(aep); + Dictionary hl = ARRAY_DICT_INIT; + int mask = use_rgb ? aep->rgb_ae_attr : aep->cterm_ae_attr; + + if (mask & HL_BOLD) { + PUT(hl, "bold", BOOLEAN_OBJ(true)); + } + + if (mask & HL_STANDOUT) { + PUT(hl, "standout", BOOLEAN_OBJ(true)); + } + + if (mask & HL_UNDERLINE) { + PUT(hl, "underline", BOOLEAN_OBJ(true)); + } + + if (mask & HL_UNDERCURL) { + PUT(hl, "undercurl", BOOLEAN_OBJ(true)); + } + + if (mask & HL_ITALIC) { + PUT(hl, "italic", BOOLEAN_OBJ(true)); + } + + if (mask & HL_INVERSE) { + PUT(hl, "reverse", BOOLEAN_OBJ(true)); + } + + if (use_rgb) { + if (aep->rgb_fg_color != -1) { + PUT(hl, "foreground", INTEGER_OBJ(aep->rgb_fg_color)); + } + + if (aep->rgb_bg_color != -1) { + PUT(hl, "background", INTEGER_OBJ(aep->rgb_bg_color)); + } + + if (aep->rgb_sp_color != -1) { + PUT(hl, "special", INTEGER_OBJ(aep->rgb_sp_color)); + } + } else { + if (cterm_normal_fg_color != aep->cterm_fg_color) { + PUT(hl, "foreground", INTEGER_OBJ(aep->cterm_fg_color - 1)); + } + + if (cterm_normal_bg_color != aep->cterm_bg_color) { + PUT(hl, "background", INTEGER_OBJ(aep->cterm_bg_color - 1)); + } + } + + return hl; +} + diff --git a/src/nvim/highlight.h b/src/nvim/highlight.h new file mode 100644 index 0000000000..3bb5600b4f --- /dev/null +++ b/src/nvim/highlight.h @@ -0,0 +1,12 @@ +#ifndef NVIM_HIGHLIGHT_H +#define NVIM_HIGHLIGHT_H + +#include +#include "nvim/highlight_defs.h" +#include "nvim/api/private/defs.h" + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "highlight.h.generated.h" +#endif + +#endif // NVIM_HIGHLIGHT_H diff --git a/src/nvim/main.c b/src/nvim/main.c index 6b382ae320..460711cd36 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -23,6 +23,7 @@ #include "nvim/fold.h" #include "nvim/getchar.h" #include "nvim/hashtab.h" +#include "nvim/highlight.h" #include "nvim/iconv.h" #include "nvim/if_cscope.h" #ifdef HAVE_LOCALE_H diff --git a/src/nvim/memory.c b/src/nvim/memory.c index b2aef13946..82367fbff8 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -10,6 +10,7 @@ #include "nvim/vim.h" #include "nvim/eval.h" +#include "nvim/highlight.h" #include "nvim/memfile.h" #include "nvim/memory.h" #include "nvim/message.h" diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 49aeaff3a6..bc7cd5f541 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -85,6 +85,7 @@ #include "nvim/fold.h" #include "nvim/indent.h" #include "nvim/getchar.h" +#include "nvim/highlight.h" #include "nvim/main.h" #include "nvim/mark.h" #include "nvim/mbyte.h" diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 87b2fe24a4..44cd3cdeac 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -22,6 +22,7 @@ #include "nvim/fileio.h" #include "nvim/fold.h" #include "nvim/hashtab.h" +#include "nvim/highlight.h" #include "nvim/indent_c.h" #include "nvim/mbyte.h" #include "nvim/memline.h" @@ -42,7 +43,6 @@ #include "nvim/ui.h" #include "nvim/os/os.h" #include "nvim/os/time.h" -#include "nvim/api/private/helpers.h" #include "nvim/buffer.h" static bool did_syntax_onoff = false; @@ -216,12 +216,6 @@ struct name_list { # include "syntax.c.generated.h" #endif -/* - * An attribute number is the index in attr_table plus ATTR_OFF. - */ -#define ATTR_OFF 1 - - static char *(spo_name_tab[SPO_COUNT]) = {"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="}; @@ -7001,161 +6995,6 @@ static void highlight_clear(int idx) } -/// Table with the specifications for an attribute number. -/// Note that this table is used by ALL buffers. This is required because the -/// GUI can redraw at any time for any buffer. -static garray_T attr_table = GA_EMPTY_INIT_VALUE; - -static inline HlAttrs * ATTR_ENTRY(int idx) -{ - return &((HlAttrs *)attr_table.ga_data)[idx]; -} - - -/// Return the attr number for a set of colors and font. -/// Add a new entry to the term_attr_table, attr_table or gui_attr_table -/// if the combination is new. -/// @return 0 for error. -int get_attr_entry(HlAttrs *aep) -{ - garray_T *table = &attr_table; - HlAttrs *taep; - static int recursive = false; - - /* - * Init the table, in case it wasn't done yet. - */ - table->ga_itemsize = sizeof(HlAttrs); - ga_set_growsize(table, 7); - - // Try to find an entry with the same specifications. - for (int i = 0; i < table->ga_len; i++) { - taep = &(((HlAttrs *)table->ga_data)[i]); - if (aep->cterm_ae_attr == taep->cterm_ae_attr - && aep->cterm_fg_color == taep->cterm_fg_color - && aep->cterm_bg_color == taep->cterm_bg_color - && aep->rgb_ae_attr == taep->rgb_ae_attr - && aep->rgb_fg_color == taep->rgb_fg_color - && aep->rgb_bg_color == taep->rgb_bg_color - && aep->rgb_sp_color == taep->rgb_sp_color) { - return i + ATTR_OFF; - } - } - - if (table->ga_len + ATTR_OFF > MAX_TYPENR) { - /* - * Running out of attribute entries! remove all attributes, and - * compute new ones for all groups. - * When called recursively, we are really out of numbers. - */ - if (recursive) { - EMSG(_("E424: Too many different highlighting attributes in use")); - return 0; - } - recursive = TRUE; - - clear_hl_tables(); - - must_redraw = CLEAR; - - for (int i = 0; i < highlight_ga.ga_len; ++i) { - set_hl_attr(i); - } - - recursive = FALSE; - } - - - // This is a new combination of colors and font, add an entry. - taep = GA_APPEND_VIA_PTR(HlAttrs, table); - memset(taep, 0, sizeof(*taep)); - taep->cterm_ae_attr = aep->cterm_ae_attr; - taep->cterm_fg_color = aep->cterm_fg_color; - taep->cterm_bg_color = aep->cterm_bg_color; - taep->rgb_ae_attr = aep->rgb_ae_attr; - taep->rgb_fg_color = aep->rgb_fg_color; - taep->rgb_bg_color = aep->rgb_bg_color; - taep->rgb_sp_color = aep->rgb_sp_color; - - return table->ga_len - 1 + ATTR_OFF; -} - -// Clear all highlight tables. -void clear_hl_tables(void) -{ - ga_clear(&attr_table); -} - -// Combine special attributes (e.g., for spelling) with other attributes -// (e.g., for syntax highlighting). -// "prim_attr" overrules "char_attr". -// This creates a new group when required. -// Since we expect there to be few spelling mistakes we don't cache the -// result. -// Return the resulting attributes. -int hl_combine_attr(int char_attr, int prim_attr) -{ - HlAttrs *char_aep = NULL; - HlAttrs *spell_aep; - HlAttrs new_en = HLATTRS_INIT; - - if (char_attr == 0) { - return prim_attr; - } - - if (prim_attr == 0) { - return char_attr; - } - - // Find the entry for char_attr - char_aep = syn_cterm_attr2entry(char_attr); - - if (char_aep != NULL) { - // Copy all attributes from char_aep to the new entry - new_en = *char_aep; - } - - spell_aep = syn_cterm_attr2entry(prim_attr); - if (spell_aep != NULL) { - new_en.cterm_ae_attr |= spell_aep->cterm_ae_attr; - new_en.rgb_ae_attr |= spell_aep->rgb_ae_attr; - - if (spell_aep->cterm_fg_color > 0) { - new_en.cterm_fg_color = spell_aep->cterm_fg_color; - } - - if (spell_aep->cterm_bg_color > 0) { - new_en.cterm_bg_color = spell_aep->cterm_bg_color; - } - - if (spell_aep->rgb_fg_color >= 0) { - new_en.rgb_fg_color = spell_aep->rgb_fg_color; - } - - if (spell_aep->rgb_bg_color >= 0) { - new_en.rgb_bg_color = spell_aep->rgb_bg_color; - } - - if (spell_aep->rgb_sp_color >= 0) { - new_en.rgb_sp_color = spell_aep->rgb_sp_color; - } - } - return get_attr_entry(&new_en); -} - -/// \note this function does not apply exclusively to cterm attr contrary -/// to what its name implies -/// \warn don't call it with attr 0 (i.e., the null attribute) -HlAttrs *syn_cterm_attr2entry(int attr) -{ - attr -= ATTR_OFF; - if (attr >= attr_table.ga_len) { - // did ":syntax clear" - return NULL; - } - return ATTR_ENTRY(attr); -} - /// \addtogroup LIST_XXX /// @{ #define LIST_ATTR 1 @@ -7590,7 +7429,7 @@ int syn_get_final_id(int hl_id) } /// Refresh the color attributes of all highlight groups. -static void highlight_attr_set_all(void) +void highlight_attr_set_all(void) { for (int idx = 0; idx < highlight_ga.ga_len; idx++) { struct hl_group *sgp = &HL_TABLE()[idx]; @@ -8522,26 +8361,6 @@ RgbValue name_to_color(const char_u *name) return -1; } -/// Gets highlight description for id `attr_id` as a map. -Dictionary hl_get_attr_by_id(Integer attr_id, Boolean rgb, Error *err) -{ - HlAttrs *aep = NULL; - Dictionary dic = ARRAY_DICT_INIT; - - if (attr_id == 0) { - return dic; - } - - aep = syn_cterm_attr2entry((int)attr_id); - if (!aep) { - api_set_error(err, kErrorTypeException, - "Invalid attribute id: %" PRId64, attr_id); - return dic; - } - - return hlattrs2dict(aep, rgb); -} - /************************************** * End of Highlighting stuff * diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 6907529726..7c90d77c1c 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -49,6 +49,7 @@ #include "nvim/message.h" #include "nvim/memory.h" #include "nvim/option.h" +#include "nvim/highlight.h" #include "nvim/macros.h" #include "nvim/mbyte.h" #include "nvim/buffer.h" diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index f41c715696..4849a47144 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -20,6 +20,7 @@ #include "nvim/vim.h" #include "nvim/log.h" #include "nvim/ui.h" +#include "nvim/highlight.h" #include "nvim/map.h" #include "nvim/main.h" #include "nvim/memory.h" diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 3b632ace41..377e011d49 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -32,7 +32,7 @@ #include "nvim/os/signal.h" #include "nvim/popupmnu.h" #include "nvim/screen.h" -#include "nvim/syntax.h" +#include "nvim/highlight.h" #include "nvim/window.h" #include "nvim/cursor_shape.h" #ifdef FEAT_TUI @@ -172,66 +172,6 @@ void ui_event(char *name, Array args) } -/// Converts an HlAttrs into Dictionary -/// -/// @param[in] aep data to convert -/// @param use_rgb use 'gui*' settings if true, else resorts to 'cterm*' -Dictionary hlattrs2dict(const HlAttrs *aep, bool use_rgb) -{ - assert(aep); - Dictionary hl = ARRAY_DICT_INIT; - int mask = use_rgb ? aep->rgb_ae_attr : aep->cterm_ae_attr; - - if (mask & HL_BOLD) { - PUT(hl, "bold", BOOLEAN_OBJ(true)); - } - - if (mask & HL_STANDOUT) { - PUT(hl, "standout", BOOLEAN_OBJ(true)); - } - - if (mask & HL_UNDERLINE) { - PUT(hl, "underline", BOOLEAN_OBJ(true)); - } - - if (mask & HL_UNDERCURL) { - PUT(hl, "undercurl", BOOLEAN_OBJ(true)); - } - - if (mask & HL_ITALIC) { - PUT(hl, "italic", BOOLEAN_OBJ(true)); - } - - if (mask & HL_INVERSE) { - PUT(hl, "reverse", BOOLEAN_OBJ(true)); - } - - - if (use_rgb) { - if (aep->rgb_fg_color != -1) { - PUT(hl, "foreground", INTEGER_OBJ(aep->rgb_fg_color)); - } - - if (aep->rgb_bg_color != -1) { - PUT(hl, "background", INTEGER_OBJ(aep->rgb_bg_color)); - } - - if (aep->rgb_sp_color != -1) { - PUT(hl, "special", INTEGER_OBJ(aep->rgb_sp_color)); - } - } else { - if (cterm_normal_fg_color != aep->cterm_fg_color) { - PUT(hl, "foreground", INTEGER_OBJ(aep->cterm_fg_color - 1)); - } - - if (cterm_normal_bg_color != aep->cterm_bg_color) { - PUT(hl, "background", INTEGER_OBJ(aep->cterm_bg_color - 1)); - } - } - - return hl; -} - void ui_refresh(void) { if (!ui_active()) { -- cgit From 989b585e105b4f343f639abf5daf820de19d4a26 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 8 Apr 2018 09:51:22 +0200 Subject: highlight: refactor to use stateful representation This allows us to keep track of the source higlight groups, and not only the final combined highlights. --- src/nvim/api/vim.c | 19 +++ src/nvim/ex_getln.c | 2 +- src/nvim/highlight.c | 305 ++++++++++++++++++++++++++++++++++------------ src/nvim/highlight.h | 1 + src/nvim/highlight_defs.h | 15 +++ src/nvim/main.c | 1 + src/nvim/map.c | 17 +++ src/nvim/map.h | 2 + src/nvim/memory.c | 2 +- src/nvim/screen.c | 50 ++------ src/nvim/syntax.c | 23 ++-- src/nvim/terminal.c | 2 +- src/nvim/tui/tui.c | 4 +- src/nvim/ui.c | 2 +- src/nvim/ui.h | 1 - 15 files changed, 304 insertions(+), 142 deletions(-) (limited to 'src') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 64d6d68c12..1ffae8ef43 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1851,3 +1851,22 @@ Object nvim_get_proc(Integer pid, Error *err) #endif return rvobj; } + +/// NB: if your UI doesn't use hlstate, this will not return hlstate first time +Array nvim__inspect_cell(Integer row, Integer col, Error *err) +{ + Array ret = ARRAY_DICT_INIT; + if (row < 0 || row >= screen_Rows + || col < 0 || col >= screen_Columns) { + return ret; + } + size_t off = LineOffset[(size_t)row] + (size_t)col; + ADD(ret, STRING_OBJ(cstr_to_string((char *)ScreenLines[off]))); + int attr = ScreenAttrs[off]; + ADD(ret, DICTIONARY_OBJ(hl_get_attr_by_id(attr, true, err))); + // will not work first time + if (!highlight_use_hlstate()) { + ADD(ret, ARRAY_OBJ(hl_inspect(attr))); + } + return ret; +} diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index d6f55ae7f7..6b52ce7c80 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2953,7 +2953,7 @@ static void ui_ext_cmdline_show(CmdlineInfo *line) Array item = ARRAY_DICT_INIT; if (chunk.attr) { - HlAttrs *aep = syn_cterm_attr2entry(chunk.attr); + HlAttrs *aep = syn_attr2entry(chunk.attr); // TODO(bfredl): this desicion could be delayed by making attr_code a // recognized type Dictionary rgb_attrs = hlattrs2dict(aep, true); diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index 022e086834..5efbafa128 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -1,7 +1,7 @@ // This is an open source non-commercial project. Dear PVS-Studio, please check // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com -// highlight.c: low level code for both UI, syntax and :terminal highlighting +// highlight.c: low level code for UI and syntax highlighting #include "nvim/vim.h" #include "nvim/highlight.h" @@ -9,6 +9,7 @@ #include "nvim/map.h" #include "nvim/screen.h" #include "nvim/syntax.h" +#include "nvim/ui.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" @@ -16,89 +17,180 @@ # include "highlight.c.generated.h" #endif -/// An attribute number is the index in attr_entries plus ATTR_OFF. -#define ATTR_OFF 1 +static bool hlstate_active = false; -/// Table with the specifications for an attribute number. -/// Note that this table is used by ALL buffers. This is required because the -/// GUI can redraw at any time for any buffer. -static garray_T attr_table = GA_EMPTY_INIT_VALUE; +static kvec_t(HlEntry) attr_entries = KV_INITIAL_VALUE; -static inline HlAttrs * ATTR_ENTRY(int idx) +static Map(HlEntry, int) *attr_entry_ids; +static Map(int, int) *combine_attr_entries; + +void highlight_init(void) { - return &((HlAttrs *)attr_table.ga_data)[idx]; + attr_entry_ids = map_new(HlEntry, int)(); + combine_attr_entries = map_new(int, int)(); + + // index 0 is no attribute, add dummy entry: + kv_push(attr_entries, ((HlEntry){ .attr = HLATTRS_INIT, .kind = kHlUnknown, + .id1 = 0, .id2 = 0 })); } +/// @return TRUE if hl table was reset +bool highlight_use_hlstate(void) +{ + if (hlstate_active) { + return false; + } + hlstate_active = true; + // hl tables must now be rebuilt. + clear_hl_tables(true); + return true; +} -/// Return the attr number for a set of colors and font. -/// Add a new entry to the term_attr_table, attr_table or gui_attr_table -/// if the combination is new. +/// Return the attr number for a set of colors and font, and optionally +/// a semantic description (see ext_hlstate documentation). +/// Add a new entry to the attr_entries array if the combination is new. /// @return 0 for error. -int get_attr_entry(HlAttrs *aep) +static int get_attr_entry(HlEntry entry) { - garray_T *table = &attr_table; - HlAttrs *taep; - static int recursive = false; - - /* - * Init the table, in case it wasn't done yet. - */ - table->ga_itemsize = sizeof(HlAttrs); - ga_set_growsize(table, 7); - - // Try to find an entry with the same specifications. - for (int i = 0; i < table->ga_len; i++) { - taep = &(((HlAttrs *)table->ga_data)[i]); - if (aep->cterm_ae_attr == taep->cterm_ae_attr - && aep->cterm_fg_color == taep->cterm_fg_color - && aep->cterm_bg_color == taep->cterm_bg_color - && aep->rgb_ae_attr == taep->rgb_ae_attr - && aep->rgb_fg_color == taep->rgb_fg_color - && aep->rgb_bg_color == taep->rgb_bg_color - && aep->rgb_sp_color == taep->rgb_sp_color) { - return i + ATTR_OFF; - } + if (!hlstate_active) { + // This information will not be used, erase it and reduce the table size. + entry.kind = kHlUnknown; + entry.id1 = 0; + entry.id2 = 0; + } + + int id = map_get(HlEntry, int)(attr_entry_ids, entry); + if (id > 0) { + return id; } - if (table->ga_len + ATTR_OFF > MAX_TYPENR) { - /* - * Running out of attribute entries! remove all attributes, and - * compute new ones for all groups. - * When called recursively, we are really out of numbers. - */ + static bool recursive = false; + if (kv_size(attr_entries) > MAX_TYPENR) { + // Running out of attribute entries! remove all attributes, and + // compute new ones for all groups. + // When called recursively, we are really out of numbers. if (recursive) { EMSG(_("E424: Too many different highlighting attributes in use")); return 0; } - recursive = TRUE; + recursive = true; - clear_hl_tables(); + clear_hl_tables(true); - must_redraw = CLEAR; + recursive = false; + if (entry.kind == kHlCombine) { + // This entry is now invalid, don't put it + return 0; + } + } - highlight_attr_set_all(); + id = (int)kv_size(attr_entries); + kv_push(attr_entries, entry); + + map_put(HlEntry, int)(attr_entry_ids, entry, id); + + return id; +} - recursive = FALSE; +/// Get attribute code for a syntax group. +int hl_get_syn_attr(int idx, HlAttrs at_en) +{ + // TODO(bfredl): should we do this unconditionally + if (at_en.cterm_fg_color != 0 || at_en.cterm_bg_color != 0 + || at_en.rgb_fg_color != -1 || at_en.rgb_bg_color != -1 + || at_en.rgb_sp_color != -1 || at_en.cterm_ae_attr != 0 + || at_en.rgb_ae_attr != 0) { + return get_attr_entry((HlEntry){ .attr = at_en, .kind = kHlSyntax, + .id1 = idx, .id2 = 0 }); + } else { + // If all the fields are cleared, clear the attr field back to default value + return 0; + } +} + +/// Get attribute code for a builtin highlight group. +/// +/// The final syntax group could be modified by hi-link or 'winhighlight'. +int hl_get_ui_attr(int idx, int final_id, bool optional) +{ + HlAttrs attrs = HLATTRS_INIT; + bool available = false; + + int syn_attr = syn_id2attr(final_id); + if (syn_attr != 0) { + HlAttrs *aep = syn_attr2entry(syn_attr); + if (aep) { + attrs = *aep; + available = true; + } + } + if (optional && !available) { + return 0; + } + return get_attr_entry((HlEntry){ .attr = attrs, .kind = kHlUI, + .id1 = idx, .id2 = final_id }); +} + +void update_window_hl(win_T *wp, bool invalid) +{ + if (!wp->w_hl_needs_update && !invalid) { + return; + } + wp->w_hl_needs_update = false; + + // determine window specific background set in 'winhighlight' + if (wp != curwin && wp->w_hl_ids[HLF_INACTIVE] > 0) { + wp->w_hl_attr_normal = hl_get_ui_attr(HLF_INACTIVE, + wp->w_hl_ids[HLF_INACTIVE], true); + } else if (wp->w_hl_id_normal > 0) { + wp->w_hl_attr_normal = hl_get_ui_attr(-1, wp->w_hl_id_normal, true); + } else { + wp->w_hl_attr_normal = 0; + } + if (wp != curwin) { + wp->w_hl_attr_normal = hl_combine_attr(HL_ATTR(HLF_INACTIVE), + wp->w_hl_attr_normal); } - // This is a new combination of colors and font, add an entry. - taep = GA_APPEND_VIA_PTR(HlAttrs, table); - memset(taep, 0, sizeof(*taep)); - taep->cterm_ae_attr = aep->cterm_ae_attr; - taep->cterm_fg_color = aep->cterm_fg_color; - taep->cterm_bg_color = aep->cterm_bg_color; - taep->rgb_ae_attr = aep->rgb_ae_attr; - taep->rgb_fg_color = aep->rgb_fg_color; - taep->rgb_bg_color = aep->rgb_bg_color; - taep->rgb_sp_color = aep->rgb_sp_color; + for (int hlf = 0; hlf < (int)HLF_COUNT; hlf++) { + int attr; + if (wp->w_hl_ids[hlf] > 0) { + attr = hl_get_ui_attr(hlf, wp->w_hl_ids[hlf], false); + } else { + attr = HL_ATTR(hlf); + } + wp->w_hl_attrs[hlf] = attr; + } +} - return table->ga_len - 1 + ATTR_OFF; +/// Get attribute code for forwarded :terminal highlights. +int get_term_attr_entry(HlAttrs *aep) +{ + return get_attr_entry((HlEntry){ .attr= *aep, .kind = kHlTerminal, + .id1 = 0, .id2 = 0 }); } -// Clear all highlight tables. -void clear_hl_tables(void) +/// Clear all highlight tables. +void clear_hl_tables(bool reinit) { - ga_clear(&attr_table); + if (reinit) { + kv_size(attr_entries) = 1; + map_clear(HlEntry, int)(attr_entry_ids); + map_clear(int, int)(combine_attr_entries); + highlight_attr_set_all(); + highlight_changed(); + redraw_all_later(NOT_VALID); + if (ScreenAttrs) { + // the meaning of 0 doesn't change anyway + // but the rest must be retransmitted + memset(ScreenAttrs, 0, + sizeof(*ScreenAttrs) * (size_t)(screen_Rows * screen_Columns)); + } + } else { + kv_destroy(attr_entries); + map_free(HlEntry, int)(attr_entry_ids); + map_free(int, int)(combine_attr_entries); + } } // Combine special attributes (e.g., for spelling) with other attributes @@ -110,27 +202,32 @@ void clear_hl_tables(void) // Return the resulting attributes. int hl_combine_attr(int char_attr, int prim_attr) { - HlAttrs *char_aep = NULL; - HlAttrs *spell_aep; - HlAttrs new_en = HLATTRS_INIT; - if (char_attr == 0) { return prim_attr; + } else if (prim_attr == 0) { + return char_attr; } - if (prim_attr == 0) { - return char_attr; + // TODO(bfredl): could use a struct for clearer intent. + int combine_tag = (char_attr << 16) + prim_attr; + int id = map_get(int, int)(combine_attr_entries, combine_tag); + if (id > 0) { + return id; } + HlAttrs *char_aep, *spell_aep; + HlAttrs new_en = HLATTRS_INIT; + + // Find the entry for char_attr - char_aep = syn_cterm_attr2entry(char_attr); + char_aep = syn_attr2entry(char_attr); if (char_aep != NULL) { // Copy all attributes from char_aep to the new entry new_en = *char_aep; } - spell_aep = syn_cterm_attr2entry(prim_attr); + spell_aep = syn_attr2entry(prim_attr); if (spell_aep != NULL) { new_en.cterm_ae_attr |= spell_aep->cterm_ae_attr; new_en.rgb_ae_attr |= spell_aep->rgb_ae_attr; @@ -155,20 +252,24 @@ int hl_combine_attr(int char_attr, int prim_attr) new_en.rgb_sp_color = spell_aep->rgb_sp_color; } } - return get_attr_entry(&new_en); + + id = get_attr_entry((HlEntry){ .attr = new_en, .kind = kHlCombine, + .id1 = char_attr, .id2 = prim_attr }); + if (id > 0) { + map_put(int, int)(combine_attr_entries, combine_tag, id); + } + + return id; } -/// \note this function does not apply exclusively to cterm attr contrary -/// to what its name implies -/// \warn don't call it with attr 0 (i.e., the null attribute) -HlAttrs *syn_cterm_attr2entry(int attr) +/// Get highlight attributes for a attribute code +HlAttrs *syn_attr2entry(int attr) { - attr -= ATTR_OFF; - if (attr >= attr_table.ga_len) { - // did ":syntax clear" + if (attr <= 0 || attr >= (int)kv_size(attr_entries)) { + // invalid attribute code, or the tables were cleared return NULL; } - return ATTR_ENTRY(attr); + return &(kv_A(attr_entries, attr).attr); } /// Gets highlight description for id `attr_id` as a map. @@ -181,7 +282,7 @@ Dictionary hl_get_attr_by_id(Integer attr_id, Boolean rgb, Error *err) return dic; } - aep = syn_cterm_attr2entry((int)attr_id); + aep = syn_attr2entry((int)attr_id); if (!aep) { api_set_error(err, kErrorTypeException, "Invalid attribute id: %" PRId64, attr_id); @@ -250,3 +351,51 @@ Dictionary hlattrs2dict(const HlAttrs *aep, bool use_rgb) return hl; } +Array hl_inspect(int attr) +{ + Array ret = ARRAY_DICT_INIT; + if (hlstate_active) { + hl_inspect_impl(&ret, attr); + } + return ret; +} + +static void hl_inspect_impl(Array *arr, int attr) +{ + Dictionary item = ARRAY_DICT_INIT; + if (attr <= 0 || attr >= (int)kv_size(attr_entries)) { + return; + } + + HlEntry e = kv_A(attr_entries, attr); + switch (e.kind) { + case kHlSyntax: + PUT(item, "kind", STRING_OBJ(cstr_to_string("syntax"))); + PUT(item, "hi_name", + STRING_OBJ(cstr_to_string((char *)syn_id2name(e.id1)))); + break; + + case kHlUI: + PUT(item, "kind", STRING_OBJ(cstr_to_string("ui"))); + const char *ui_name = (e.id1 == -1) ? "Normal" : hlf_names[e.id1]; + PUT(item, "ui_name", STRING_OBJ(cstr_to_string(ui_name))); + PUT(item, "hi_name", + STRING_OBJ(cstr_to_string((char *)syn_id2name(e.id2)))); + break; + + case kHlTerminal: + PUT(item, "kind", STRING_OBJ(cstr_to_string("term"))); + break; + + case kHlCombine: + // attribute combination is associative, so flatten to an array + hl_inspect_impl(arr, e.id1); + hl_inspect_impl(arr, e.id2); + return; + + case kHlUnknown: + return; + } + PUT(item, "id", INTEGER_OBJ(attr)); + ADD(*arr, DICTIONARY_OBJ(item)); +} diff --git a/src/nvim/highlight.h b/src/nvim/highlight.h index 3bb5600b4f..6be0d6200b 100644 --- a/src/nvim/highlight.h +++ b/src/nvim/highlight.h @@ -4,6 +4,7 @@ #include #include "nvim/highlight_defs.h" #include "nvim/api/private/defs.h" +#include "nvim/ui.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "highlight.h.generated.h" diff --git a/src/nvim/highlight_defs.h b/src/nvim/highlight_defs.h index 3518c8bdcc..5f637228ba 100644 --- a/src/nvim/highlight_defs.h +++ b/src/nvim/highlight_defs.h @@ -152,4 +152,19 @@ EXTERN RgbValue normal_fg INIT(= -1); EXTERN RgbValue normal_bg INIT(= -1); EXTERN RgbValue normal_sp INIT(= -1); +typedef enum { + kHlUnknown, + kHlUI, + kHlSyntax, + kHlTerminal, + kHlCombine, +} HlKind; + +typedef struct { + HlAttrs attr; + HlKind kind; + int id1; + int id2; +} HlEntry; + #endif // NVIM_HIGHLIGHT_DEFS_H diff --git a/src/nvim/main.c b/src/nvim/main.c index 460711cd36..528fd921bc 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -183,6 +183,7 @@ void early_init(void) eval_init(); // init global variables init_path(argv0 ? argv0 : "nvim"); init_normal_cmds(); // Init the table of Normal mode commands. + highlight_init(); #if defined(HAVE_LOCALE_H) // Setup to use the current locale (for ctype() and many other things). diff --git a/src/nvim/map.c b/src/nvim/map.c index 537b6751e2..cc264f3729 100644 --- a/src/nvim/map.c +++ b/src/nvim/map.c @@ -140,6 +140,22 @@ static inline bool String_eq(String a, String b) return memcmp(a.data, b.data, a.size) == 0; } +static inline khint_t HlEntry_hash(HlEntry ae) +{ + const uint8_t *data = (const uint8_t *)&ae; + khint_t h = 0; + for (size_t i = 0; i < sizeof(ae); i++) { + h = (h << 5) - h + data[i]; + } + return h; +} + +static inline bool HlEntry_eq(HlEntry ae1, HlEntry ae2) +{ + return memcmp(&ae1, &ae2, sizeof(ae1)) == 0; +} + + MAP_IMPL(int, int, DEFAULT_INITIALIZER) MAP_IMPL(cstr_t, ptr_t, DEFAULT_INITIALIZER) @@ -149,3 +165,4 @@ MAP_IMPL(handle_T, ptr_t, DEFAULT_INITIALIZER) #define MSGPACK_HANDLER_INITIALIZER { .fn = NULL, .async = false } MAP_IMPL(String, MsgpackRpcRequestHandler, MSGPACK_HANDLER_INITIALIZER) #define KVEC_INITIALIZER { .size = 0, .capacity = 0, .items = NULL } +MAP_IMPL(HlEntry, int, DEFAULT_INITIALIZER) diff --git a/src/nvim/map.h b/src/nvim/map.h index ac1239a548..65204a798b 100644 --- a/src/nvim/map.h +++ b/src/nvim/map.h @@ -7,6 +7,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/dispatch.h" #include "nvim/bufhl_defs.h" +#include "nvim/highlight_defs.h" #if defined(__NetBSD__) # undef uint64_t @@ -35,6 +36,7 @@ MAP_DECLS(ptr_t, ptr_t) MAP_DECLS(uint64_t, ptr_t) MAP_DECLS(handle_T, ptr_t) MAP_DECLS(String, MsgpackRpcRequestHandler) +MAP_DECLS(HlEntry, int) #define map_new(T, U) map_##T##_##U##_new #define map_free(T, U) map_##T##_##U##_free diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 82367fbff8..d3d0968a5c 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -697,7 +697,7 @@ void free_all_mem(void) /* screenlines (can't display anything now!) */ free_screenlines(); - clear_hl_tables(); + clear_hl_tables(false); list_free_log(); } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index bc7cd5f541..f9a474e44b 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1480,6 +1480,8 @@ static void win_update(win_T *wp) wp->w_empty_rows = 0; wp->w_filler_rows = 0; if (!eof && !didline) { + int at_attr = hl_combine_attr(wp->w_hl_attr_normal, + win_hl_attr(wp, HLF_AT)); if (lnum == wp->w_topline) { /* * Single line that does not fit! @@ -1494,12 +1496,11 @@ static void win_update(win_T *wp) int scr_row = wp->w_winrow + wp->w_height - 1; // Last line isn't finished: Display "@@@" in the last screen line. - screen_puts_len((char_u *)"@@", 2, scr_row, wp->w_wincol, - win_hl_attr(wp, HLF_AT)); + screen_puts_len((char_u *)"@@", 2, scr_row, wp->w_wincol, at_attr); screen_fill(scr_row, scr_row + 1, (int)wp->w_wincol + 2, (int)W_ENDCOL(wp), - '@', ' ', win_hl_attr(wp, HLF_AT)); + '@', ' ', at_attr); set_empty_rows(wp, srow); wp->w_botline = lnum; } else if (dy_flags & DY_LASTLINE) { // 'display' has "lastline" @@ -1507,7 +1508,7 @@ static void win_update(win_T *wp) screen_fill(wp->w_winrow + wp->w_height - 1, wp->w_winrow + wp->w_height, W_ENDCOL(wp) - 3, W_ENDCOL(wp), - '@', '@', win_hl_attr(wp, HLF_AT)); + '@', '@', at_attr); set_empty_rows(wp, srow); wp->w_botline = lnum; } else { @@ -1605,7 +1606,7 @@ static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T h # define FDC_OFF n int fdc = compute_foldcolumn(wp, 0); - int attr = win_hl_attr(wp, hl); + int attr = hl_combine_attr(wp->w_hl_attr_normal, win_hl_attr(wp, hl)); if (wp->w_p_rl) { // No check for cmdline window: should never be right-left. @@ -1992,7 +1993,7 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T } screen_line(row + wp->w_winrow, wp->w_wincol, wp->w_width, - wp->w_width, false, wp, 0); + wp->w_width, false, wp, wp->w_hl_attr_normal); /* * Update w_cline_height and w_cline_folded if the cursor line was @@ -2408,7 +2409,7 @@ win_line ( if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !(wp == curwin && VIsual_active)) { int cul_attr = win_hl_attr(wp, HLF_CUL); - HlAttrs *aep = syn_cterm_attr2entry(cul_attr); + HlAttrs *aep = syn_attr2entry(cul_attr); // We make a compromise here (#7383): // * low-priority CursorLine if fg is not set @@ -5392,41 +5393,6 @@ static void end_search_hl(void) } } -static void update_window_hl(win_T *wp, bool invalid) -{ - if (!wp->w_hl_needs_update && !invalid) { - return; - } - wp->w_hl_needs_update = false; - - // determine window specific background set in 'winhighlight' - if (wp != curwin && wp->w_hl_ids[HLF_INACTIVE] > 0) { - wp->w_hl_attr_normal = syn_id2attr(wp->w_hl_ids[HLF_INACTIVE]); - } else if (wp->w_hl_id_normal > 0) { - wp->w_hl_attr_normal = syn_id2attr(wp->w_hl_id_normal); - } else { - wp->w_hl_attr_normal = 0; - } - if (wp != curwin) { - wp->w_hl_attr_normal = hl_combine_attr(HL_ATTR(HLF_INACTIVE), - wp->w_hl_attr_normal); - } - - for (int hlf = 0; hlf < (int)HLF_COUNT; hlf++) { - int attr; - if (wp->w_hl_ids[hlf] > 0) { - attr = syn_id2attr(wp->w_hl_ids[hlf]); - } else { - attr = HL_ATTR(hlf); - } - if (wp->w_hl_attr_normal != 0) { - attr = hl_combine_attr(wp->w_hl_attr_normal, attr); - } - wp->w_hl_attrs[hlf] = attr; - } -} - - /* * Init for calling prepare_search_hl(). diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 44cd3cdeac..ff9619574b 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -7249,15 +7249,7 @@ static void set_hl_attr(int idx) at_en.rgb_bg_color = sgp->sg_rgb_bg_name ? sgp->sg_rgb_bg : -1; at_en.rgb_sp_color = sgp->sg_rgb_sp_name ? sgp->sg_rgb_sp : -1; - if (at_en.cterm_fg_color != 0 || at_en.cterm_bg_color != 0 - || at_en.rgb_fg_color != -1 || at_en.rgb_bg_color != -1 - || at_en.rgb_sp_color != -1 || at_en.cterm_ae_attr != 0 - || at_en.rgb_ae_attr != 0) { - sgp->sg_attr = get_attr_entry(&at_en); - } else { - // If all the fields are cleared, clear the attr field back to default value - sgp->sg_attr = 0; - } + sgp->sg_attr = hl_get_syn_attr(idx+1, at_en); } /// Lookup a highlight group name and return its ID. @@ -7392,7 +7384,7 @@ static void syn_unadd_group(void) /// Translate a group ID to highlight attributes. -/// @see syn_cterm_attr2entry +/// @see syn_attr2entry int syn_id2attr(int hl_id) { struct hl_group *sgp; @@ -7452,7 +7444,6 @@ void highlight_attr_set_all(void) /// screen redraw after any :highlight command. void highlight_changed(void) { - int attr; int id; char_u userhl[10]; int id_SNC = -1; @@ -7467,13 +7458,15 @@ void highlight_changed(void) if (id == 0) { abort(); } - attr = syn_id2attr(id); + int final_id = syn_get_final_id(id); if (hlf == (int)HLF_SNC) { - id_SNC = syn_get_final_id(id); + id_SNC = final_id; } else if (hlf == (int)HLF_S) { - id_S = syn_get_final_id(id); + id_S = final_id; } - highlight_attr[hlf] = attr; + + highlight_attr[hlf] = hl_get_ui_attr(hlf, final_id, + hlf == (int)HLF_INACTIVE); } /* Setup the user highlights diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 7c90d77c1c..c91b959ce3 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -603,7 +603,7 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, int attr_id = 0; if (hl_attrs || vt_fg != -1 || vt_bg != -1) { - attr_id = get_attr_entry(&(HlAttrs) { + attr_id = get_term_attr_entry(&(HlAttrs) { .cterm_ae_attr = (int16_t)hl_attrs, .cterm_fg_color = vt_fg_idx, .cterm_bg_color = vt_bg_idx, diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 4849a47144..03288a3325 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -32,13 +32,13 @@ #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/strings.h" +#include "nvim/syntax.h" #include "nvim/ui_bridge.h" #include "nvim/ugrid.h" #include "nvim/tui/input.h" #include "nvim/tui/tui.h" #include "nvim/tui/terminfo.h" #include "nvim/cursor_shape.h" -#include "nvim/syntax.h" #include "nvim/macros.h" // Space reserved in two output buffers to make the cursor normal or invisible @@ -933,7 +933,7 @@ static void tui_set_mode(UI *ui, ModeShape mode) if (c.id != 0 && ui->rgb) { int attr = syn_id2attr(c.id); if (attr > 0) { - HlAttrs *aep = syn_cterm_attr2entry(attr); + HlAttrs *aep = syn_attr2entry(attr); UNIBI_SET_NUM_VAR(data->params[0], aep->rgb_bg_color); unibi_out_ext(ui, data->unibi_ext.set_cursor_color); } diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 377e011d49..301d3be00e 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -339,7 +339,7 @@ void ui_set_highlight(int attr_code) HlAttrs attrs = HLATTRS_INIT; if (attr_code != 0) { - HlAttrs *aep = syn_cterm_attr2entry(attr_code); + HlAttrs *aep = syn_attr2entry(attr_code); if (aep) { attrs = *aep; } diff --git a/src/nvim/ui.h b/src/nvim/ui.h index 6b04e9c67a..9e98ff9f15 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -6,7 +6,6 @@ #include #include "api/private/defs.h" -#include "nvim/buffer_defs.h" typedef enum { kUICmdline = 0, -- cgit From 2134396074d86c344aaf43c3b839fd38c499fb69 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 9 Apr 2018 12:58:17 +0200 Subject: ui: add TODO for non-working terminal linewrap Note: this has not been working since the TUI reimplementation --- src/nvim/screen.c | 20 +------------------- src/nvim/ui.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index f9a474e44b..41a430bb8b 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -4226,25 +4226,7 @@ win_line ( LineOffset[screen_row] + screen_Columns) == 2)) ) { - /* First make sure we are at the end of the screen line, - * then output the same character again to let the - * terminal know about the wrap. If the terminal doesn't - * auto-wrap, we overwrite the character. */ - if (ui_current_col() != wp->w_width) - screen_char(LineOffset[screen_row - 1] - + (unsigned)Columns - 1, - screen_row - 1, (int)(Columns - 1)); - - /* When there is a multi-byte character, just output a - * space to keep it simple. */ - if (ScreenLines[LineOffset[screen_row - 1] - + (Columns - 1)][1] != 0) { - ui_putc(' '); - } else { - ui_puts(ScreenLines[LineOffset[screen_row - 1] + (Columns - 1)]); - } - /* force a redraw of the first char on the next line */ - ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; + ui_add_linewrap(screen_row-1); } } diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 301d3be00e..8419951079 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -403,6 +403,32 @@ void ui_cursor_goto(int new_row, int new_col) pending_cursor_update = true; } +void ui_add_linewrap(int row) +{ + // TODO(bfredl): check that this actually still works + // and move to TUI module in that case. +#if 0 + // First make sure we are at the end of the screen line, + // then output the same character again to let the + // terminal know about the wrap. If the terminal doesn't + // auto-wrap, we overwrite the character. + if (ui_current_col() != Columns) { + screen_char(LineOffset[row] + (unsigned)Columns - 1, row, + (int)(Columns - 1)); + } + + // When there is a multi-byte character, just output a + // space to keep it simple. */ + if (ScreenLines[LineOffset[row] + (Columns - 1)][1] != 0) { + ui_putc(' '); + } else { + ui_puts(ScreenLines[LineOffset[row] + (Columns - 1)]); + } + // force a redraw of the first char on the next line + ScreenAttrs[LineOffset[row+1]] = (sattr_T)-1; +#endif +} + void ui_mode_info_set(void) { Array style = mode_style_array(); -- cgit From 1adb01c120d04bdbf25cd4ea6151ecd5f2de3a72 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 6 Jul 2018 14:39:50 +0200 Subject: ui: use line-based rather than char-based updates in screen.c Add ext_newgrid and ext_hlstate extensions. These use predefined highlights and line-segment based updates, for efficiency and simplicity.. The ext_hlstate extension in addition allows semantic identification of builtin and syntax highlights. Reimplement the old char-based updates in the remote UI layer, for compatibility. For the moment, this is still the default. The bulitin TUI uses the new line-based protocol. cmdline uses curwin cursor position when ext_cmdline is active. --- src/nvim/api/ui.c | 345 ++++++++++++++++++++++++--- src/nvim/api/ui_events.in.h | 68 ++++-- src/nvim/event/defs.h | 2 +- src/nvim/ex_docmd.c | 4 +- src/nvim/ex_getln.c | 22 +- src/nvim/generators/gen_api_ui_events.lua | 26 ++- src/nvim/highlight.c | 19 +- src/nvim/highlight_defs.h | 13 ++ src/nvim/lib/kvec.h | 8 +- src/nvim/main.c | 3 +- src/nvim/message.c | 12 +- src/nvim/misc1.c | 2 +- src/nvim/popupmnu.c | 3 + src/nvim/screen.c | 377 +++++++++++++++--------------- src/nvim/syntax.c | 14 +- src/nvim/tui/tui.c | 174 +++++++------- src/nvim/ugrid.c | 17 +- src/nvim/ugrid.h | 3 +- src/nvim/ui.c | 193 +++++---------- src/nvim/ui.h | 19 +- src/nvim/ui_bridge.c | 50 ++-- 21 files changed, 848 insertions(+), 526 deletions(-) (limited to 'src') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 01e6e0ca03..63c2c4a1b9 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -26,6 +26,12 @@ typedef struct { uint64_t channel_id; Array buffer; + + int hl_id; // current higlight for legacy put event + Integer cursor_row, cursor_col; // Intended visibule cursor position + + // Position of legacy cursor, used both for drawing and visible user cursor. + Integer client_row, client_col; } UIData; static PMap(uint64_t) *connected_uis = NULL; @@ -71,10 +77,9 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, ui->width = (int)width; ui->height = (int)height; ui->rgb = true; - ui->resize = remote_ui_resize; - ui->clear = remote_ui_clear; - ui->eol_clear = remote_ui_eol_clear; - ui->cursor_goto = remote_ui_cursor_goto; + ui->grid_resize = remote_ui_grid_resize; + ui->grid_clear = remote_ui_grid_clear; + ui->grid_cursor_goto = remote_ui_grid_cursor_goto; ui->mode_info_set = remote_ui_mode_info_set; ui->update_menu = remote_ui_update_menu; ui->busy_start = remote_ui_busy_start; @@ -82,16 +87,12 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, ui->mouse_on = remote_ui_mouse_on; ui->mouse_off = remote_ui_mouse_off; ui->mode_change = remote_ui_mode_change; - ui->set_scroll_region = remote_ui_set_scroll_region; - ui->scroll = remote_ui_scroll; - ui->highlight_set = remote_ui_highlight_set; - ui->put = remote_ui_put; + ui->grid_scroll = remote_ui_grid_scroll; + ui->hl_attr_define = remote_ui_hl_attr_define; + ui->raw_line = remote_ui_raw_line; ui->bell = remote_ui_bell; ui->visual_bell = remote_ui_visual_bell; ui->default_colors_set = remote_ui_default_colors_set; - ui->update_fg = remote_ui_update_fg; - ui->update_bg = remote_ui_update_bg; - ui->update_sp = remote_ui_update_sp; ui->flush = remote_ui_flush; ui->suspend = remote_ui_suspend; ui->set_title = remote_ui_set_title; @@ -103,16 +104,22 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, memset(ui->ui_ext, 0, sizeof(ui->ui_ext)); for (size_t i = 0; i < options.size; i++) { - ui_set_option(ui, options.items[i].key, options.items[i].value, err); + ui_set_option(ui, true, options.items[i].key, options.items[i].value, err); if (ERROR_SET(err)) { xfree(ui); return; } } + if (ui->ui_ext[kUIHlState]) { + ui->ui_ext[kUINewgrid] = true; + } + UIData *data = xmalloc(sizeof(UIData)); data->channel_id = channel_id; data->buffer = (Array)ARRAY_DICT_INIT; + data->hl_id = 0; + data->client_col = -1; ui->data = data; pmap_put(uint64_t)(connected_uis, channel_id, ui); @@ -174,13 +181,11 @@ void nvim_ui_set_option(uint64_t channel_id, String name, } UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); - ui_set_option(ui, name, value, error); - if (!ERROR_SET(error)) { - ui_refresh(); - } + ui_set_option(ui, false, name, value, error); } -static void ui_set_option(UI *ui, String name, Object value, Error *error) +static void ui_set_option(UI *ui, bool init, String name, Object value, + Error *error) { if (strequal(name.data, "rgb")) { if (value.type != kObjectTypeBoolean) { @@ -188,40 +193,46 @@ static void ui_set_option(UI *ui, String name, Object value, Error *error) return; } ui->rgb = value.data.boolean; + // A little drastic, but only legacy uis need to use this option + if (!init) { + ui_refresh(); + } return; } + // LEGACY: Deprecated option, use `ext_cmdline` instead. + bool is_popupmenu = strequal(name.data, "popupmenu_external"); + for (UIExtension i = 0; i < kUIExtCount; i++) { - if (strequal(name.data, ui_ext_names[i])) { + if (strequal(name.data, ui_ext_names[i]) + || (i == kUIPopupmenu && is_popupmenu)) { if (value.type != kObjectTypeBoolean) { snprintf((char *)IObuff, IOSIZE, "%s must be a Boolean", - ui_ext_names[i]); + name.data); api_set_error(error, kErrorTypeValidation, (char *)IObuff); return; } - ui->ui_ext[i] = value.data.boolean; - return; - } - } - - if (strequal(name.data, "popupmenu_external")) { - // LEGACY: Deprecated option, use `ext_cmdline` instead. - if (value.type != kObjectTypeBoolean) { - api_set_error(error, kErrorTypeValidation, - "popupmenu_external must be a Boolean"); + bool boolval = value.data.boolean; + if (!init && i == kUINewgrid && boolval != ui->ui_ext[i]) { + // There shouldn't be a reason for an UI to do this ever + // so explicitly don't support this. + api_set_error(error, kErrorTypeValidation, + "ext_newgrid option cannot be changed"); + } + ui->ui_ext[i] = boolval; + if (!init) { + ui_set_ext_option(ui, i, boolval); + } return; } - ui->ui_ext[kUIPopupmenu] = value.data.boolean; - return; } api_set_error(error, kErrorTypeValidation, "No such UI option: %s", name.data); -#undef UI_EXT_OPTION } /// Pushes data into UI.UIData, to be consumed later by remote_ui_flush(). -static void push_call(UI *ui, char *name, Array args) +static void push_call(UI *ui, const char *name, Array args) { Array call = ARRAY_DICT_INIT; UIData *data = ui->data; @@ -243,27 +254,293 @@ static void push_call(UI *ui, char *name, Array args) kv_A(data->buffer, kv_size(data->buffer) - 1).data.array = call; } +static void remote_ui_grid_clear(UI *ui, Integer grid) +{ + Array args = ARRAY_DICT_INIT; + if (ui->ui_ext[kUINewgrid]) { + ADD(args, INTEGER_OBJ(grid)); + } + const char *name = ui->ui_ext[kUINewgrid] ? "grid_clear" : "clear"; + push_call(ui, name, args); +} -static void remote_ui_highlight_set(UI *ui, HlAttrs attrs) +static void remote_ui_grid_resize(UI *ui, Integer grid, + Integer width, Integer height) { Array args = ARRAY_DICT_INIT; + if (ui->ui_ext[kUINewgrid]) { + ADD(args, INTEGER_OBJ(grid)); + } + ADD(args, INTEGER_OBJ(width)); + ADD(args, INTEGER_OBJ(height)); + const char *name = ui->ui_ext[kUINewgrid] ? "grid_resize" : "resize"; + push_call(ui, name, args); +} + +static void remote_ui_grid_scroll(UI *ui, Integer grid, Integer top, + Integer bot, Integer left, Integer right, + Integer rows, Integer cols) +{ + if (ui->ui_ext[kUINewgrid]) { + Array args = ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(grid)); + ADD(args, INTEGER_OBJ(top)); + ADD(args, INTEGER_OBJ(bot)); + ADD(args, INTEGER_OBJ(left)); + ADD(args, INTEGER_OBJ(right)); + ADD(args, INTEGER_OBJ(rows)); + ADD(args, INTEGER_OBJ(cols)); + push_call(ui, "grid_scroll", args); + } else { + Array args = ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(top)); + ADD(args, INTEGER_OBJ(bot-1)); + ADD(args, INTEGER_OBJ(left)); + ADD(args, INTEGER_OBJ(right-1)); + push_call(ui, "set_scroll_region", args); + + args = (Array)ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(rows)); + push_call(ui, "scroll", args); + } +} + +static void remote_ui_default_colors_set(UI *ui, Integer rgb_fg, + Integer rgb_bg, Integer rgb_sp, + Integer cterm_fg, Integer cterm_bg) +{ + Array args = ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(rgb_fg)); + ADD(args, INTEGER_OBJ(rgb_bg)); + ADD(args, INTEGER_OBJ(rgb_sp)); + ADD(args, INTEGER_OBJ(cterm_fg)); + ADD(args, INTEGER_OBJ(cterm_bg)); + push_call(ui, "default_colors_set", args); + + // Deprecated + if (!ui->ui_ext[kUINewgrid]) { + args = (Array)ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(ui->rgb ? rgb_fg : cterm_fg - 1)); + push_call(ui, "update_fg", args); + + args = (Array)ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(ui->rgb ? rgb_bg : cterm_bg - 1)); + push_call(ui, "update_bg", args); + + args = (Array)ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(ui->rgb ? rgb_sp : -1)); + push_call(ui, "update_sp", args); + } +} + +static void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, + HlAttrs cterm_attrs, Array info) +{ + if (!ui->ui_ext[kUINewgrid]) { + return; + } + Array args = ARRAY_DICT_INIT; + + ADD(args, INTEGER_OBJ(id)); + + Dictionary rgb_hl = hlattrs2dict(&rgb_attrs, true); + ADD(args, DICTIONARY_OBJ(rgb_hl)); + + Dictionary cterm_hl = hlattrs2dict(&cterm_attrs, false); + ADD(args, DICTIONARY_OBJ(cterm_hl)); + + if (ui->ui_ext[kUIHlState]) { + ADD(args, ARRAY_OBJ(copy_array(info))); + } else { + ADD(args, ARRAY_OBJ((Array)ARRAY_DICT_INIT)); + } + + push_call(ui, "hl_attr_define", args); +} + +static void remote_ui_highlight_set(UI *ui, int id) +{ + Array args = ARRAY_DICT_INIT; + UIData *data = ui->data; + + HlAttrs attrs = HLATTRS_INIT; + + if (data->hl_id == id) { + return; + } + data->hl_id = id; + + if (id != 0) { + HlAttrs *aep = syn_attr2entry(id); + if (aep) { + attrs = *aep; + } + } + Dictionary hl = hlattrs2dict(&attrs, ui->rgb); ADD(args, DICTIONARY_OBJ(hl)); push_call(ui, "highlight_set", args); } +/// "true" cursor used only for input focus +static void remote_ui_grid_cursor_goto(UI *ui, Integer grid, Integer row, + Integer col) +{ + if (ui->ui_ext[kUINewgrid]) { + Array args = ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(grid)); + ADD(args, INTEGER_OBJ(row)); + ADD(args, INTEGER_OBJ(col)); + push_call(ui, "grid_cursor_goto", args); + } else { + UIData *data = ui->data; + data->cursor_row = row; + data->cursor_col = col; + remote_ui_cursor_goto(ui, row, col); + } +} + +/// emulated cursor used both for drawing and for input focus +static void remote_ui_cursor_goto(UI *ui, Integer row, Integer col) +{ + UIData *data = ui->data; + if (data->client_row == row && data->client_col == col) { + return; + } + data->client_row = row; + data->client_col = col; + Array args = ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(row)); + ADD(args, INTEGER_OBJ(col)); + push_call(ui, "cursor_goto", args); +} + +static void remote_ui_put(UI *ui, const char *cell) +{ + UIData *data = ui->data; + data->client_col++; + Array args = ARRAY_DICT_INIT; + ADD(args, STRING_OBJ(cstr_to_string(cell))); + push_call(ui, "put", args); +} + +static void remote_ui_raw_line(UI *ui, Integer grid, Integer row, + Integer startcol, Integer endcol, + Integer clearcol, Integer clearattr, + const schar_T *chunk, const sattr_T *attrs) +{ + UIData *data = ui->data; + if (ui->ui_ext[kUINewgrid]) { + Array args = ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(grid)); + ADD(args, INTEGER_OBJ(row)); + ADD(args, INTEGER_OBJ(startcol)); + Array cells = ARRAY_DICT_INIT; + int repeat = 0; + size_t ncells = (size_t)(endcol-startcol); + int last_hl = -1; + for (size_t i = 0; i < ncells; i++) { + repeat++; + if (i == ncells-1 || attrs[i] != attrs[i+1] + || STRCMP(chunk[i], chunk[i+1])) { + Array cell = ARRAY_DICT_INIT; + ADD(cell, STRING_OBJ(cstr_to_string((const char *)chunk[i]))); + if (attrs[i] != last_hl || repeat > 1) { + ADD(cell, INTEGER_OBJ(attrs[i])); + last_hl = attrs[i]; + } + if (repeat > 1) { + ADD(cell, INTEGER_OBJ(repeat)); + } + ADD(cells, ARRAY_OBJ(cell)); + repeat = 0; + } + } + if (endcol < clearcol) { + Array cell = ARRAY_DICT_INIT; + ADD(cell, STRING_OBJ(cstr_to_string(" "))); + ADD(cell, INTEGER_OBJ(clearattr)); + ADD(cell, INTEGER_OBJ(clearcol-endcol)); + ADD(cells, ARRAY_OBJ(cell)); + } + ADD(args, ARRAY_OBJ(cells)); + + push_call(ui, "grid_line", args); + } else { + for (int i = 0; i < endcol-startcol; i++) { + remote_ui_cursor_goto(ui, row, startcol+i); + remote_ui_highlight_set(ui, attrs[i]); + remote_ui_put(ui, (const char *)chunk[i]); + if (utf_ambiguous_width(utf_ptr2char(chunk[i]))) { + data->client_col = -1; // force cursor update + } + } + if (endcol < clearcol) { + remote_ui_cursor_goto(ui, row, endcol); + remote_ui_highlight_set(ui, (int)clearattr); + // legacy eol_clear was only ever used with cleared attributes + // so be on the safe side + if (clearattr == 0 && clearcol == Columns) { + Array args = ARRAY_DICT_INIT; + push_call(ui, "eol_clear", args); + } else { + for (Integer c = endcol; c < clearcol; c++) { + remote_ui_put(ui, " "); + } + } + } + } +} + static void remote_ui_flush(UI *ui) { UIData *data = ui->data; if (data->buffer.size > 0) { + if (!ui->ui_ext[kUINewgrid]) { + remote_ui_cursor_goto(ui, data->cursor_row, data->cursor_col); + } rpc_send_event(data->channel_id, "redraw", data->buffer); data->buffer = (Array)ARRAY_DICT_INIT; } } +static void remote_ui_cmdline_show(UI *ui, Array args) +{ + Array new_args = ARRAY_DICT_INIT; + Array contents = args.items[0].data.array; + Array new_contents = ARRAY_DICT_INIT; + for (size_t i = 0; i < contents.size; i++) { + Array item = contents.items[i].data.array; + Array new_item = ARRAY_DICT_INIT; + int attr = (int)item.items[0].data.integer; + if (attr) { + HlAttrs *aep = syn_attr2entry(attr); + Dictionary rgb_attrs = hlattrs2dict(aep, ui->rgb ? kTrue : kFalse); + ADD(new_item, DICTIONARY_OBJ(rgb_attrs)); + } else { + ADD(new_item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); + } + ADD(new_item, copy_object(item.items[1])); + ADD(new_contents, ARRAY_OBJ(new_item)); + } + ADD(new_args, ARRAY_OBJ(new_contents)); + for (size_t i = 1; i < args.size; i++) { + ADD(new_args, copy_object(args.items[i])); + } + push_call(ui, "cmdline_show", new_args); +} + static void remote_ui_event(UI *ui, char *name, Array args, bool *args_consumed) { + if (!ui->ui_ext[kUINewgrid]) { + // the representation of cmdline_show changed, translate back + if (strequal(name, "cmdline_show")) { + remote_ui_cmdline_show(ui, args); + // never consumes args + return; + } + } Array my_args = ARRAY_DICT_INIT; // Objects are currently single-reference // make a copy, but only if necessary diff --git a/src/nvim/a