fix(api): include event in get_autocmds (#17553)

This commit is contained in:
Christian Clason 2022-03-01 09:07:41 +01:00 committed by GitHub
parent 01139ec82c
commit 37a86a2f96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -197,6 +197,10 @@ Array nvim_get_autocmds(Dict(get_autocmds) *opts, Error *err)
"pattern", "pattern",
STRING_OBJ(cstr_to_string((char *)ap->pat))); STRING_OBJ(cstr_to_string((char *)ap->pat)));
PUT(autocmd_info,
"event",
STRING_OBJ(cstr_to_string((char *)event_nr2name(event))));
PUT(autocmd_info, "once", BOOLEAN_OBJ(ac->once)); PUT(autocmd_info, "once", BOOLEAN_OBJ(ac->once));
if (ap->buflocal_nr) { if (ap->buflocal_nr) {

View File

@ -598,7 +598,7 @@ event_T event_name2nr(const char_u *start, char_u **end)
/// @param[in] event Event to return name for. /// @param[in] event Event to return name for.
/// ///
/// @return Event name, static string. Returns "Unknown" for unknown events. /// @return Event name, static string. Returns "Unknown" for unknown events.
static const char *event_nr2name(event_T event) const char *event_nr2name(event_T event)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_CONST FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_CONST
{ {
int i; int i;

View File

@ -217,6 +217,14 @@ describe('autocmd api', function()
eq(1, #new_aus) eq(1, #new_aus)
eq(first, new_aus[1]) eq(first, new_aus[1])
end) end)
it('should return event name', function()
command [[au! InsertEnter]]
command [[au InsertEnter * :echo "1"]]
local aus = meths.get_autocmds { event = "InsertEnter" }
eq({ { buflocal = false, command = ':echo "1"', event = "InsertEnter", once = false, pattern = "*" } }, aus)
end)
end) end)
describe('groups', function() describe('groups', function()