mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
highlight: refactor to use stateful representation
This allows us to keep track of the source higlight groups, and not only the final combined highlights.
This commit is contained in:
parent
696e24f311
commit
989b585e10
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 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)
|
||||
/// @return TRUE if hl table was reset
|
||||
bool highlight_use_hlstate(void)
|
||||
{
|
||||
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) {
|
||||
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, 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.
|
||||
static int get_attr_entry(HlEntry entry)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
int id = map_get(HlEntry, int)(attr_entry_ids, entry);
|
||||
if (id > 0) {
|
||||
return id;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
highlight_attr_set_all();
|
||||
|
||||
recursive = FALSE;
|
||||
recursive = false;
|
||||
if (entry.kind == kHlCombine) {
|
||||
// This entry is now invalid, don't put it
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
id = (int)kv_size(attr_entries);
|
||||
kv_push(attr_entries, entry);
|
||||
|
||||
return table->ga_len - 1 + ATTR_OFF;
|
||||
map_put(HlEntry, int)(attr_entry_ids, entry, id);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
// Clear all highlight tables.
|
||||
void clear_hl_tables(void)
|
||||
/// Get attribute code for a syntax group.
|
||||
int hl_get_syn_attr(int idx, HlAttrs at_en)
|
||||
{
|
||||
ga_clear(&attr_table);
|
||||
// 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// 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(bool reinit)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
if (prim_attr == 0) {
|
||||
} else 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));
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "nvim/highlight_defs.h"
|
||||
#include "nvim/api/private/defs.h"
|
||||
#include "nvim/ui.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "highlight.h.generated.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
|
||||
|
@ -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).
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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().
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "api/private/defs.h"
|
||||
#include "nvim/buffer_defs.h"
|
||||
|
||||
typedef enum {
|
||||
kUICmdline = 0,
|
||||
|
@ -834,7 +834,7 @@ describe("'winhighlight' highlight", function()
|
||||
{1:a^a }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
{11:[No Name] [+] }|
|
||||
{3:[No Name] [+] }|
|
||||
aa |
|
||||
{0:~ }|
|
||||
{4:[No Name] [+] }|
|
||||
@ -846,7 +846,7 @@ describe("'winhighlight' highlight", function()
|
||||
{1:^ }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
{11:[No Name] }|
|
||||
{3:[No Name] }|
|
||||
aa |
|
||||
{0:~ }|
|
||||
{4:[No Name] [+] }|
|
||||
@ -891,7 +891,7 @@ describe("'winhighlight' highlight", function()
|
||||
{1:a^a }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
{11:[No Name] [+] }|
|
||||
{3:[No Name] [+] }|
|
||||
aa |
|
||||
{0:~ }|
|
||||
{4:[No Name] [+] }|
|
||||
@ -915,7 +915,7 @@ describe("'winhighlight' highlight", function()
|
||||
{1:^aa }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
{11:[No Name] [+] }|
|
||||
{3:[No Name] [+] }|
|
||||
aa |
|
||||
{0:~ }|
|
||||
{4:[No Name] [+] }|
|
||||
@ -931,10 +931,10 @@ describe("'winhighlight' highlight", function()
|
||||
{1:^ }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
{11:[No Name] }|
|
||||
{3:[No Name] }|
|
||||
{5: }|
|
||||
{6:~ }|
|
||||
{12:[No Name] }|
|
||||
{4:[No Name] }|
|
||||
|
|
||||
]])
|
||||
|
||||
@ -943,10 +943,10 @@ describe("'winhighlight' highlight", function()
|
||||
{5: }|
|
||||
{6:~ }|
|
||||
{6:~ }|
|
||||
{12:[No Name] }|
|
||||
{4:[No Name] }|
|
||||
{1:^ }|
|
||||
{2:~ }|
|
||||
{11:[No Name] }|
|
||||
{3:[No Name] }|
|
||||
|
|
||||
]])
|
||||
|
||||
@ -955,10 +955,10 @@ describe("'winhighlight' highlight", function()
|
||||
{1:^ }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
{11:[No Name] }|
|
||||
{3:[No Name] }|
|
||||
{5: }|
|
||||
{6:~ }|
|
||||
{12:[No Name] }|
|
||||
{4:[No Name] }|
|
||||
|
|
||||
]])
|
||||
end)
|
||||
@ -974,7 +974,7 @@ describe("'winhighlight' highlight", function()
|
||||
{3:[No Name] }|
|
||||
{7: }|
|
||||
{8:~ }|
|
||||
{13:[No Name] }|
|
||||
{4:[No Name] }|
|
||||
|
|
||||
]])
|
||||
|
||||
@ -983,7 +983,7 @@ describe("'winhighlight' highlight", function()
|
||||
{7: }|
|
||||
{8:~ }|
|
||||
{8:~ }|
|
||||
{13:[No Name] }|
|
||||
{4:[No Name] }|
|
||||
^ |
|
||||
{0:~ }|
|
||||
{3:[No Name] }|
|
||||
@ -997,10 +997,10 @@ describe("'winhighlight' highlight", function()
|
||||
{7: }|
|
||||
{8:~ }|
|
||||
{8:~ }|
|
||||
{13:[No Name] }|
|
||||
{4:[No Name] }|
|
||||
{1:^ }|
|
||||
{2:~ }|
|
||||
{11:[No Name] }|
|
||||
{3:[No Name] }|
|
||||
|
|
||||
]])
|
||||
|
||||
@ -1012,7 +1012,7 @@ describe("'winhighlight' highlight", function()
|
||||
{3:[No Name] }|
|
||||
{1: }|
|
||||
{2:~ }|
|
||||
{14:[No Name] }|
|
||||
{4:[No Name] }|
|
||||
|
|
||||
]])
|
||||
|
||||
@ -1022,10 +1022,10 @@ describe("'winhighlight' highlight", function()
|
||||
{7: }|
|
||||
{8:~ }|
|
||||
{8:~ }|
|
||||
{13:[No Name] }|
|
||||
{4:[No Name] }|
|
||||
{1:^ }|
|
||||
{2:~ }|
|
||||
{11:[No Name] }|
|
||||
{3:[No Name] }|
|
||||
|
|
||||
]])
|
||||
|
||||
@ -1037,7 +1037,7 @@ describe("'winhighlight' highlight", function()
|
||||
{3:[No Name] }|
|
||||
{5: }|
|
||||
{6:~ }|
|
||||
{12:[No Name] }|
|
||||
{4:[No Name] }|
|
||||
|
|
||||
]])
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user