api: add API for themes

co-author: hlpr98 <hlpr98@gmail.com> (dict2hlattrs function)

orange is sus??

NOVEMBER DAWN

erase the lie that is redraw_later()
This commit is contained in:
Björn Linse 2020-09-08 09:47:10 +02:00
parent 037ffd54dc
commit c146eddc8b
43 changed files with 690 additions and 203 deletions

View File

@ -974,9 +974,9 @@ void nvim_buf_delete(Buffer buffer, Dictionary opts, Error *err)
String k = opts.items[i].key;
Object v = opts.items[i].value;
if (strequal("force", k.data)) {
force = api_coerce_to_bool(v, "force", false, err);
force = api_object_to_bool(v, "force", false, err);
} else if (strequal("unload", k.data)) {
unload = api_coerce_to_bool(v, "unload", false, err);
unload = api_object_to_bool(v, "unload", false, err);
} else {
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
return;
@ -1441,7 +1441,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,
goto error;
}
} else if (strequal("ephemeral", k.data)) {
ephemeral = api_coerce_to_bool(*v, "ephemeral", false, err);
ephemeral = api_object_to_bool(*v, "ephemeral", false, err);
if (ERROR_SET(err)) {
goto error;
}

View File

@ -1625,11 +1625,8 @@ free_exit:
/// @param what The name of the object, used for error message
/// @param nil_value What to return if the type is nil.
/// @param err Set if there was an error in converting to a bool
bool api_coerce_to_bool(
Object obj,
const char *what,
bool nil_value,
Error *err)
bool api_object_to_bool(Object obj, const char *what,
bool nil_value, Error *err)
{
if (obj.type == kObjectTypeBoolean) {
return obj.data.boolean;
@ -1654,3 +1651,30 @@ const char *describe_ns(NS ns_id)
})
return "(UNKNOWN PLUGIN)";
}
DecorationProvider *get_provider(NS ns_id, bool force)
{
ssize_t i;
for (i = 0; i < (ssize_t)kv_size(decoration_providers); i++) {
DecorationProvider *item = &kv_A(decoration_providers, i);
if (item->ns_id == ns_id) {
return item;
} else if (item->ns_id > ns_id) {
break;
}
}
if (!force) {
return NULL;
}
for (ssize_t j = (ssize_t)kv_size(decoration_providers)-1; j >= i; j++) {
// allocates if needed:
(void)kv_a(decoration_providers, (size_t)j+1);
kv_A(decoration_providers, (size_t)j+1) = kv_A(decoration_providers, j);
}
DecorationProvider *item = &kv_a(decoration_providers, (size_t)i);
*item = DECORATION_PROVIDER_INIT(ns_id);
return item;
}

View File

@ -199,6 +199,69 @@ Integer nvim_get_hl_id_by_name(String name)
return syn_check_group((const char_u *)name.data, (int)name.size);
}
Dictionary nvim__get_hl_defs(Integer ns_id, Error *err)
{
if (ns_id == 0) {
return get_global_hl_defs();
}
abort();
}
/// Set a highlight group.
///
/// @param ns_id number of namespace for this highlight
/// @param name highlight group name, like ErrorMsg
/// @param val highlight definiton map, like |nvim_get_hl_by_name|.
/// @param[out] err Error details, if any
///
/// TODO: ns_id = 0, should modify :highlight namespace
/// TODO val should take update vs reset flag
void nvim_set_hl(Integer ns_id, String name, Dictionary val, Error *err)
FUNC_API_SINCE(7)
{
int hl_id = syn_check_group( (char_u *)(name.data), (int)name.size);
int link_id = -1;
HlAttrs attrs = dict2hlattrs(val, true, &link_id, err);
if (!ERROR_SET(err)) {
ns_hl_def((NS)ns_id, hl_id, attrs, link_id);
}
}
/// Set active namespace for highlights.
///
/// NB: this function can be called from async contexts, but the
/// semantics are not yet well-defined. To start with
/// |nvim_set_decoration_provider| on_win and on_line callbacks
/// are explicitly allowed to change the namespace during a redraw cycle.
///
/// @param ns_id the namespace to activate
/// @param[out] err Error details, if any
void nvim_set_hl_ns(Integer ns_id, Error *err)
FUNC_API_SINCE(7)
FUNC_API_FAST
{
if (ns_id >= 0) {
ns_hl_active = (NS)ns_id;
}
// TODO(bfredl): this is a little bit hackish. Eventually we want a standard
// event path for redraws caused by "fast" events. This could tie in with
// better throttling of async events causing redraws, such as non-batched
// nvim_buf_set_extmark calls from async contexts.
if (!updating_screen && !ns_hl_changed) {
multiqueue_put(main_loop.events, on_redraw_event, 0);
}
ns_hl_changed = true;
}
static void on_redraw_event(void **argv)
FUNC_API_NOEXPORT
{
redraw_all_later(NOT_VALID);
}
/// Sends input-keys to Nvim, subject to various quirks controlled by `mode`
/// flags. This is a blocking call, unlike |nvim_input()|.
///
@ -1477,7 +1540,7 @@ void nvim_unsubscribe(uint64_t channel_id, String event)
Integer nvim_get_color_by_name(String name)
FUNC_API_SINCE(1)
{
return name_to_color((char_u *)name.data);
return name_to_color(name.data);
}
/// Returns a map of color names and RGB values.
@ -2610,33 +2673,6 @@ void nvim__screenshot(String path)
ui_call_screenshot(path);
}
static DecorationProvider *get_provider(NS ns_id, bool force)
{
ssize_t i;
for (i = 0; i < (ssize_t)kv_size(decoration_providers); i++) {
DecorationProvider *item = &kv_A(decoration_providers, i);
if (item->ns_id == ns_id) {
return item;
} else if (item->ns_id > ns_id) {
break;
}
}
if (!force) {
return NULL;
}
for (ssize_t j = (ssize_t)kv_size(decoration_providers)-1; j >= i; j++) {
// allocates if needed:
(void)kv_a(decoration_providers, (size_t)j+1);
kv_A(decoration_providers, (size_t)j+1) = kv_A(decoration_providers, j);
}
DecorationProvider *item = &kv_a(decoration_providers, (size_t)i);
*item = DECORATION_PROVIDER_INIT(ns_id);
return item;
}
static void clear_provider(DecorationProvider *p)
{
NLUA_CLEAR_REF(p->redraw_start);
@ -2695,7 +2731,7 @@ void nvim_set_decoration_provider(Integer ns_id, DictionaryOf(LuaRef) opts,
clear_provider(p);
// regardless of what happens, it seems good idea to redraw
redraw_later(NOT_VALID); // TODO(bfredl): too soon?
redraw_all_later(NOT_VALID); // TODO(bfredl): too soon?
struct {
const char *name;
@ -2706,6 +2742,7 @@ void nvim_set_decoration_provider(Integer ns_id, DictionaryOf(LuaRef) opts,
{ "on_win", &p->redraw_win },
{ "on_line", &p->redraw_line },
{ "on_end", &p->redraw_end },
{ "_on_hl_def", &p->hl_def },
{ NULL, NULL },
};

View File

@ -142,7 +142,7 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
// make sure cursor is in visible range even if win != curwin
update_topline_win(win);
redraw_win_later(win, VALID);
redraw_later(win, VALID);
}
/// Gets the window height
@ -471,7 +471,7 @@ void nvim_win_set_config(Window window, Dictionary config, Error *err)
if (!win_new_float(win, fconfig, err)) {
return;
}
redraw_later(NOT_VALID);
redraw_later(win, NOT_VALID);
} else {
win_config_float(win, fconfig);
win->w_pos_changed = true;

View File

@ -1623,7 +1623,7 @@ void enter_buffer(buf_T *buf)
}
curbuf->b_last_used = time(NULL);
redraw_later(NOT_VALID);
redraw_later(curwin, NOT_VALID);
}
// Change to the directory of the current buffer.

View File

