feat(autocmds): retrieve lua callback (#18642)

add a new `callback` field to `nvim_get_autocmds`
This commit is contained in:
kylo252
2022-06-09 15:18:56 +02:00
committed by GitHub
parent c5720c7221
commit 3da3cfc864
5 changed files with 112 additions and 38 deletions

View File

@@ -1205,6 +1205,30 @@ void callback_copy(Callback *dest, Callback *src)
}
}
/// Generate a string description of a callback
char *callback_to_string(Callback *cb)
{
size_t msglen = 100;
char *msg = (char *)xmallocz(msglen);
switch (cb->type) {
case kCallbackLua:
snprintf(msg, msglen, "<lua: %d>", cb->data.luaref);
break;
case kCallbackFuncref:
// TODO(tjdevries): Is this enough space for this?
snprintf(msg, msglen, "<vim function: %s>", cb->data.funcref);
break;
case kCallbackPartial:
snprintf(msg, msglen, "<vim partial: %s>", cb->data.partial->pt_name);
break;
default:
snprintf(msg, msglen, "%s", "");
break;
}
return msg;
}
/// Remove watcher from a dictionary
///
/// @param dict Dictionary to remove watcher from.