aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/executor.c
diff options
context:
space:
mode:
authorerrael <errael@raelity.com>2024-10-31 18:11:15 -0700
committerGitHub <noreply@github.com>2024-11-01 09:11:15 +0800
commitb34e137e43d359c8db4fb76028dea3b410842aff (patch)
tree3172f9aa1819934d35e9f6220f0676e135a3fbe7 /src/nvim/lua/executor.c
parent8585183ba2f27cb246b79c017149a878a543c82f (diff)
downloadrneovim-b34e137e43d359c8db4fb76028dea3b410842aff.tar.gz
rneovim-b34e137e43d359c8db4fb76028dea3b410842aff.tar.bz2
rneovim-b34e137e43d359c8db4fb76028dea3b410842aff.zip
feat(lua): allow vim.on_key() callback to consume the key (#30939)
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r--src/nvim/lua/executor.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 9392765f40..27ebfacc5f 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -2063,12 +2063,13 @@ char *nlua_register_table_as_callable(const typval_T *const arg)
return name;
}
-void nlua_execute_on_key(int c, char *typed_buf)
+/// @return true to discard the key
+bool nlua_execute_on_key(int c, char *typed_buf)
{
static bool recursive = false;
if (recursive) {
- return;
+ return false;
}
recursive = true;
@@ -2097,9 +2098,15 @@ void nlua_execute_on_key(int c, char *typed_buf)
int save_got_int = got_int;
got_int = false; // avoid interrupts when the key typed is Ctrl-C
- if (nlua_pcall(lstate, 2, 0)) {
+ bool discard = false;
+ if (nlua_pcall(lstate, 2, 1)) {
nlua_error(lstate,
_("Error executing vim.on_key Lua callback: %.*s"));
+ } else {
+ if (lua_isboolean(lstate, -1)) {
+ discard = lua_toboolean(lstate, -1);
+ }
+ lua_pop(lstate, 1);
}
got_int |= save_got_int;
@@ -2112,6 +2119,7 @@ void nlua_execute_on_key(int c, char *typed_buf)
#endif
recursive = false;
+ return discard;
}
// Sets the editor "script context" during Lua execution. Used by :verbose.