@ -294,7 +294,7 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume,
// change.
if (wp->w_p_rnu
|| (wp->w_p_cul && lnum <= wp->w_last_cursorline)) {
redraw_win_later(wp, SOME_VALID);
redraw_later(wp, SOME_VALID);
}
}
}
@ -348,7 +348,7 @@ void changed_bytes(linenr_T lnum, colnr_T col)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_p_diff && wp != curwin) {
redraw_win_later(wp, VALID);
redraw_later(wp, VALID);
wlnum = diff_lnum_win(lnum, wp);
if (wlnum > 0) {
changedOneline(wp->w_buffer, wlnum);
@ -475,7 +475,7 @@ changed_lines(
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_p_diff && wp != curwin) {
redraw_win_later(wp, VALID);
redraw_later(wp, VALID);
wlnum = diff_lnum_win(lnum, wp);
if (wlnum > 0) {
changed_lines_buf(wp->w_buffer, wlnum,

View File

@ -482,7 +482,7 @@ bool leftcol_changed(void)
if (retval)
curwin->w_set_curswant = true;
redraw_later(NOT_VALID);
redraw_later(curwin, NOT_VALID);
return retval;
}

View File

@ -643,7 +643,7 @@ void diff_redraw(bool dofold)
if (!wp->w_p_diff) {
continue;
}
redraw_win_later(wp, SOME_VALID);
redraw_later(wp, SOME_VALID);
if (dofold && foldmethodIsDiff(wp)) {
foldUpdateAll(wp);
}
@ -1415,7 +1415,7 @@ void diff_win_options(win_T *wp, int addbuf)
if (addbuf) {
diff_buf_add(wp->w_buffer);
}
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
}
/// Set options not to show diffs. For the current window or all windows.

View File

@ -8571,7 +8571,7 @@ static void ins_up(
if (old_topline != curwin->w_topline
|| old_topfill != curwin->w_topfill
)
redraw_later(VALID);
redraw_later(curwin, VALID);
start_arrow(&tpos);
can_cindent = true;
} else {
@ -8619,7 +8619,7 @@ static void ins_down(
if (old_topline != curwin->w_topline
|| old_topfill != curwin->w_topfill
)
redraw_later(VALID);
redraw_later(curwin, VALID);
start_arrow(&tpos);
can_cindent = true;
} else {
@ -9013,7 +9013,7 @@ static int ins_ctrl_ey(int tc)
scrolldown_clamp();
else
scrollup_clamp();
redraw_later(VALID);
redraw_later(curwin, VALID);
} else {
c = ins_copychar(curwin->w_cursor.lnum + (c == Ctrl_Y ? -1 : 1));
if (c != NUL) {

View File

@ -3721,8 +3721,8 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout,
update_topline();
validate_cursor();
update_screen(SOME_VALID);
highlight_match = FALSE;
redraw_later(SOME_VALID);
highlight_match = false;
redraw_later(curwin, SOME_VALID);
curwin->w_p_fen = save_p_fen;
if (msg_row == Rows - 1)
@ -5751,7 +5751,7 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr,
}
xfree(str);
redraw_later(SOME_VALID);
redraw_later(curwin, SOME_VALID);
win_enter(save_curwin, false); // Return to original window
update_topline();

View File

@ -7379,7 +7379,7 @@ static void ex_syncbind(exarg_T *eap)
else
scrolldown(-y, TRUE);
curwin->w_scbind_pos = topline;
redraw_later(VALID);
redraw_later(curwin, VALID);
cursor_correct();
curwin->w_redr_status = TRUE;
}
@ -8504,7 +8504,7 @@ static void ex_pedit(exarg_T *eap)
if (curwin != curwin_save && win_valid(curwin_save)) {
// Return cursor to where we were
validate_cursor();
redraw_later(VALID);
redraw_later(curwin, VALID);
win_enter(curwin_save, true);
}
g_do_tagpreview = 0;

View File

@ -6483,7 +6483,7 @@ static int open_cmdwin(void)
ccline.redraw_state = kCmdRedrawNone;
ui_call_cmdline_hide(ccline.level);
}
redraw_later(SOME_VALID);
redraw_later(curwin, SOME_VALID);
// Save the command line info, can be used recursively.
save_cmdline(&save_ccline);

View File

@ -50,10 +50,13 @@ typedef struct {
LuaRef redraw_win;
LuaRef redraw_line;
LuaRef redraw_end;
LuaRef hl_def;
int hl_valid;
} DecorationProvider;
#define DECORATION_PROVIDER_INIT(ns_id) (DecorationProvider) \
{ ns_id, false, LUA_NOREF, LUA_NOREF, \
LUA_NOREF, LUA_NOREF, LUA_NOREF }
LUA_NOREF, LUA_NOREF, LUA_NOREF, \
LUA_NOREF, -1 }
#endif // NVIM_EXTMARK_DEFS_H

View File

@ -862,7 +862,7 @@ void foldUpdateAfterInsert(void)
void foldUpdateAll(win_T *win)
{
win->w_foldinvalid = true;
redraw_win_later(win, NOT_VALID);
redraw_later(win, NOT_VALID);
}
// foldMoveTo() {{{2

View File

@ -92,6 +92,10 @@ EXTERN struct nvim_stats_s {
EXTERN int Rows INIT(= DFLT_ROWS); // nr of rows in the screen
EXTERN int Columns INIT(= DFLT_COLS); // nr of columns in the screen
EXTERN NS ns_hl_active INIT(= 0); // current ns that defines highlights
EXTERN bool ns_hl_changed INIT(= false); // highlight need update
// We use 64-bit file functions here, if available. E.g. ftello() returns
// off_t instead of long, which helps if long is 32 bit and off_t is 64 bit.
// We assume that when fseeko() is available then ftello() is too.

View File

@ -14,6 +14,7 @@
#include "nvim/ui.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/lua/executor.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "highlight.c.generated.h"
@ -28,12 +29,16 @@ static Map(int, int) *combine_attr_entries;
static Map(int, int) *blend_attr_entries;
static Map(int, int) *blendthrough_attr_entries;
/// highlight entries private to a namespace
static Map(ColorKey, ColorItem) *ns_hl;
void highlight_init(void)
{
attr_entry_ids = map_new(HlEntry, int)();
combine_attr_entries = map_new(int, int)();
blend_attr_entries = map_new(int, int)();
blendthrough_attr_entries = map_new(int, int)();
ns_hl = map_new(ColorKey, ColorItem)();
// index 0 is no attribute, add dummy entry:
kv_push(attr_entries, ((HlEntry){ .attr = HLATTRS_INIT, .kind = kHlUnknown,
@ -129,21 +134,114 @@ void ui_send_all_hls(UI *ui)
}
/// Get attribute code for a syntax group.
int hl_get_syn_attr(int idx, HlAttrs at_en)
int hl_get_syn_attr(int ns_id, 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) {
|| at_en.rgb_ae_attr != 0 || ns_id != 0) {
return get_attr_entry((HlEntry){ .attr = at_en, .kind = kHlSyntax,
.id1 = idx, .id2 = 0 });
.id1 = idx, .id2 = ns_id });
} else {
// If all the fields are cleared, clear the attr field back to default value
return 0;
}
}
static ColorKey colored_key(NS ns_id, int syn_id)
{
return (ColorKey){ .ns_id = (int)ns_id, .syn_id = syn_id };
}
void ns_hl_def(NS ns_id, int hl_id, HlAttrs attrs, int link_id)
{
DecorationProvider *p = get_provider(ns_id, true);
int attr_id = link_id > 0 ? -1 : hl_get_syn_attr(ns_id, hl_id, attrs);
ColorItem it = { .attr_id = attr_id,
.link_id = link_id,
.version = p->hl_valid };
map_put(ColorKey, ColorItem)(ns_hl, colored_key(ns_id, hl_id), it);
}
int ns_get_hl(NS ns_id, int hl_id, bool link)
{
static int recursive = 0;
if (ns_id < 0) {
if (ns_hl_active <= 0) {
return -1;
}
ns_id = ns_hl_active;
}
DecorationProvider *p = get_provider(ns_id, true);
ColorItem it = map_get(ColorKey, ColorItem)(ns_hl, colored_key(ns_id, hl_id));
// TODO(bfredl): map_ref true even this?
bool valid_cache = it.version >= p->hl_valid;
if (!valid_cache && p->hl_def != LUA_NOREF && !recursive) {
FIXED_TEMP_ARRAY(args, 3);
args.items[0] = INTEGER_OBJ((Integer)ns_id);
args.items[1] = STRING_OBJ(cstr_to_string((char *)syn_id2name(hl_id)));
args.items[2] = BOOLEAN_OBJ(link);
// TODO(bfredl): preload the "global" attr dict?
Error err = ERROR_INIT;
recursive++;
Object ret = nlua_call_ref(p->hl_def, "hl_def", args, true, &err);
recursive--;
// TODO(bfredl): or "inherit", combine with global value?
bool fallback = true;
int tmp = false;
HlAttrs attrs = HLATTRS_INIT;
if (ret.type == kObjectTypeDictionary) {
Dictionary dict = ret.data.dictionary;
fallback = false;
attrs = dict2hlattrs(dict, true, &it.link_id, &err);
for (size_t i = 0; i < dict.size; i++) {
char *key = dict.items[i].key.data;
Object val = dict.items[i].value;
bool truthy = api_object_to_bool(val, key, false, &err);
if (strequal(key, "fallback")) {
fallback = truthy;
} else if (strequal(key, "temp")) {
tmp = truthy;
}
}
if (it.link_id >= 0) {
fallback = true;
}
}
it.attr_id = fallback ? -1 : hl_get_syn_attr((int)ns_id, hl_id, attrs);
it.version = p->hl_valid-tmp;
map_put(ColorKey, ColorItem)(ns_hl, colored_key(ns_id, hl_id), it);
}
if (link) {
return it.attr_id >= 0 ? -1 : it.link_id;
} else {
return it.attr_id;
}
}
bool win_check_ns_hl(win_T *wp)
{
if (ns_hl_changed) {
highlight_changed();
if (wp) {
update_window_hl(wp, true);
}
ns_hl_changed = false;
return true;
}
return false;
}
/// Get attribute code for a builtin highlight group.
///
/// The final syntax group could be modified by hi-link or 'winhighlight'.
@ -204,6 +302,17 @@ void update_window_hl(win_T *wp, bool invalid)
wp->w_hl_attr_normal = float_win ? HL_ATTR(HLF_NFLOAT) : 0;
}
// NOOOO! You cannot just pretend that "Normal" is just like any other
// syntax group! It needs at least 10 layers of special casing! Noooooo!
//
// haha, theme engine go brrr
int normality = syn_check_group((const char_u *)S_LEN("Normal"));
int ns_attr = ns_get_hl(-1, normality, false);
if (ns_attr > 0) {
// TODO(bfredl): hantera NormalNC and so on
wp->w_hl_attr_normal = ns_attr;
}
// if blend= attribute is not set, 'winblend' value overrides it.
if (wp->w_floating && wp->w_p_winbl > 0) {
HlEntry entry = kv_A(attr_entries, wp->w_hl_attr_normal);
@ -275,6 +384,7 @@ void clear_hl_tables(bool reinit)
map_free(int, int)(combine_attr_entries);
map_free(int, int)(blend_attr_entries);
map_free(int, int)(blendthrough_attr_entries);
map_free(ColorKey, ColorItem)(ns_hl);
}
}
@ -663,6 +773,103 @@ Dictionary hlattrs2dict(HlAttrs ae, bool use_rgb)
return hl;
}
HlAttrs dict2hlattrs(Dictionary dict, bool use_rgb, int *link_id, Error *err)
{
HlAttrs hlattrs = HLATTRS_INIT;
int32_t fg = -1, bg = -1, sp = -1;
int16_t mask = 0;
for (size_t i = 0; i < dict.size; i++) {
char *key = dict.items[i].key.data;
Object val = dict.items[i].value;
struct {
const char *name;
int16_t flag;
} flags[] = {
{ "bold", HL_BOLD },
{ "standout", HL_STANDOUT },
{ "underline", HL_UNDERLINE },
{ "undercurl", HL_UNDERCURL },
{ "italic", HL_ITALIC },
{ "reverse", HL_INVERSE },
{ NULL, 0 },
};
int j;
for (j = 0; flags[j].name; j++) {
if (strequal(flags[j].name, key)) {
if (api_object_to_bool(val, key, false, err)) {
mask = mask | flags[j].flag;
}
break;
}
}
struct {
const char *name;
const char *shortname;
int *dest;
} colors[] = {
{ "foreground", "fg", &fg },
{ "background", "bg", &bg },
{ "special", "sp", &sp },
{ NULL, NULL, NULL },
};
int k;
for (k = 0; (!flags[j].name) && colors[k].name; k++) {
if (strequal(colors[k].name, key) || strequal(colors[k].shortname, key)) {
if (val.type == kObjectTypeInteger) {
*colors[k].dest = (int)val.data.integer;
} else if (val.type == kObjectTypeString) {
String str = val.data.string;
// TODO(bfredl): be more fancy with "bg", "fg" etc
if (str.size) {
*colors[k].dest = name_to_color(str.data);
}
} else {
api_set_error(err, kErrorTypeValidation,
"'%s' must be string or integer", key);
}
break;
}
}
if (flags[j].name || colors[k].name) {
// handled above
} else if (link_id && strequal(key, "link")) {
if (val.type == kObjectTypeString) {
String str = val.data.string;
*link_id = syn_check_group((const char_u *)str.data, (int)str.size);
} else if (val.type == kObjectTypeInteger) {
// TODO(bfredl): validate range?
*link_id = (int)val.data.integer;
} else {
api_set_error(err, kErrorTypeValidation,
"'link' must be string or integer");
}
}
if (ERROR_SET(err)) {
return hlattrs; // error set, caller should not use retval
}
}
if (use_rgb) {
hlattrs.rgb_ae_attr = mask;
hlattrs.rgb_bg_color = bg;
hlattrs.rgb_fg_color = fg;
hlattrs.rgb_sp_color = sp;
} else {
hlattrs.cterm_ae_attr = mask;
hlattrs.cterm_bg_color = bg == -1 ? cterm_normal_bg_color : bg + 1;
hlattrs.cterm_fg_color = fg == -1 ? cterm_normal_fg_color : fg + 1;
}
return hlattrs;
}
Array hl_inspect(int attr)
{
Array ret = ARRAY_DICT_INIT;

View File

@ -4,6 +4,7 @@
#include <inttypes.h>
#include "nvim/macros.h"
#include "nvim/types.h"
typedef int32_t RgbValue;
@ -180,6 +181,20 @@ typedef struct {
HlKind kind;
int id1;
int id2;
int winid;
} HlEntry;
typedef struct {
int ns_id;
int syn_id;
} ColorKey;
typedef struct {
int attr_id;
int link_id;
int version;
} ColorItem;
#define COLOR_ITEM_INITIALIZER { .attr_id = -1, .link_id = -1, .version = -1 }
#endif // NVIM_HIGHLIGHT_DEFS_H

View File

@ -891,6 +891,17 @@ LuaRef nlua_newref(lua_State *lstate, LuaRef original_ref)
return new_ref;
}
LuaRef api_new_luaref(LuaRef original_ref)
{
if (original_ref == LUA_NOREF) {
return LUA_NOREF;
}
lua_State *const lstate = nlua_enter();
return nlua_newref(lstate, original_ref);
}
/// Evaluate lua string
///
/// Used for luaeval().

