diff options
author | TJ DeVries <devries.timothyj@gmail.com> | 2021-05-28 15:45:34 -0400 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-02-27 22:04:55 +0100 |
commit | 991e472881bf29805982b402c1a010cde051ded3 (patch) | |
tree | 8d453a80320e49c2748f03240db8a4338384c9a1 /src/nvim/api/private/helpers.h | |
parent | 1b5767aa3480c0cdc43f7a4b78f36a14e85a182f (diff) | |
download | rneovim-991e472881bf29805982b402c1a010cde051ded3.tar.gz rneovim-991e472881bf29805982b402c1a010cde051ded3.tar.bz2 rneovim-991e472881bf29805982b402c1a010cde051ded3.zip |
feat(lua): add api and lua autocmds
Diffstat (limited to 'src/nvim/api/private/helpers.h')
-rw-r--r-- | src/nvim/api/private/helpers.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 6d0aec9c90..6969994c3b 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -138,10 +138,27 @@ typedef struct { msg_list = saved_msg_list; /* Restore the exception context. */ \ } while (0) +// Useful macro for executing some `code` for each item in an array. +#define FOREACH_ITEM(a, __foreach_item, code) \ + for (size_t __foreach_i = 0; __foreach_i < (a).size; __foreach_i++) { \ + Object __foreach_item = (a).items[__foreach_i]; \ + code; \ + } + + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/private/helpers.h.generated.h" # include "keysets.h.generated.h" #endif +#define WITH_SCRIPT_CONTEXT(channel_id, code) \ + const sctx_T save_current_sctx = current_sctx; \ + current_sctx.sc_sid = \ + (channel_id) == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT; \ + current_sctx.sc_lnum = 0; \ + current_channel_id = channel_id; \ + code; \ + current_sctx = save_current_sctx; + #endif // NVIM_API_PRIVATE_HELPERS_H |