mirror of
https://github.com/neovim/neovim.git
synced 2025-09-11 22:08:18 +00:00
luahl: global the luahl
This commit is contained in:
@@ -244,78 +244,6 @@ Boolean nvim_buf_detach(uint64_t channel_id,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void buf_clear_luahl(buf_T *buf, bool force)
|
||||
{
|
||||
if (buf->b_luahl || force) {
|
||||
api_free_luaref(buf->b_luahl_start);
|
||||
api_free_luaref(buf->b_luahl_window);
|
||||
api_free_luaref(buf->b_luahl_line);
|
||||
api_free_luaref(buf->b_luahl_end);
|
||||
}
|
||||
buf->b_luahl_start = LUA_NOREF;
|
||||
buf->b_luahl_window = LUA_NOREF;
|
||||
buf->b_luahl_line = LUA_NOREF;
|
||||
buf->b_luahl_end = LUA_NOREF;
|
||||
}
|
||||
|
||||
/// Unstabilized interface for defining syntax hl in lua.
|
||||
///
|
||||
/// This is not yet safe for general use, lua callbacks will need to
|
||||
/// be restricted, like textlock and probably other stuff.
|
||||
///
|
||||
/// The API on_line/nvim__put_attr is quite raw and not intended to be the
|
||||
/// final shape. Ideally this should operate on chunks larger than a single
|
||||
/// line to reduce interpreter overhead, and generate annotation objects
|
||||
/// (bufhl/virttext) on the fly but using the same representation.
|
||||
void nvim__buf_set_luahl(uint64_t channel_id, Buffer buffer,
|
||||
DictionaryOf(LuaRef) opts, Error *err)
|
||||
FUNC_API_LUA_ONLY
|
||||
{
|
||||
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
|
||||
redraw_buf_later(buf, NOT_VALID);
|
||||
buf_clear_luahl(buf, false);
|
||||
|
||||
for (size_t i = 0; i < opts.size; i++) {
|
||||
String k = opts.items[i].key;
|
||||
Object *v = &opts.items[i].value;
|
||||
if (strequal("on_start", k.data)) {
|
||||
if (v->type != kObjectTypeLuaRef) {
|
||||
api_set_error(err, kErrorTypeValidation, "callback is not a function");
|
||||
goto error;
|
||||
}
|
||||
buf->b_luahl_start = v->data.luaref;
|
||||
v->data.luaref = LUA_NOREF;
|
||||
} else if (strequal("on_window", k.data)) {
|
||||
if (v->type != kObjectTypeLuaRef) {
|
||||
api_set_error(err, kErrorTypeValidation, "callback is not a function");
|
||||
goto error;
|
||||
}
|
||||
buf->b_luahl_window = v->data.luaref;
|
||||
v->data.luaref = LUA_NOREF;
|
||||
} else if (strequal("on_line", k.data)) {
|
||||
if (v->type != kObjectTypeLuaRef) {
|
||||
api_set_error(err, kErrorTypeValidation, "callback is not a function");
|
||||
goto error;
|
||||
}
|
||||
buf->b_luahl_line = v->data.luaref;
|
||||
v->data.luaref = LUA_NOREF;
|
||||
} else {
|
||||
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
buf->b_luahl = true;
|
||||
return;
|
||||
error:
|
||||
buf_clear_luahl(buf, true);
|
||||
buf->b_luahl = false;
|
||||
}
|
||||
|
||||
void nvim__buf_redraw_range(Buffer buffer, Integer first, Integer last,
|
||||
Error *err)
|
||||
FUNC_API_LUA_ONLY
|
||||
|
Reference in New Issue
Block a user