View File

@ -446,7 +446,7 @@ int main(int argc, char **argv)
if (exmode_active || use_remote_ui || use_builtin_ui) {
// Don't clear the screen when starting in Ex mode, or when a UI might have
// displayed messages.
redraw_later(VALID);
redraw_later(curwin, VALID);
} else {
screenclear(); // clear screen
TIME_MSG("clearing screen");

View File

@ -12,6 +12,9 @@
#include <stdbool.h>
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include "nvim/map.h"
#include "nvim/map_defs.h"
#include "nvim/vim.h"
@ -173,6 +176,20 @@ static inline bool HlEntry_eq(HlEntry ae1, HlEntry ae2)
return memcmp(&ae1, &ae2, sizeof(ae1)) == 0;
}
static inline khint_t ColorKey_hash(ColorKey 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 ColorKey_eq(ColorKey ae1, ColorKey ae2)
{
return memcmp(&ae1, &ae2, sizeof(ae1)) == 0;
}
MAP_IMPL(int, int, DEFAULT_INITIALIZER)
@ -191,6 +208,7 @@ MAP_IMPL(String, MsgpackRpcRequestHandler, MSGPACK_HANDLER_INITIALIZER)
MAP_IMPL(HlEntry, int, DEFAULT_INITIALIZER)
MAP_IMPL(String, handle_T, 0)
MAP_IMPL(ColorKey, ColorItem, COLOR_ITEM_INITIALIZER)
/// Deletes a key:value pair from a string:pointer map, and frees the
/// storage of both key and value.

View File

@ -55,6 +55,8 @@ MAP_DECLS(String, MsgpackRpcRequestHandler)
MAP_DECLS(HlEntry, int)
MAP_DECLS(String, handle_T)
MAP_DECLS(ColorKey, ColorItem)
#define map_new(T, U) map_##T##_##U##_new
#define map_free(T, U) map_##T##_##U##_free
#define map_get(T, U) map_##T##_##U##_get

View File

@ -193,7 +193,7 @@ ex_menu(exarg_T *eap)
vimmenu_T **root_menu_ptr = get_root_menu(menu_path);
if (root_menu_ptr == &curwin->w_winbar) {
// Assume the window toolbar menu will change.
redraw_later(NOT_VALID);
redraw_later(curwin, NOT_VALID);
}
if (enable != kNone) {

View File

@ -1216,7 +1216,7 @@ void wait_return(int redraw)
ui_refresh();
} else if (!skip_redraw) {
if (redraw == true || (msg_scrolled != 0 && redraw != -1)) {
redraw_later(VALID);
redraw_later(curwin, VALID);
}
if (ui_has(kUIMessages)) {
msg_ext_clear(true);
@ -2222,7 +2222,7 @@ void msg_scroll_up(bool may_throttle)
///
/// Probably message scrollback storage should reimplented as a file_buffer, and
/// message scrolling in TUI be reimplemented as a modal floating window. Then
/// we get throttling "for free" using standard redraw_win_later code paths.
/// we get throttling "for free" using standard redraw_later code paths.
void msg_scroll_flush(void)
{
if (msg_grid.throttled) {

View File

@ -286,7 +286,7 @@ retnomove:
check_topfill(curwin, false);
curwin->w_valid &=
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
redraw_later(VALID);
redraw_later(curwin, VALID);
row = 0;
} else if (row >= curwin->w_height_inner) {
count = 0;
@ -316,7 +316,7 @@ retnomove:
}
}
check_topfill(curwin, false);
redraw_later(VALID);
redraw_later(curwin, VALID);
curwin->w_valid &=
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
row = curwin->w_height_inner - 1;

View File

@ -107,7 +107,7 @@ void redraw_for_cursorline(win_T *wp)
&& !pum_visible()) {
if (wp->w_p_rnu) {
// win_line() will redraw the number column only.
redraw_win_later(wp, VALID);
redraw_later(wp, VALID);
}
if (win_cursorline_standout(wp)) {
if (wp->w_redr_type <= VALID && wp->w_last_cursorline != 0) {
@ -117,7 +117,7 @@ void redraw_for_cursorline(win_T *wp)
redrawWinline(wp, wp->w_last_cursorline);
redrawWinline(wp, wp->w_cursor.lnum);
} else {
redraw_win_later(wp, SOME_VALID);
redraw_later(wp, SOME_VALID);
}
}
}
@ -172,7 +172,7 @@ void update_topline(void)
// If the buffer is empty, always set topline to 1.
if (BUFEMPTY()) { // special case - file is empty
if (curwin->w_topline != 1) {
redraw_later(NOT_VALID);
redraw_later(curwin, NOT_VALID);
}
curwin->w_topline = 1;
curwin->w_botline = 2;
@ -326,12 +326,14 @@ void update_topline(void)
dollar_vcol = -1;
if (curwin->w_skipcol != 0) {
curwin->w_skipcol = 0;
redraw_later(NOT_VALID);
} else
redraw_later(VALID);
/* May need to set w_skipcol when cursor in w_topline. */
if (curwin->w_cursor.lnum == curwin->w_topline)
redraw_later(curwin, NOT_VALID);
} else {
redraw_later(curwin, VALID);
}
// May need to set w_skipcol when cursor in w_topline.
if (curwin->w_cursor.lnum == curwin->w_topline) {
validate_cursor();
}
}
*so_ptr = save_so;
@ -439,7 +441,7 @@ void changed_window_setting_win(win_T *wp)
wp->w_lines_valid = 0;
changed_line_abv_curs_win(wp);
wp->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP|VALID_TOPLINE);
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
}
/*
@ -455,8 +457,8 @@ void set_topline(win_T *wp, linenr_T lnum)
wp->w_topline_was_set = true;
wp->w_topfill = 0;
wp->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_TOPLINE);
/* Don't set VALID_TOPLINE here, 'scrolloff' needs to be checked. */
redraw_later(VALID);
// Don't set VALID_TOPLINE here, 'scrolloff' needs to be checked.
redraw_later(wp, VALID);
}
/*
@ -634,7 +636,7 @@ void validate_virtcol_win(win_T *wp)
if (wp->w_p_cuc
&& !pum_visible()
)
redraw_win_later(wp, SOME_VALID);
redraw_later(wp, SOME_VALID);
}
}
@ -830,7 +832,7 @@ void curs_columns(
curwin->w_leftcol = new_leftcol;
win_check_anchored_floats(curwin);
// screen has to be redrawn with new curwin->w_leftcol
redraw_later(NOT_VALID);
redraw_later(curwin, NOT_VALID);
}
}
curwin->w_wcol -= curwin->w_leftcol;
@ -934,13 +936,14 @@ void curs_columns(
} else {
curwin->w_skipcol = 0;
}
if (prev_skipcol != curwin->w_skipcol)
redraw_later(NOT_VALID);
if (prev_skipcol != curwin->w_skipcol) {
redraw_later(curwin, NOT_VALID);
}
/* Redraw when w_virtcol changes and 'cursorcolumn' is set */
if (curwin->w_p_cuc && (curwin->w_valid & VALID_VIRTCOL) == 0
&& !pum_visible()) {
redraw_later(SOME_VALID);
redraw_later(curwin, SOME_VALID);
}
// now w_leftcol is valid, avoid check_cursor_moved() thinking otherwise
@ -2013,7 +2016,7 @@ int onepage(Direction dir, long count)
}
}
redraw_later(VALID);
redraw_later(curwin, VALID);
return retval;
}
@ -2199,7 +2202,7 @@ void halfpage(bool flag, linenr_T Prenum)
check_topfill(curwin, !flag);
cursor_correct();
beginline(BL_SOL | BL_FIX);
redraw_later(VALID);
redraw_later(curwin, VALID);
}
void do_check_cursorbind(void)
@ -2247,7 +2250,7 @@ void do_check_cursorbind(void)
}
// Correct cursor for multi-byte character.
mb_adjust_cursor();
redraw_later(VALID);
redraw_later(curwin, VALID);
// Only scroll when 'scrollbind' hasn't done this.
if (!curwin->w_p_scb) {

View File

@ -3601,7 +3601,7 @@ void check_scrollbind(linenr_T topline_diff, long leftcol_diff)
scrolldown(-y, false);
}
redraw_later(VALID);
redraw_later(curwin, VALID);
cursor_correct();
curwin->w_redr_status = true;
}
@ -4143,7 +4143,7 @@ void scroll_redraw(int up, long count)
if (curwin->w_cursor.lnum != prev_lnum)
coladvance(curwin->w_curswant);
curwin->w_viewport_invalid = true;
redraw_later(VALID);
redraw_later(curwin, VALID);
}
/*
@ -4241,7 +4241,7 @@ dozet:
FALLTHROUGH;
case 't': scroll_cursor_top(0, true);
redraw_later(VALID);
redraw_later(curwin, VALID);
set_fraction(curwin);
break;
@ -4250,7 +4250,7 @@ dozet:
FALLTHROUGH;
case 'z': scroll_cursor_halfway(true);
redraw_later(VALID);
redraw_later(curwin, VALID);
set_fraction(curwin);
break;
@ -4271,7 +4271,7 @@ dozet:
FALLTHROUGH;
case 'b': scroll_cursor_bot(0, true);
redraw_later(VALID);
redraw_later(curwin, VALID);
set_fraction(curwin);
break;
@ -4318,7 +4318,7 @@ dozet:
col = 0;
if (curwin->w_leftcol != col) {
curwin->w_leftcol = col;
redraw_later(NOT_VALID);
redraw_later(curwin, NOT_VALID);
}
}
break;
@ -4337,7 +4337,7 @@ dozet:
}
if (curwin->w_leftcol != col) {
curwin->w_leftcol = col;
redraw_later(NOT_VALID);
redraw_later(curwin, NOT_VALID);
}
}
break;
@ -4690,7 +4690,7 @@ static void nv_clear(cmdarg_T *cap)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
wp->w_s->b_syn_slow = false;
}
redraw_later(CLEAR);
redraw_later(curwin, CLEAR);
}
}

View File

@ -2652,7 +2652,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
xfree(reg->y_array);
}
if (curwin->w_p_rnu) {
redraw_later(SOME_VALID); // cursor moved to start
redraw_later(curwin, SOME_VALID); // cursor moved to start
}
if (message) { // Display message about yank?
if (yank_type == kMTCharWise && yanklines == 1) {

View File

@ -3121,7 +3121,7 @@ ambw_end:
} else {
if (curwin->w_status_height) {
curwin->w_redr_status = true;
redraw_later(VALID);
redraw_later(curwin, VALID);
}
curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
redraw_titles();
@ -4702,7 +4702,7 @@ static void check_redraw(uint32_t flags)
redraw_curbuf_later(NOT_VALID);
}
if (flags & P_RWINONLY) {
redraw_later(NOT_VALID);
redraw_later(curwin, NOT_VALID);
}
if (doclear) {
redraw_all_later(CLEAR);
@ -5716,12 +5716,12 @@ void unset_global_local_option(char *name, void *from)
case PV_LCS:
clear_string_option(&((win_T *)from)->w_p_lcs);
set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs, true);
redraw_win_later((win_T *)from, NOT_VALID);
redraw_later((win_T *)from, NOT_VALID);
break;
case PV_FCS:
clear_string_option(&((win_T *)from)->w_p_fcs);
set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs, true);
redraw_win_later((win_T *)from, NOT_VALID);
redraw_later((win_T *)from, NOT_VALID);
break;
}
}

View File

@ -786,7 +786,7 @@ static int pum_set_selected(int n, int repeat)
// Return cursor to where we were
validate_cursor();
redraw_later(SOME_VALID);
redraw_later(curwin, SOME_VALID);
// When the preview window was resized we need to
// update the view on the buffer. Only go back to

View File

@ -3707,7 +3707,7 @@ static void qf_win_goto(win_T *win, linenr_T lnum)
curwin->w_cursor.coladd = 0;
curwin->w_curswant = 0;
update_topline(); // scroll to show the line
redraw_later(VALID);
redraw_later(curwin, VALID);
curwin->w_redr_status = true; // update ruler
curwin = old_curwin;
curbuf = curwin->w_buffer;

View File

@ -25,7 +25,7 @@
//
// Commands that scroll a window change w_topline and must call
// check_cursor() to move the cursor into the visible part of the window, and
// call redraw_later(VALID) to have the window displayed by update_screen()
// call redraw_later(wp, VALID) to have the window displayed by update_screen()
// later.
//
// Commands that change text in the buffer must call changed_bytes() or
@ -37,7 +37,7 @@
//
// Commands that change how a window is displayed (e.g., setting 'list') or
// invalidate the contents of a window in another way (e.g., change fold
// settings), must call redraw_later(NOT_VALID) to have the whole window
// settings), must call redraw_later(wp, NOT_VALID) to have the whole window
// redisplayed by update_screen() later.
//
// Commands that change how a buffer is displayed (e.g., setting 'tabstop')
@ -45,11 +45,11 @@
// buffer redisplayed by update_screen() later.
//
// Commands that change highlighting and possibly cause a scroll too must call
// redraw_later(SOME_VALID) to update the whole window but still use scrolling
// to avoid redrawing everything. But the length of displayed lines must not
// change, use NOT_VALID then.
// redraw_later(wp, SOME_VALID) to update the whole window but still use
// scrolling to avoid redrawing everything. But the length of displayed lines
// must not change, use NOT_VALID then.
//
// Commands that move the window position must call redraw_later(NOT_VALID).
// Commands that move the window position must call redraw_later(wp, NOT_VALID).
// TODO(neovim): should minimize redrawing by scrolling when possible.
//
// Commands that change everything (e.g., resizing the screen) must call
@ -176,7 +176,7 @@ static bool provider_invoke(NS ns_id, const char *name, LuaRef ref,
textlock--;
if (!ERROR_SET(&err)
&& api_coerce_to_bool(ret, "provider %s retval", default_true, &err)) {
&& api_object_to_bool(ret, "provider %s retval", default_true, &err)) {
return true;
}
@ -195,17 +195,11 @@ static bool provider_invoke(NS ns_id, const char *name, LuaRef ref,
return false;
}
/*
* Redraw the current window later, with update_screen(type).
* Set must_redraw only if not already set to a higher value.
* e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing.
*/
void redraw_later(int type)
{
redraw_win_later(curwin, type);
}
void redraw_win_later(win_T *wp, int type)
/// Redraw a window later, with update_screen(type).
///
/// Set must_redraw only if not already set to a higher value.
/// e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing.
void redraw_later(win_T *wp, int type)
FUNC_ATTR_NONNULL_ALL
{
if (!exiting && wp->w_redr_type < type) {
@ -223,7 +217,7 @@ void redraw_win_later(win_T *wp, int type)
void redraw_all_later(int type)
{
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
redraw_win_later(wp, type);
redraw_later(wp, type);
}
// This may be needed when switching tabs.
if (must_redraw < type) {
@ -234,7 +228,7 @@ void redraw_all_later(int type)
void screen_invalidate_highlights(void)
{
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
wp->w_grid.valid = false;
}
}
@ -251,7 +245,7 @@ void redraw_buf_later(buf_T *buf, int type)
{
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_buffer == buf) {
redraw_win_later(wp, type);
redraw_later(wp, type);
}
}
}
@ -277,7 +271,7 @@ void redraw_buf_range_later(buf_T *buf, linenr_T firstline, linenr_T lastline)
if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lastline) {
wp->w_redraw_bot = lastline;
}
redraw_win_later(wp, VALID);
redraw_later(wp, VALID);
}
}
}
@ -305,7 +299,7 @@ redrawWinline(
if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) {
wp->w_redraw_bot = lnum;
}
redraw_win_later(wp, VALID);
redraw_later(wp, VALID);
}
}
@ -359,7 +353,6 @@ int update_screen(int type)
/* Postpone the redrawing when it's not needed and when being called
* recursively. */
if (!redrawing() || updating_screen) {
redraw_later(type); /* remember type for next time */
must_redraw = type;
if (type > INVERTED_ALL) {
curwin->w_lines_valid = 0; // don't use w_lines[].wl_size now
@ -501,6 +494,12 @@ int update_screen(int type)
}
}
// "start" callback could have changed highlights for global elements
if (win_check_ns_hl(NULL)) {
redraw_cmdline = true;
redraw_tabline = true;
}
if (clear_cmdline) /* going to clear cmdline (done below) */
check_for_delay(FALSE);
@ -1331,6 +1330,8 @@ static void win_update(win_T *wp, Providers *providers)
}
}
win_check_ns_hl(wp);
for (;; ) {
/* stop updating when reached the end of the window (check for _past_
@ -2185,6 +2186,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
// return 'false' or error: skip rest of this window
kv_A(*providers, k) = NULL;
}
win_check_ns_hl(wp);
}
}
@ -4649,8 +4652,8 @@ void status_redraw_all(void)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_status_height) {
wp->w_redr_status = TRUE;
redraw_later(VALID);
wp->w_redr_status = true;
redraw_later(wp, VALID);
}
}
}
@ -4667,7 +4670,7 @@ void status_redraw_buf(buf_T *buf)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_status_height != 0 && wp->w_buffer == buf) {
wp->w_redr_status = true;
redraw_later(VALID);
redraw_later(wp, VALID);
}
}
}

View File

@ -4923,7 +4923,7 @@ search_line:
&& curwin != curwin_save && win_valid(curwin_save)) {
/* Return cursor to where we were */
validate_cursor();
redraw_later(VALID);
redraw_later(curwin, VALID);
win_enter(curwin_save, true);
}
break;

