mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
feat(api): remove Lua autocommand callbacks when they return true (#17784)
This copies the semantics of nvim_buf_attach callbacks, and is a convenient way to create oneshot autocommands gated by some condition.
This commit is contained in:
@@ -2013,6 +2013,7 @@ char_u *getnextac(int c, void *cookie, int indent, bool do_concat)
|
||||
}
|
||||
|
||||
AutoCmd *ac = acp->nextcmd;
|
||||
bool oneshot = ac->once;
|
||||
|
||||
if (p_verbose >= 9) {
|
||||
verbose_enter_scroll();
|
||||
@@ -2024,7 +2025,13 @@ char_u *getnextac(int c, void *cookie, int indent, bool do_concat)
|
||||
if (ac->exec.type == CALLABLE_CB) {
|
||||
typval_T argsin = TV_INITIAL_VALUE;
|
||||
typval_T rettv = TV_INITIAL_VALUE;
|
||||
callback_call(&ac->exec.callable.cb, 0, &argsin, &rettv);
|
||||
if (callback_call(&ac->exec.callable.cb, 0, &argsin, &rettv)) {
|
||||
if (ac->exec.callable.cb.type == kCallbackLua) {
|
||||
// If a Lua callback returns 'true' then the autocommand is removed
|
||||
oneshot = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO(tjdevries):
|
||||
//
|
||||
@@ -2042,7 +2049,7 @@ char_u *getnextac(int c, void *cookie, int indent, bool do_concat)
|
||||
}
|
||||
|
||||
// Remove one-shot ("once") autocmd in anticipation of its execution.
|
||||
if (ac->once) {
|
||||
if (oneshot) {
|
||||
aucmd_del(ac);
|
||||
}
|
||||
autocmd_nested = ac->nested;
|
||||
|
Reference in New Issue
Block a user