View File

@ -2258,7 +2258,7 @@ char_u *did_set_spelllang(win_T *wp)
theend:
xfree(spl_copy);
recursive = false;
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
return ret_msg;
}
@ -6877,7 +6877,7 @@ void ex_spelldump(exarg_T *eap)
if (curbuf->b_ml.ml_line_count > 1) {
ml_delete(curbuf->b_ml.ml_line_count, false);
}
redraw_later(NOT_VALID);
redraw_later(curwin, NOT_VALID);
}
// Go through all possible words and:

View File

@ -73,9 +73,9 @@ struct hl_group {
RgbValue sg_rgb_fg; ///< RGB foreground color
RgbValue sg_rgb_bg; ///< RGB background color
RgbValue sg_rgb_sp; ///< RGB special color
uint8_t *sg_rgb_fg_name; ///< RGB foreground color name
uint8_t *sg_rgb_bg_name; ///< RGB background color name
uint8_t *sg_rgb_sp_name; ///< RGB special color name
char *sg_rgb_fg_name; ///< RGB foreground color name
char *sg_rgb_bg_name; ///< RGB background color name
char *sg_rgb_sp_name; ///< RGB special color name
int sg_blend; ///< blend level (0-100 inclusive), -1 if unset
};
@ -3147,7 +3147,7 @@ static void syn_cmd_spell(exarg_T *eap, int syncing)
}
// assume spell checking changed, force a redraw
redraw_win_later(curwin, NOT_VALID);
redraw_later(curwin, NOT_VALID);
}
/// Handle ":syntax iskeyword" command.
@ -3187,7 +3187,7 @@ static void syn_cmd_iskeyword(exarg_T *eap, int syncing)
curbuf->b_p_isk = save_isk;
}
}
redraw_win_later(curwin, NOT_VALID);
redraw_later(curwin, NOT_VALID);
}
/*
@ -6899,7 +6899,7 @@ void do_highlight(const char *line, const bool forceit, const bool init)
}
}
} else if (strcmp(key, "GUIFG") == 0) {
char_u **const namep = &HL_TABLE()[idx].sg_rgb_fg_name;
char **namep = &HL_TABLE()[idx].sg_rgb_fg_name;
if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) {
if (!init) {
@ -6909,8 +6909,8 @@ void do_highlight(const char *line, const bool forceit, const bool init)
if (*namep == NULL || STRCMP(*namep, arg) != 0) {
xfree(*namep);
if (strcmp(arg, "NONE") != 0) {
*namep = (char_u *)xstrdup(arg);
HL_TABLE()[idx].sg_rgb_fg = name_to_color((char_u *)arg);
*namep = xstrdup(arg);
HL_TABLE()[idx].sg_rgb_fg = name_to_color(arg);
} else {
*namep = NULL;
HL_TABLE()[idx].sg_rgb_fg = -1;
@ -6923,7 +6923,7 @@ void do_highlight(const char *line, const bool forceit, const bool init)
normal_fg = HL_TABLE()[idx].sg_rgb_fg;
}
} else if (STRCMP(key, "GUIBG") == 0) {
char_u **const namep = &HL_TABLE()[idx].sg_rgb_bg_name;
char **const namep = &HL_TABLE()[idx].sg_rgb_bg_name;
if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) {
if (!init) {
@ -6933,8 +6933,8 @@ void do_highlight(const char *line, const bool forceit, const bool init)
if (*namep == NULL || STRCMP(*namep, arg) != 0) {
xfree(*namep);
if (STRCMP(arg, "NONE") != 0) {
*namep = (char_u *)xstrdup(arg);
HL_TABLE()[idx].sg_rgb_bg = name_to_color((char_u *)arg);
*namep = xstrdup(arg);
HL_TABLE()[idx].sg_rgb_bg = name_to_color(arg);
} else {
*namep = NULL;
HL_TABLE()[idx].sg_rgb_bg = -1;
@ -6947,7 +6947,7 @@ void do_highlight(const char *line, const bool forceit, const bool init)
normal_bg = HL_TABLE()[idx].sg_rgb_bg;
}
} else if (strcmp(key, "GUISP") == 0) {
char_u **const namep = &HL_TABLE()[idx].sg_rgb_sp_name;
char **const namep = &HL_TABLE()[idx].sg_rgb_sp_name;
if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) {
if (!init) {
@ -6957,8 +6957,8 @@ void do_highlight(const char *line, const bool forceit, const bool init)
if (*namep == NULL || STRCMP(*namep, arg) != 0) {
xfree(*namep);
if (strcmp(arg, "NONE") != 0) {
*namep = (char_u *)xstrdup(arg);
HL_TABLE()[idx].sg_rgb_sp = name_to_color((char_u *)arg);
*namep = xstrdup(arg);
HL_TABLE()[idx].sg_rgb_sp = name_to_color(arg);
} else {
*namep = NULL;
HL_TABLE()[idx].sg_rgb_sp = -1;
@ -7152,13 +7152,32 @@ static void highlight_list_one(const int id)
msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name);
}
if (!didh)
highlight_list_arg(id, didh, LIST_STRING, 0, (char_u *)"cleared", "");
if (!didh) {
highlight_list_arg(id, didh, LIST_STRING, 0, "cleared", "");
}
if (p_verbose > 0) {
last_set_msg(sgp->sg_script_ctx);
}
}
Dictionary get_global_hl_defs(void)
{
Dictionary rv = ARRAY_DICT_INIT;
for (int i = 1; i <= highlight_ga.ga_len && !got_int; i++) {
Dictionary attrs = ARRAY_DICT_INIT;
struct hl_group *h = &HL_TABLE()[i - 1];
if (h->sg_attr > 0) {
attrs = hlattrs2dict(syn_attr2entry(h->sg_attr), true);
} else if (h->sg_link > 0) {
const char *link = (const char *)HL_TABLE()[h->sg_link - 1].sg_name;
PUT(attrs, "link", STRING_OBJ(cstr_to_string(link)));
}
PUT(rv, (const char *)h->sg_name, DICTIONARY_OBJ(attrs));
}
return rv;
}
/// Outputs a highlight when doing ":hi MyHighlight"
///
/// @param type one of \ref LIST_XXX
@ -7166,15 +7185,15 @@ static void highlight_list_one(const int id)
/// @param sarg string used if \p type == LIST_STRING
static bool highlight_list_arg(
const int id, bool didh, const int type, int iarg,
char_u *const sarg, const char *const name)
char *const sarg, const char *const name)
{
char_u buf[100];
char buf[100];
if (got_int) {
return false;
}
if (type == LIST_STRING ? (sarg != NULL) : (iarg != 0)) {
char_u *ts = buf;
char *ts = buf;
if (type == LIST_INT) {
snprintf((char *)buf, sizeof(buf), "%d", iarg - 1);
} else if (type == LIST_STRING) {
@ -7191,15 +7210,15 @@ static bool highlight_list_arg(
}
}
(void)syn_list_header(didh, (int)(vim_strsize(ts) + STRLEN(name) + 1), id,
false);
(void)syn_list_header(didh, (int)(vim_strsize((char_u *)ts) + STRLEN(name)
+ 1), id, false);
didh = true;
if (!got_int) {
if (*name != NUL) {
MSG_PUTS_ATTR(name, HL_ATTR(HLF_D));
MSG_PUTS_ATTR("=", HL_ATTR(HLF_D));
}
msg_outtrans(ts);
msg_outtrans((char_u *)ts);
}
}
return didh;
@ -7378,7 +7397,7 @@ static void set_hl_attr(int idx)
at_en.rgb_sp_color = sgp->sg_rgb_sp_name ? sgp->sg_rgb_sp : -1;
at_en.hl_blend = sgp->sg_blend;
sgp->sg_attr = hl_get_syn_attr(idx+1, at_en);
sgp->sg_attr = hl_get_syn_attr(0, idx+1, at_en);
// a cursor style uses this syn_id, make sure its attribute is updated.
if (cursor_mode_uses_syn_id(idx+1)) {
@ -7541,11 +7560,17 @@ int syn_id2attr(int hl_id)
struct hl_group *sgp;
hl_id = syn_get_final_id(hl_id);
sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */
int attr = ns_get_hl(-1, hl_id, false);
if (attr >= 0) {
return attr;
}
sgp = &HL_TABLE()[hl_id - 1]; // index is ID minus one
return sgp->sg_attr;
}
/*
* Translate a group ID to the final group ID (following links).
*/
@ -7562,9 +7587,22 @@ int syn_get_final_id(int hl_id)
* Look out for loops! Break after 100 links.
*/
for (count = 100; --count >= 0; ) {
sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */
if (sgp->sg_link == 0 || sgp->sg_link > highlight_ga.ga_len)
// ACHTUNG: when using "tmp" attribute (no link) the function might be
// called twice. it needs be smart enough to remember attr only to
// syn_id2attr time
int check = ns_get_hl(-1, hl_id, true);
if (check == 0) {
return 0; // how dare! it broke the link!
} else if (check > 0) {
hl_id = check;
continue;
}
sgp = &HL_TABLE()[hl_id - 1]; // index is ID minus one
if (sgp->sg_link == 0 || sgp->sg_link > highlight_ga.ga_len) {
break;
}
hl_id = sgp->sg_link;
}
@ -8494,7 +8532,7 @@ color_name_table_T color_name_table[] = {
///
/// @param[in] name string value to convert to RGB
/// return the hex value or -1 if could not find a correct value
RgbValue name_to_color(const char_u *name)
RgbValue name_to_color(const char *name)
{
if (name[0] == '#' && isxdigit(name[1]) && isxdigit(name[2])

View File

@ -2903,7 +2903,7 @@ static int jumpto_tag(
&& curwin != curwin_save && win_valid(curwin_save)) {
/* Return cursor to where we were */
validate_cursor();
redraw_later(VALID);
redraw_later(curwin, VALID);
win_enter(curwin_save, true);
}

View File

@ -233,7 +233,7 @@ Terminal *terminal_open(TerminalOptions opts)
snprintf(var, sizeof(var), "terminal_color_%d", i);
char *name = get_config_string(var);
if (name) {
color_val = name_to_color((uint8_t *)name);
color_val = name_to_color(name);
xfree(name);
if (color_val != -1) {
@ -1060,7 +1060,7 @@ static bool send_mouse_event(Terminal *term, int c)
curwin->w_redr_status = true;
curwin = save_curwin;
curbuf = curwin->w_buffer;
redraw_win_later(mouse_win, NOT_VALID);
redraw_later(mouse_win, NOT_VALID);
invalidate_terminal(term, -1, -1);
// Only need to exit focus if the scrolled window is the terminal window
return mouse_win == curwin;

View File

@ -21,7 +21,7 @@ typedef int handle_T;
// absent callback etc.
typedef int LuaRef;
typedef uint64_t NS;
typedef handle_T NS;
typedef struct expand expand_T;

View File

@ -26,6 +26,7 @@
#include "nvim/screen.h"
#include "nvim/syntax.h"
#include "nvim/api/private/helpers.h"
#include "nvim/lua/executor.h"
#include "nvim/os/os.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS

View File

@ -2455,7 +2455,7 @@ static void u_undo_end(
{
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_buffer == curbuf && wp->w_p_cole > 0) {
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
}
}
}

View File

@ -606,7 +606,7 @@ win_T *win_new_float(win_T *wp, FloatConfig fconfig, Error *err)
win_config_float(wp, fconfig);
wp->w_pos_changed = true;
redraw_win_later(wp, VALID);
redraw_later(wp, VALID);
return wp;
}
@ -679,7 +679,7 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
wp->w_pos_changed = true;
if (change_external) {
wp->w_hl_needs_update = true;
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
}
}
@ -764,7 +764,7 @@ static void ui_ext_win_position(win_T *wp)
wp->w_grid.focusable = wp->w_float_config.focusable;
if (!valid) {
wp->w_grid.valid = false;
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
}
}
} else {
@ -1492,8 +1492,8 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
// Both windows need redrawing. Update all status lines, in case they
// show something related to the window count or position.
redraw_win_later(wp, NOT_VALID);
redraw_win_later(oldwin, NOT_VALID);
redraw_later(wp, NOT_VALID);
redraw_later(oldwin, NOT_VALID);
status_redraw_all();
if (need_status) {
@ -1823,8 +1823,8 @@ static void win_exchange(long Prenum)
(void)win_comp_pos(); /* recompute window positions */
win_enter(wp, true);
redraw_later(NOT_VALID);
redraw_win_later(wp, NOT_VALID);
redraw_later(curwin, NOT_VALID);
redraw_later(wp, NOT_VALID);
}
// rotate windows: if upwards true the second window becomes the first one
@ -1996,8 +1996,8 @@ void win_move_after(win_T *win1, win_T *win2)
win_append(win2, win1);
frame_append(win2->w_frame, win1->w_frame);
(void)win_comp_pos(); /* recompute w_winrow for all windows */
redraw_later(NOT_VALID);
(void)win_comp_pos(); // recompute w_winrow for all windows
redraw_later(curwin, NOT_VALID);
}
win_enter(win1, false);
@ -3635,7 +3635,7 @@ void curwin_init(void)
void win_init_empty(win_T *wp)
{
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
wp->w_lines_valid = 0;
wp->w_cursor.lnum = 1;
wp->w_curswant = wp->w_cursor.col = 0;
@ -4587,10 +4587,11 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid,
}
maketitle();
curwin->w_redr_status = TRUE;
redraw_tabline = TRUE;
if (restart_edit)
redraw_later(VALID); /* causes status line redraw */
curwin->w_redr_status = true;
redraw_tabline = true;
if (restart_edit) {
redraw_later(curwin, VALID); // causes status line redraw
}
if (HL_ATTR(HLF_INACTIVE)
|| (prevwin && prevwin->w_hl_ids[HLF_INACTIVE])
@ -5056,7 +5057,7 @@ static void frame_comp_pos(frame_T *topfrp, int *row, int *col)
/* position changed, redraw */
wp->w_winrow = *row;
wp->w_wincol = *col;
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
wp->w_redr_status = true;
wp->w_pos_changed = true;
}
@ -5109,7 +5110,7 @@ void win_setheight_win(int height, win_T *win)
if (win->w_floating) {
win->w_float_config.height = height;
win_config_float(win, win->w_float_config);
redraw_win_later(win, NOT_VALID);
redraw_later(win, NOT_VALID);
} else {
frame_setheight(win->w_frame, height + win->w_status_height);
@ -5312,7 +5313,7 @@ void win_setwidth_win(int width, win_T *wp)
if (wp->w_floating) {
wp->w_float_config.width = width;
win_config_float(wp, wp->w_float_config);
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
} else {
frame_setwidth(wp->w_frame, width + wp->w_vsep_width);
@ -5845,8 +5846,8 @@ void scroll_to_fraction(win_T *wp, int prev_height)
}
win_comp_scroll(wp);
redraw_win_later(wp, SOME_VALID);
wp->w_redr_status = TRUE;
redraw_later(wp, SOME_VALID);
wp->w_redr_status = true;
invalidate_botline_win(wp);
}
@ -5885,7 +5886,7 @@ void win_set_inner_size(win_T *wp)
if (!exiting) {
scroll_to_fraction(wp, prev_height);
}
redraw_win_later(wp, NOT_VALID); // SOME_VALID??
redraw_later(wp, NOT_VALID); // SOME_VALID??
}
if (width != wp->w_width_inner) {
@ -5897,7 +5898,7 @@ void win_set_inner_size(win_T *wp)
update_topline();
curs_columns(true); // validate w_wrow
}
redraw_win_later(wp, NOT_VALID);
redraw_later(wp, NOT_VALID);
}
if (wp->w_buffer->terminal) {
@ -6741,7 +6742,7 @@ int match_add(win_T *wp, const char *const grp, const char *const pat,
prev->next = m;
m->next = cur;
redraw_win_later(wp, rtype);
redraw_later(wp, rtype);
return id;
fail:
@ -6799,7 +6800,7 @@ int match_delete(win_T *wp, int id, int perr)
rtype = VALID;
}
xfree(cur);
redraw_win_later(wp, rtype);
redraw_later(wp, rtype);
return 0;
}
@ -6817,7 +6818,7 @@ void clear_matches(win_T *wp)
xfree(wp->w_match_head);
wp->w_match_head = m;
}
redraw_win_later(wp, SOME_VALID);
redraw_later(wp, SOME_VALID);
}
/*

View File

@ -751,6 +751,14 @@ module.curbufmeths = module.create_callindex(module.curbuf)
module.curwinmeths = module.create_callindex(module.curwin)
module.curtabmeths = module.create_callindex(module.curtab)
function module.exec(code)
return module.meths.exec(code, false)
end
function module.exec_capture(code)
return module.meths.exec(code, true)
end
function module.exec_lua(code, ...)
return module.meths.exec_lua(code, {...})
end

View File

@ -5,20 +5,32 @@ local clear = helpers.clear
local feed = helpers.feed
local insert = helpers.insert
local exec_lua = helpers.exec_lua
local exec = helpers.exec
local expect_events = helpers.expect_events
local meths = helpers.meths
describe('decorations provider', function()
describe('decorations providers', function()
local screen
before_each(function()
clear()
screen = Screen.new(40, 8)
screen:attach()
screen:set_default_attr_ids({
[1] = {bold=true, foreground=Screen.colors.Blue},
})
screen:set_default_attr_ids {
[1] = {bold=true, foreground=Screen.colors.Blue};
[2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red};
[3] = {foreground = Screen.colors.Brown};
[4] = {foreground = Screen.colors.Blue1};
[5] = {foreground = Screen.colors.Magenta};
[6] = {bold = true, foreground = Screen.colors.Brown};
[7] = {background = Screen.colors.Gray90};
[8] = {bold = true, reverse = true};
[9] = {reverse = true};
[10] = {italic = true, background = Screen.colors.Magenta};
[11] = {foreground = Screen.colors.Red, background = tonumber('0x005028')};
}
end)
local mudholland = [[
local mulholland = [[
// just to see if there was an accident
// on Mulholland Drive
try_start();
@ -28,21 +40,21 @@ describe('decorations provider', function()
restore_buffer(&save_buf); ]]
local function setup_provider(code)
exec_lua ([[
return exec_lua ([[
local a = vim.api
test1 = a.nvim_create_namespace "test1"
_G.ns1 = a.nvim_create_namespace "ns1"
]] .. (code or [[
beamtrace = {}
function on_do(kind, ...)
local function on_do(kind, ...)
table.insert(beamtrace, {kind, ...})
end
]]) .. [[
a.nvim_set_decoration_provider(
test1, {
a.nvim_set_decoration_provider(_G.ns1, {
on_start = on_do; on_buf = on_do;
on_win = on_do; on_line = on_do;
on_end = on_do;
})
return _G.ns1
]])
end
@ -51,8 +63,8 @@ describe('decorations provider', function()
expect_events(expected, actual, "beam trace")
end
it('leaves a trace', function()
insert(mudholland)
it('leave a trace', function()
insert(mulholland)
setup_provider()
@ -99,11 +111,12 @@ describe('decorations provider', function()
}
end)
it('single provider', function()
insert(mudholland)
it('can have single provider', function()
insert(mulholland)
setup_provider [[
local hl = a.nvim_get_hl_id_by_name "ErrorMsg"
function do_it(event, ...)
local test_ns = a.nvim_create_namespace "mulholland"
function on_do(event, ...)
if event == "line" then
local win, buf, line = ...
a.nvim_buf_set_extmark(buf, test_ns, line, line,
@ -114,5 +127,104 @@ describe('decorations provider', function()
end
end
]]
screen:expect{grid=[[
{2:/}/ just to see if there was an accident |
/{2:/} on Mulholland Drive |
tr{2:y}_start(); |
buf{2:r}ef_T save_buf; |
swit{2:c}h_buffer(&save_buf, buf); |
posp {2:=} getmark(mark, false); |
restor{2:e}_buffer(&save_buf);^ |
|
]]}
end)
it('can predefine highlights', function()
screen:try_resize(40, 16)
insert(mulholland)
exec [[
3
set ft=c
syntax on
set number cursorline
split
]]
local ns1 = setup_provider()
for k,v in pairs {
LineNr = {italic=true, bg="Magenta"};
Comment = {fg="#FF0000", bg = 80*256+40};
CursorLine = {link="ErrorMsg"};
} do meths.set_hl(ns1, k, v) end
screen:expect{grid=[[
{3: 1 }{4:// just to see if there was an accid}|
{3: }{4:ent} |
{3: 2 }{4:// on Mulholland Drive} |
{6: 3 }{7:^try_start(); }|
{3: 4 }bufref_T save_buf; |
{3: 5 }switch_buffer(&save_buf, buf); |
{3: 6 }posp = getmark(mark, {5:false}); |
{8:[No Name] [+] }|
{3: 2 }{4:// on Mulholland Drive} |
{6: 3 }{7:try_start(); }|
{3: 4 }bufref_T save_buf; |
{3: 5 }switch_buffer(&save_buf, buf); |
{3: 6 }posp = getmark(mark, {5:false}); |
{3: 7 }restore_buffer(&save_buf); |
{9:[No Name] [+] }|
|
]]}
meths.set_hl_ns(ns1)
screen:expect{grid=[[
{10: 1 }{11:// just to see if there was an accid}|
{10: }{11:ent} |
{10: 2 }{11:// on Mulholland Drive} |
{6: 3 }{2:^try_start(); }|
{10: 4 }bufref_T save_buf; |
{10: 5 }switch_buffer(&save_buf, buf); |
{10: 6 }posp = getmark(mark, {5:false}); |
{8:[No Name] [+] }|
{10: 2 }{11:// on Mulholland Drive} |
{6: 3 }{2:try_start(); }|
{10: 4 }bufref_T save_buf; |
{10: 5 }switch_buffer(&save_buf, buf); |
{10: 6 }posp = getmark(mark, {5:false}); |
{10: 7 }restore_buffer(&save_buf); |
{9:[No Name] [+] }|
|
]]}
exec_lua [[
local a = vim.api
local thewin = a.nvim_get_current_win()
local ns2 = a.nvim_create_namespace 'ns2'
a.nvim_set_decoration_provider (ns2, {
on_win = function (_, win, buf)
a.nvim_set_hl_ns(win == thewin and _G.ns1 or ns2)
end;
})
]]
screen:expect{grid=[[
{10: 1 }{11:// just to see if there was an accid}|
{10: }{11:ent} |
{10: 2 }{11:// on Mulholland Drive} |
{6: 3 }{2:^try_start(); }|
{10: 4 }bufref_T save_buf; |
{10: 5 }switch_buffer(&save_buf, buf); |
{10: 6 }posp = getmark(mark, {5:false}); |
{8:[No Name] [+] }|
{3: 2 }{4:// on Mulholland Drive} |
{6: 3 }{7:try_start(); }|
{3: 4 }bufref_T save_buf; |
{3: 5 }switch_buffer(&save_buf, buf); |
{3: 6 }posp = getmark(mark, {5:false}); |
{3: 7 }restore_buffer(&save_buf); |
{9:[No Name] [+] }|
|
]]}
end)
end)

View File

@ -1289,7 +1289,7 @@ local function fmt_ext_state(name, state)
for k,v in pairs(state) do
str = (str.." ["..k.."] = {win = {id = "..v.win.id.."}, topline = "
..v.topline..", botline = "..v.botline..", curline = "..v.curline
..", curcol = "..v.curcol.."},\n")
..", curcol = "..v.curcol.."};\n")
end
return str .. "}"
else
@ -1316,7 +1316,7 @@ function Screen:print_snapshot(attrs, ignore)
dict = "{"..self:_pprint_attrs(a).."}"
end
local keyval = (type(i) == "number") and "["..tostring(i).."]" or i
table.insert(attrstrs, " "..keyval.." = "..dict..",")
table.insert(attrstrs, " "..keyval.." = "..dict..";")
end
attrstr = (", attr_ids={\n"..table.concat(attrstrs, "\n").."\n}")
end